JDK-8231269 : JNIHandles::is_weak_global_handle is not cheap
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 14
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2019-09-19
  • Updated: 2019-09-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Relates :  
Description
The compiler task queue code that makes weak global handles into strong global handles in select_for_compilation, could set a flag that the compileTask is active, so that it doesn't have to ask is_weak_global_handle() about the holders, which is expensive (lock and several SafeFetch loads).

bool CompileTask::is_unloaded() const {
  return _method_holder != NULL && JNIHandles::is_weak_global_handle(_method_holder) && JNIHandles::is_global_weak_cleared(_method_holder);
}

// Replace weak handles by strong handles to avoid unloading during compilation.
CompileTask* CompileTask::select_for_compilation() {
  if (is_unloaded()) {
    // Guard against concurrent class unloading
    return NULL;
  }
  Thread* thread = Thread::current();
  assert(_method->method_holder()->is_loader_alive(), "should be alive");
  Handle method_holder(thread, _method->method_holder()->klass_holder());
  JNIHandles::destroy_weak_global(_method_holder);
  JNIHandles::destroy_weak_global(_hot_method_holder);
  _method_holder = JNIHandles::make_global(method_holder);
  if (_hot_method != NULL) {
    _hot_method_holder = JNIHandles::make_global(Handle(thread, _hot_method->method_holder()->klass_holder()));
  }
  return this;
}

Comments
JNIHandles::is_[weak_]global_handle mostly exist to support jniCheck, and weren't really intended for this kind of use-case. A possible alternative to a flag that tracks the _method_holder state would be to make JNIHandles::is_jweak public rather than private and use it. But I don't think that's the way to go, because I think this code shouldn't be using JNIHandles and jobjects at all. It should be using oop* from VMGlobal and VMWeak.
24-09-2019