src/share/vm/runtime/jniHandles.cpp

changeset 9669
32bc598624bd
parent 9665
a8441ccaff15
child 9703
2fdf635bcf28
     1.1 --- a/src/share/vm/runtime/jniHandles.cpp	Thu Nov 05 11:42:42 2015 +0100
     1.2 +++ b/src/share/vm/runtime/jniHandles.cpp	Tue May 07 20:38:26 2019 +0000
     1.3 @@ -30,6 +30,9 @@
     1.4  #include "runtime/jniHandles.hpp"
     1.5  #include "runtime/mutexLocker.hpp"
     1.6  #include "runtime/thread.inline.hpp"
     1.7 +#if INCLUDE_ALL_GCS
     1.8 +#include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
     1.9 +#endif
    1.10  
    1.11  PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
    1.12  
    1.13 @@ -87,34 +90,52 @@
    1.14    return res;
    1.15  }
    1.16  
    1.17 -
    1.18  jobject JNIHandles::make_weak_global(Handle obj) {
    1.19    assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC");
    1.20    jobject res = NULL;
    1.21    if (!obj.is_null()) {
    1.22      // ignore null handles
    1.23 -    MutexLocker ml(JNIGlobalHandle_lock);
    1.24 -    assert(Universe::heap()->is_in_reserved(obj()), "sanity check");
    1.25 -    res = _weak_global_handles->allocate_handle(obj());
    1.26 +    {
    1.27 +      MutexLocker ml(JNIGlobalHandle_lock);
    1.28 +      assert(Universe::heap()->is_in_reserved(obj()), "sanity check");
    1.29 +      res = _weak_global_handles->allocate_handle(obj());
    1.30 +    }
    1.31 +    // Add weak tag.
    1.32 +    assert(is_ptr_aligned(res, weak_tag_alignment), "invariant");
    1.33 +    char* tptr = reinterpret_cast<char*>(res) + weak_tag_value;
    1.34 +    res = reinterpret_cast<jobject>(tptr);
    1.35    } else {
    1.36      CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
    1.37    }
    1.38    return res;
    1.39  }
    1.40  
    1.41 +template<bool external_guard>
    1.42 +oop JNIHandles::resolve_jweak(jweak handle) {
    1.43 +  assert(is_jweak(handle), "precondition");
    1.44 +  oop result = jweak_ref(handle);
    1.45 +  result = guard_value<external_guard>(result);
    1.46 +#if INCLUDE_ALL_GCS
    1.47 +  if (result != NULL && UseG1GC) {
    1.48 +    G1SATBCardTableModRefBS::enqueue(result);
    1.49 +  }
    1.50 +#endif // INCLUDE_ALL_GCS
    1.51 +  return result;
    1.52 +}
    1.53 +
    1.54 +template oop JNIHandles::resolve_jweak<true>(jweak);
    1.55 +template oop JNIHandles::resolve_jweak<false>(jweak);
    1.56  
    1.57  void JNIHandles::destroy_global(jobject handle) {
    1.58    if (handle != NULL) {
    1.59      assert(is_global_handle(handle), "Invalid delete of global JNI handle");
    1.60 -    *((oop*)handle) = deleted_handle(); // Mark the handle as deleted, allocate will reuse it
    1.61 +    jobject_ref(handle) = deleted_handle();
    1.62    }
    1.63  }
    1.64  
    1.65 -
    1.66  void JNIHandles::destroy_weak_global(jobject handle) {
    1.67    if (handle != NULL) {
    1.68 -    assert(!CheckJNICalls || is_weak_global_handle(handle), "Invalid delete of weak global JNI handle");
    1.69 -    *((oop*)handle) = deleted_handle(); // Mark the handle as deleted, allocate will reuse it
    1.70 +    jweak_ref(handle) = deleted_handle();
    1.71    }
    1.72  }
    1.73  

mercurial