Skip to content
Permalink
Browse files

8261607: SA attach is exceeding JNI Local Refs capacity

Reviewed-by: sgehwolf, amenkov
  • Loading branch information
plummercj committed Feb 16, 2021
1 parent 0a50688 commit 55d7bbcec01f4b2bb4105ee5641cd28136cdd61a
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020, NTT DATA.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -183,6 +183,8 @@ static void fillThreadsAndLoadObjects(JNIEnv* env, jobject this_obj, struct ps_p
CHECK_EXCEPTION;
env->CallBooleanMethod(threadList, listAdd_ID, thread);
CHECK_EXCEPTION;
env->DeleteLocalRef(thread);
env->DeleteLocalRef(threadList);
}

// add load objects
@@ -205,6 +207,9 @@ static void fillThreadsAndLoadObjects(JNIEnv* env, jobject this_obj, struct ps_p
CHECK_EXCEPTION;
env->CallBooleanMethod(loadObjectList, listAdd_ID, loadObject);
CHECK_EXCEPTION;
env->DeleteLocalRef(str);
env->DeleteLocalRef(loadObject);
env->DeleteLocalRef(loadObjectList);
}
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -965,14 +965,17 @@ static bool wait_for_exception() {
called from Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2 */
static void fillLoadObjects(JNIEnv* env, jobject this_obj, struct ps_prochandle* ph) {
int n = 0, i = 0;
jobject loadObjectList;

loadObjectList = (*env)->GetObjectField(env, this_obj, loadObjectList_ID);
CHECK_EXCEPTION;

// add load objects
n = get_num_libs(ph);
for (i = 0; i < n; i++) {
uintptr_t base;
const char* name;
jobject loadObject;
jobject loadObjectList;
jstring nameString;

base = get_lib_base(ph, i);
@@ -982,10 +985,10 @@ static void fillLoadObjects(JNIEnv* env, jobject this_obj, struct ps_prochandle*
loadObject = (*env)->CallObjectMethod(env, this_obj, createLoadObject_ID,
nameString, (jlong)0, (jlong)base);
CHECK_EXCEPTION;
loadObjectList = (*env)->GetObjectField(env, this_obj, loadObjectList_ID);
CHECK_EXCEPTION;
(*env)->CallBooleanMethod(env, loadObjectList, listAdd_ID, loadObject);
CHECK_EXCEPTION;
(*env)->DeleteLocalRef(env, nameString);
(*env)->DeleteLocalRef(env, loadObject);
}
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -503,6 +503,7 @@ static bool addLoadObjects(JNIEnv* env, jobject obj) {
env->CallVoidMethod(obj, addLoadObject_ID, strName, (jlong) params[u].Size,
(jlong) params[u].Base);
CHECK_EXCEPTION_(false);
env->DeleteLocalRef(strName);
}

return true;
@@ -629,6 +630,7 @@ static bool addThreads(JNIEnv* env, jobject obj) {

env->CallVoidMethod(obj, setThreadIntegerRegisterSet_ID, (jlong)ptrThreadIds[t], regs);
CHECK_EXCEPTION_(false);
env->DeleteLocalRef(regs);

ULONG sysId;
COM_VERIFY_OK_(ptrIDebugSystemObjects->GetCurrentThreadSystemId(&sysId),
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -144,6 +144,9 @@ private String runCmd(List<String> commands,
System.out.println("Output: ");
System.out.println(output);

// -Xcheck:jni might be set via TEST_VM_OPTS. Make sure there are no warnings.
oa.shouldNotMatch("^WARNING: JNI local refs:.*$");
oa.shouldNotMatch("^WARNING in native method:.*$");
// This will detect most SA failures, including during the attach.
oa.shouldNotMatch("^sun.jvm.hotspot.debugger.DebuggerException:.*$");
// This will detect unexpected exceptions, like NPEs and asserts, that are caught

1 comment on commit 55d7bbc

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 55d7bbc Feb 16, 2021

Please sign in to comment.