src/share/vm/oops/instanceKlass.cpp

changeset 482
2c106685d6d0
parent 435
a61af66fc99e
child 484
31000d79ec71
     1.1 --- a/src/share/vm/oops/instanceKlass.cpp	Fri Feb 29 20:03:58 2008 -0800
     1.2 +++ b/src/share/vm/oops/instanceKlass.cpp	Wed Mar 12 18:06:50 2008 -0700
     1.3 @@ -2165,12 +2165,20 @@
     1.4    RC_TRACE(0x00000100, ("adding previous version ref for %s @%d, EMCP_cnt=%d",
     1.5      ikh->external_name(), _previous_versions->length(), emcp_method_count));
     1.6    constantPoolHandle cp_h(ikh->constants());
     1.7 -  jweak cp_ref = JNIHandles::make_weak_global(cp_h);
     1.8 +  jobject cp_ref;
     1.9 +  if (cp_h->is_shared()) {
    1.10 +    // a shared ConstantPool requires a regular reference; a weak
    1.11 +    // reference would be collectible
    1.12 +    cp_ref = JNIHandles::make_global(cp_h);
    1.13 +  } else {
    1.14 +    cp_ref = JNIHandles::make_weak_global(cp_h);
    1.15 +  }
    1.16    PreviousVersionNode * pv_node = NULL;
    1.17    objArrayOop old_methods = ikh->methods();
    1.18  
    1.19    if (emcp_method_count == 0) {
    1.20 -    pv_node = new PreviousVersionNode(cp_ref, NULL);
    1.21 +    // non-shared ConstantPool gets a weak reference
    1.22 +    pv_node = new PreviousVersionNode(cp_ref, !cp_h->is_shared(), NULL);
    1.23      RC_TRACE(0x00000400,
    1.24        ("add: all methods are obsolete; flushing any EMCP weak refs"));
    1.25    } else {
    1.26 @@ -2190,7 +2198,8 @@
    1.27          }
    1.28        }
    1.29      }
    1.30 -    pv_node = new PreviousVersionNode(cp_ref, method_refs);
    1.31 +    // non-shared ConstantPool gets a weak reference
    1.32 +    pv_node = new PreviousVersionNode(cp_ref, !cp_h->is_shared(), method_refs);
    1.33    }
    1.34  
    1.35    _previous_versions->append(pv_node);
    1.36 @@ -2208,7 +2217,7 @@
    1.37      // check the previous versions array for a GC'ed weak refs
    1.38      pv_node = _previous_versions->at(i);
    1.39      cp_ref = pv_node->prev_constant_pool();
    1.40 -    assert(cp_ref != NULL, "weak cp ref was unexpectedly cleared");
    1.41 +    assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
    1.42      if (cp_ref == NULL) {
    1.43        delete pv_node;
    1.44        _previous_versions->remove_at(i);
    1.45 @@ -2281,7 +2290,7 @@
    1.46            // check the previous versions array for a GC'ed weak refs
    1.47            pv_node = _previous_versions->at(j);
    1.48            cp_ref = pv_node->prev_constant_pool();
    1.49 -          assert(cp_ref != NULL, "weak cp ref was unexpectedly cleared");
    1.50 +          assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
    1.51            if (cp_ref == NULL) {
    1.52              delete pv_node;
    1.53              _previous_versions->remove_at(j);
    1.54 @@ -2379,8 +2388,8 @@
    1.55      // been GC'ed
    1.56      PreviousVersionNode * pv_node = _previous_versions->at(i);
    1.57  
    1.58 -    jweak cp_ref = pv_node->prev_constant_pool();
    1.59 -    assert(cp_ref != NULL, "weak reference was unexpectedly cleared");
    1.60 +    jobject cp_ref = pv_node->prev_constant_pool();
    1.61 +    assert(cp_ref != NULL, "cp reference was unexpectedly cleared");
    1.62      if (cp_ref == NULL) {
    1.63        continue;  // robustness
    1.64      }
    1.65 @@ -2440,10 +2449,11 @@
    1.66  
    1.67  // Construct a PreviousVersionNode entry for the array hung off
    1.68  // the instanceKlass.
    1.69 -PreviousVersionNode::PreviousVersionNode(jweak prev_constant_pool,
    1.70 -  GrowableArray<jweak>* prev_EMCP_methods) {
    1.71 +PreviousVersionNode::PreviousVersionNode(jobject prev_constant_pool,
    1.72 +  bool prev_cp_is_weak, GrowableArray<jweak>* prev_EMCP_methods) {
    1.73  
    1.74    _prev_constant_pool = prev_constant_pool;
    1.75 +  _prev_cp_is_weak = prev_cp_is_weak;
    1.76    _prev_EMCP_methods = prev_EMCP_methods;
    1.77  }
    1.78  
    1.79 @@ -2451,7 +2461,11 @@
    1.80  // Destroy a PreviousVersionNode
    1.81  PreviousVersionNode::~PreviousVersionNode() {
    1.82    if (_prev_constant_pool != NULL) {
    1.83 -    JNIHandles::destroy_weak_global(_prev_constant_pool);
    1.84 +    if (_prev_cp_is_weak) {
    1.85 +      JNIHandles::destroy_weak_global(_prev_constant_pool);
    1.86 +    } else {
    1.87 +      JNIHandles::destroy_global(_prev_constant_pool);
    1.88 +    }
    1.89    }
    1.90  
    1.91    if (_prev_EMCP_methods != NULL) {
    1.92 @@ -2471,8 +2485,8 @@
    1.93    _prev_constant_pool_handle = constantPoolHandle();  // NULL handle
    1.94    _prev_EMCP_method_handles = NULL;
    1.95  
    1.96 -  jweak cp_ref = pv_node->prev_constant_pool();
    1.97 -  assert(cp_ref != NULL, "weak constant pool ref was unexpectedly cleared");
    1.98 +  jobject cp_ref = pv_node->prev_constant_pool();
    1.99 +  assert(cp_ref != NULL, "constant pool ref was unexpectedly cleared");
   1.100    if (cp_ref == NULL) {
   1.101      return;  // robustness
   1.102    }

mercurial