< prev index next >

src/hotspot/share/runtime/jniHandles.cpp

Print this page

  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"

 26 #include "gc/shared/collectedHeap.hpp"
 27 #include "gc/shared/oopStorage.inline.hpp"
 28 #include "gc/shared/oopStorageSet.hpp"
 29 #include "logging/log.hpp"
 30 #include "memory/iterator.hpp"
 31 #include "memory/universe.hpp"
 32 #include "oops/access.inline.hpp"
 33 #include "oops/oop.inline.hpp"
 34 #include "runtime/handles.inline.hpp"

 35 #include "runtime/javaThread.inline.hpp"
 36 #include "runtime/jniHandles.inline.hpp"
 37 #include "runtime/mutexLocker.hpp"
 38 #include "utilities/align.hpp"
 39 #include "utilities/debug.hpp"
 40 
 41 OopStorage* JNIHandles::global_handles() {
 42   return _global_handles;
 43 }
 44 
 45 OopStorage* JNIHandles::weak_global_handles() {
 46   return _weak_global_handles;
 47 }
 48 
 49 // Serviceability agent support.
 50 OopStorage* JNIHandles::_global_handles = NULL;
 51 OopStorage* JNIHandles::_weak_global_handles = NULL;
 52 
 53 void jni_handles_init() {
 54   JNIHandles::_global_handles = OopStorageSet::create_strong("JNI Global", mtInternal);

280     guarantee(oopDesc::is_oop_or_null(RawAccess<>::oop_load(root)), "Invalid oop");
281   }
282   virtual void do_oop(narrowOop* root) { ShouldNotReachHere(); }
283 };
284 
285 void JNIHandles::verify() {
286   VerifyJNIHandles verify_handle;
287 
288   oops_do(&verify_handle);
289   weak_oops_do(&verify_handle);
290 }
291 
292 // This method is implemented here to avoid circular includes between
293 // jniHandles.hpp and thread.hpp.
294 bool JNIHandles::current_thread_in_native() {
295   Thread* thread = Thread::current();
296   return (thread->is_Java_thread() &&
297           JavaThread::cast(thread)->thread_state() == _thread_in_native);
298 }
299 






































