< 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/jniHandles.inline.hpp"
 36 #include "runtime/mutexLocker.hpp"
 37 #include "runtime/thread.inline.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);

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





































308 
309 int             JNIHandleBlock::_blocks_allocated     = 0;
310 JNIHandleBlock* JNIHandleBlock::_block_free_list      = NULL;
311 #ifndef PRODUCT
312 JNIHandleBlock* JNIHandleBlock::_block_list           = NULL;
313 #endif
314 
315 static inline bool is_tagged_free_list(uintptr_t value) {
316   return (value & 1u) != 0;
317 }
318 
319 static inline uintptr_t tag_free_list(uintptr_t value) {
320   return value | 1u;
321 }
322 
323 static inline uintptr_t untag_free_list(uintptr_t value) {
324   return value & ~(uintptr_t)1u;
325 }
326 
327 // There is a freelist of handles running through the JNIHandleBlock

  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/jniHandles.inline.hpp"
 38 #include "runtime/mutexLocker.hpp"
 39 #include "runtime/thread.inline.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);

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