< 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 = nullptr;
 51 OopStorage* JNIHandles::_weak_global_handles = nullptr;
 52 
 53 void jni_handles_init() {
 54   JNIHandles::_global_handles = OopStorageSet::create_strong("JNI Global", mtInternal);

266     guarantee(oopDesc::is_oop_or_null(RawAccess<>::oop_load(root)), "Invalid oop");
267   }
268   virtual void do_oop(narrowOop* root) { ShouldNotReachHere(); }
269 };
270 
271 void JNIHandles::verify() {
272   VerifyJNIHandles verify_handle;
273 
274   oops_do(&verify_handle);
275   weak_oops_do(&verify_handle);
276 }
277 
278 // This method is implemented here to avoid circular includes between
279 // jniHandles.hpp and thread.hpp.
280 bool JNIHandles::current_thread_in_native() {
281   Thread* thread = Thread::current();
282   return (thread->is_Java_thread() &&
283           JavaThread::cast(thread)->thread_state() == _thread_in_native);
284 }
285 






































286 int JNIHandleBlock::_blocks_allocated = 0;
287 
288 static inline bool is_tagged_free_list(uintptr_t value) {
289   return (value & 1u) != 0;
290 }
291 
292 static inline uintptr_t tag_free_list(uintptr_t value) {
293   return value | 1u;
294 }
295 
296 static inline uintptr_t untag_free_list(uintptr_t value) {
297   return value & ~(uintptr_t)1u;
298 }
299 
300 // There is a freelist of handles running through the JNIHandleBlock
301 // with a tagged next pointer, distinguishing these next pointers from
302 // oops. The freelist handling currently relies on the size of oops
303 // being the same as a native pointer. If this ever changes, then
304 // this freelist handling must change too.
305 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 = nullptr;
 53 OopStorage* JNIHandles::_weak_global_handles = nullptr;
 54 
 55 void jni_handles_init() {
 56   JNIHandles::_global_handles = OopStorageSet::create_strong("JNI Global", mtInternal);

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