Skip to content

Commit bb03bac

Browse files
committed
Fix jdk8 patching
1 parent 396fec6 commit bb03bac

3 files changed

Lines changed: 24 additions & 22 deletions

File tree

ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,31 +1270,33 @@ bool isHiddenClass(jvmtiEnv *jvmti, jclass clazz) {
12701270
return false;
12711271
}
12721272

1273-
bool HotspotSupport::loadMethodIDsIfNeededImpl(jvmtiEnv *jvmti, JNIEnv *jni, jclass klass) {
1274-
jobject cl = nullptr;
1275-
// Hidden/lambda classes can not unloaded, fallback to use jmethodIDs, so preload them.
1276-
if (!isHiddenClass(jvmti, klass) &&
1277-
jvmti->GetClassLoader(klass, &cl) == JVMTI_ERROR_NONE &&
1278-
isSystemClassLoader(jni, cl)) {
1279-
char* signature_ptr = nullptr;
1280-
if (jvmti->GetClassSignature(klass, &signature_ptr, nullptr) == JVMTI_ERROR_NONE) {
1281-
// Lambda classes, even loaded by bootstrap class loader, can be unloaded,
1282-
// fallback to jmethodID
1283-
if (!isLambdaClass(signature_ptr)) {
1284-
if (cl != nullptr) {
1285-
jni->DeleteLocalRef(cl);
1273+
bool HotspotSupport::loadMethodIDsIfNeededImpl(jvmtiEnv *jvmti, JNIEnv *jni, jclass klass, bool load_all) {
1274+
if (!load_all) {
1275+
jobject cl = nullptr;
1276+
// Hidden/lambda classes can not unloaded, fallback to use jmethodIDs, so preload them.
1277+
if (!isHiddenClass(jvmti, klass) &&
1278+
jvmti->GetClassLoader(klass, &cl) == JVMTI_ERROR_NONE &&
1279+
isSystemClassLoader(jni, cl)) {
1280+
char* signature_ptr = nullptr;
1281+
if (jvmti->GetClassSignature(klass, &signature_ptr, nullptr) == JVMTI_ERROR_NONE) {
1282+
// Lambda classes, even loaded by bootstrap class loader, can be unloaded,
1283+
// fallback to jmethodID
1284+
if (!isLambdaClass(signature_ptr)) {
1285+
if (cl != nullptr) {
1286+
jni->DeleteLocalRef(cl);
1287+
}
1288+
jvmti->Deallocate((unsigned char*)signature_ptr);
1289+
return false;
12861290
}
1291+
}
1292+
if (signature_ptr != nullptr) {
12871293
jvmti->Deallocate((unsigned char*)signature_ptr);
1288-
return false;
12891294
}
12901295
}
1291-
if (signature_ptr != nullptr) {
1292-
jvmti->Deallocate((unsigned char*)signature_ptr);
1296+
if (cl != nullptr) {
1297+
jni->DeleteLocalRef(cl);
12931298
}
12941299
}
1295-
if (cl != nullptr) {
1296-
jni->DeleteLocalRef(cl);
1297-
}
12981300
patchClassLoaderData(jni, klass);
12991301
return JVMSupport::loadMethodIDsImpl(jvmti, jni, klass);
13001302
}

ddprof-lib/src/main/cpp/hotspot/hotspotSupport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class HotspotSupport {
3333
int max_depth, StackContext *java_ctx,
3434
bool *truncated);
3535

36-
static bool loadMethodIDsIfNeededImpl(jvmtiEnv *jvmti, JNIEnv *jni, jclass klass);
36+
static bool loadMethodIDsIfNeededImpl(jvmtiEnv *jvmti, JNIEnv *jni, jclass klass, bool load_all);
3737
public:
3838
static void initClassloaderInfo(JNIEnv* jni);
3939

ddprof-lib/src/main/cpp/jvmSupport.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ bool JVMSupport::loadMethodIDsIfNeeded(jvmtiEnv *jvmti, JNIEnv *jni, jclass klas
122122
return false;
123123
}
124124

125-
if (VM::isHotspot() && state == Partial_loaded) {
126-
return HotspotSupport::loadMethodIDsIfNeededImpl(jvmti, jni, klass);
125+
if (VM::isHotspot()) {
126+
return HotspotSupport::loadMethodIDsIfNeededImpl(jvmti, jni, klass, state == Fully_loaded /* load all */);
127127
} else {
128128
return loadMethodIDsImpl(jvmti, jni, klass);
129129
}

0 commit comments

Comments
 (0)