< prev index next >

src/hotspot/share/prims/jni.cpp

Print this page
@@ -362,10 +362,18 @@
  JNI_END
  
  DT_RETURN_MARK_DECL(FromReflectedMethod, jmethodID
                      , HOTSPOT_JNI_FROMREFLECTEDMETHOD_RETURN((uintptr_t)_ret_ref));
  
+ #define NOTE_JNI_CLASSINIT(k1, reason)                                  \
+   if (RecordTraining && k1->is_instance_klass()) {                      \
+     InstanceKlass::cast(k1)                                             \
+       ->record_initialization_touch(reason, nullptr, nullptr,           \
+                                     nullptr, "jni", CHECK_0);           \
+   }
+ 
+ 
  JNI_ENTRY(jmethodID, jni_FromReflectedMethod(JNIEnv *env, jobject method))
    HOTSPOT_JNI_FROMREFLECTEDMETHOD_ENTRY(env, method);
  
    jmethodID ret = nullptr;
    DT_RETURN_MARK(FromReflectedMethod, jmethodID, (const jmethodID&)ret);

@@ -384,10 +392,11 @@
      slot   = java_lang_reflect_Method::slot(reflected);
    }
    Klass* k1 = java_lang_Class::as_Klass(mirror);
  
    // Make sure class is initialized before handing id's out to methods
+   NOTE_JNI_CLASSINIT(k1, "reflect");
    k1->initialize(CHECK_NULL);
    Method* m = InstanceKlass::cast(k1)->method_with_idnum(slot);
    ret = m==nullptr? nullptr : m->jmethod_id();  // return null if reflected method deleted
    return ret;
  JNI_END

@@ -407,10 +416,11 @@
    Klass* k1       = java_lang_Class::as_Klass(mirror);
    int slot        = java_lang_reflect_Field::slot(reflected);
    int modifiers   = java_lang_reflect_Field::modifiers(reflected);
  
    // Make sure class is initialized before handing id's out to fields
+   NOTE_JNI_CLASSINIT(k1, "reflect");
    k1->initialize(CHECK_NULL);
  
    // First check if this is a static field
    if (modifiers & JVM_ACC_STATIC) {
      int offset = InstanceKlass::cast(k1)->field_offset( slot );

@@ -967,11 +977,11 @@
    HOTSPOT_JNI_ALLOCOBJECT_ENTRY(env, clazz);
  
    jobject ret = nullptr;
    DT_RETURN_MARK(AllocObject, jobject, (const jobject&)ret);
  
-   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);
+   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), "jni", CHECK_NULL);
    ret = JNIHandles::make_local(THREAD, i);
    return ret;
  JNI_END
  
  DT_RETURN_MARK_DECL(NewObjectA, jobject

@@ -981,11 +991,11 @@
    HOTSPOT_JNI_NEWOBJECTA_ENTRY(env, clazz, (uintptr_t) methodID);
  
    jobject obj = nullptr;
    DT_RETURN_MARK(NewObjectA, jobject, (const jobject&)obj);
  
-   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);
+   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), "jni", CHECK_NULL);
    obj = JNIHandles::make_local(THREAD, i);
    JavaValue jvalue(T_VOID);
    JNI_ArgumentPusherArray ap(methodID, args);
    jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
    return obj;

@@ -999,11 +1009,11 @@
    HOTSPOT_JNI_NEWOBJECTV_ENTRY(env, clazz, (uintptr_t) methodID);
  
    jobject obj = nullptr;
    DT_RETURN_MARK(NewObjectV, jobject, (const jobject&)obj);
  
-   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);
+   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), "jni", CHECK_NULL);
    obj = JNIHandles::make_local(THREAD, i);
    JavaValue jvalue(T_VOID);
    JNI_ArgumentPusherVaArg ap(methodID, args);
    jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
    return obj;

@@ -1017,11 +1027,11 @@
    HOTSPOT_JNI_NEWOBJECT_ENTRY(env, clazz, (uintptr_t) methodID);
  
    jobject obj = nullptr;
    DT_RETURN_MARK(NewObject, jobject, (const jobject&)obj);
  
-   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);
+   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), "jni", CHECK_NULL);
    obj = JNIHandles::make_local(THREAD, i);
    va_list args;
    va_start(args, methodID);
    JavaValue jvalue(T_VOID);
    JNI_ArgumentPusherVaArg ap(methodID, args);

@@ -1087,10 +1097,11 @@
      THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), err_msg("%s%s.%s%s", is_static ? "static " : "", klass->signature_name(), name_str, sig));
    }
  
    // Make sure class is linked and initialized before handing id's out to
    // Method*s.
+   NOTE_JNI_CLASSINIT(klass, "resolve");
    klass->initialize(CHECK_NULL);
  
    Method* m;
    if (name == vmSymbols::object_initializer_name() ||
        name == vmSymbols::class_initializer_name()) {

@@ -1607,10 +1618,11 @@
  \
    JavaValue jvalue(Tag); \
    JNI_ArgumentPusherVaArg ap(methodID, args); \
    /* Make sure class is initialized before trying to invoke its method */ \
    Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); \
+   NOTE_JNI_CLASSINIT(k, "invokestatic"); \
    k->initialize(CHECK_0); \
    jni_invoke_static(env, &jvalue, nullptr, JNI_STATIC, methodID, &ap, CHECK_0); \
    va_end(args); \
    ret = jvalue.get_##ResultType(); \
    return ret;\

@@ -1764,10 +1776,11 @@
      ResourceMark rm;
      THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), err_msg("%s.%s %s", k->external_name(), name, sig));
    }
  
    // Make sure class is initialized before handing id's out to fields
+   NOTE_JNI_CLASSINIT(k, "resolve");
    k->initialize(CHECK_NULL);
  
    fieldDescriptor fd;
    if (!k->is_instance_klass() ||
        !InstanceKlass::cast(k)->find_field(fieldname, signame, false, &fd)) {

@@ -1988,10 +2001,11 @@
    if (fieldname == nullptr || signame == nullptr) {
      THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name);
    }
    Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
    // Make sure class is initialized before handing id's out to static fields
+   NOTE_JNI_CLASSINIT(k, "resolve");
    k->initialize(CHECK_NULL);
  
    fieldDescriptor fd;
    if (!k->is_instance_klass() ||
        !InstanceKlass::cast(k)->find_field(fieldname, signame, true, &fd)) {
< prev index next >