300 int JNIHandleBlock::_blocks_allocated = 0;
301 
302 static inline bool is_tagged_free_list(uintptr_t value) {
303   return (value & 1u) != 0;
304 }
305 
306 static inline uintptr_t tag_free_list(uintptr_t value) {
307   return value | 1u;
308 }
309 
310 static inline uintptr_t untag_free_list(uintptr_t value) {
311   return value & ~(uintptr_t)1u;
312 }
313 
314 // There is a freelist of handles running through the JNIHandleBlock
315 // with a tagged next pointer, distinguishing these next pointers from
316 // oops. The freelist handling currently relies on the size of oops
317 // being the same as a native pointer. If this ever changes, then
318 // this freelist handling must change too.
319 STATIC_ASSERT(sizeof(oop) == sizeof(uintptr_t));

  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "classfile/vmSymbols.hpp"
 27 #include "gc/shared/collectedHeap.hpp"
 28 #include "gc/shared/oopStorage.inline.hpp"
 29 #include "gc/shared/oopStorageSet.hpp"
 30 #include "logging/log.hpp"
 31 #include "memory/iterator.hpp"
 32 #include "memory/universe.hpp"
 33 #include "oops/access.inline.hpp"
 34 #include "oops/oop.inline.hpp"
 35 #include "runtime/handles.inline.hpp"
 36 #include "runtime/javaCalls.hpp"
 37 #include "runtime/javaThread.inline.hpp"
 38 #include "runtime/jniHandles.inline.hpp"
 39 #include "runtime/mutexLocker.hpp"
 40 #include "utilities/align.hpp"
 41 #include "utilities/debug.hpp"
 42 
 43 OopStorage* JNIHandles::global_handles() {
 44   return _global_handles;
 45 }
 46 
 47 OopStorage* JNIHandles::weak_global_handles() {
 48   return _weak_global_handles;
 49 }
 50 
 51 // Serviceability agent support.
 52 OopStorage* JNIHandles::_global_handles = NULL;
 53 OopStorage* JNIHandles::_weak_global_handles = NULL;
 54 
 55 void jni_handles_init() {
 56   JNIHandles::_global_handles = OopStorageSet::create_strong("JNI Global", mtInternal);

282     guarantee(oopDesc::is_oop_or_null(RawAccess<>::oop_load(root)), "Invalid oop");
283   }
284   virtual void do_oop(narrowOop* root) { ShouldNotReachHere(); }
285 };
286 
287 void JNIHandles::verify() {
288   VerifyJNIHandles verify_handle;
289 
290   oops_do(&verify_handle);
291   weak_oops_do(&verify_handle);
292 }
293 
294 // This method is implemented here to avoid circular includes between
295 // jniHandles.hpp and thread.hpp.
296 bool JNIHandles::current_thread_in_native() {
297   Thread* thread = Thread::current();
298   return (thread->is_Java_thread() &&
299           JavaThread::cast(thread)->thread_state() == _thread_in_native);
300 }
301 
302 bool JNIHandles::is_same_object(jobject handle1, jobject handle2) {
303   oop obj1 = resolve_no_keepalive(handle1);
304   oop obj2 = resolve_no_keepalive(handle2);
305 
306   bool ret = obj1 == obj2;
307 
308   if (EnableValhalla) {
309     if (!ret && obj1 != NULL && obj2 != NULL && obj1->klass() == obj2->klass() && obj1->klass()->is_inline_klass()) {
310       // The two references are different, they are not null and they are both inline types,
311       // a full substitutability test is required, calling PrimitiveObjectMethods.isSubstitutable()
312       // (similarly to InterpreterRuntime::is_substitutable)
313       JavaThread* THREAD = JavaThread::current();
314       Handle ha(THREAD, obj1);
315       Handle hb(THREAD, obj2);
316       JavaValue result(T_BOOLEAN);
317       JavaCallArguments args;
318       args.push_oop(ha);
319       args.push_oop(hb);
320       methodHandle method(THREAD, Universe::is_substitutable_method());
321       JavaCalls::call(&result, method, &args, THREAD);
322       if (HAS_PENDING_EXCEPTION) {
323         // Something really bad happened because isSubstitutable() should not throw exceptions
324         // If it is an error, just let it propagate
325         // If it is an exception, wrap it into an InternalError
326         if (!PENDING_EXCEPTION->is_a(vmClasses::Error_klass())) {
327           Handle e(THREAD, PENDING_EXCEPTION);
328           CLEAR_PENDING_EXCEPTION;
329           THROW_MSG_CAUSE_(vmSymbols::java_lang_InternalError(), "Internal error in substitutability test", e, false);
330         }
331       }
332       ret = result.get_jboolean();
333     }
334   }
335 
336   return ret;
337 }
338 
339 
340 int JNIHandleBlock::_blocks_allocated = 0;
341 
342 static inline bool is_tagged_free_list(uintptr_t value) {
343   return (value & 1u) != 0;
344 }
345 
346 static inline uintptr_t tag_free_list(uintptr_t value) {
347   return value | 1u;
348 }
349 
350 static inline uintptr_t untag_free_list(uintptr_t value) {
351   return value & ~(uintptr_t)1u;
352 }
353 
354 // There is a freelist of handles running through the JNIHandleBlock
355 // with a tagged next pointer, distinguishing these next pointers from
356 // oops. The freelist handling currently relies on the size of oops
357 // being the same as a native pointer. If this ever changes, then
358 // this freelist handling must change too.
359 STATIC_ASSERT(sizeof(oop) == sizeof(uintptr_t));
< prev index next >