Skip to content

Commit c462c91

Browse files
coleenpfparain
authored andcommitted
8336829: [lworld] serviceability/jvmti/RedefineClasses/RedefineLeakThrowable.java gets Metaspace OOM
Reviewed-by: fparain
1 parent ca99443 commit c462c91

File tree

4 files changed

+81
-17
lines changed

4 files changed

+81
-17
lines changed

Diff for: src/hotspot/share/oops/inlineKlass.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,11 @@ void InlineKlass::initialize_calling_convention(TRAPS) {
318318
void InlineKlass::deallocate_contents(ClassLoaderData* loader_data) {
319319
if (extended_sig() != nullptr) {
320320
MetadataFactory::free_array<SigEntry>(loader_data, extended_sig());
321+
*((Array<SigEntry>**)adr_extended_sig()) = nullptr;
321322
}
322323
if (return_regs() != nullptr) {
323324
MetadataFactory::free_array<VMRegPair>(loader_data, return_regs());
325+
*((Array<VMRegPair>**)adr_return_regs()) = nullptr;
324326
}
325327
cleanup_blobs();
326328
InstanceKlass::deallocate_contents(loader_data);

Diff for: src/hotspot/share/oops/instanceKlass.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -720,11 +720,12 @@ void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) {
720720

721721
if (inline_type_field_klasses_array() != nullptr) {
722722
MetadataFactory::free_array<InlineKlass*>(loader_data, inline_type_field_klasses_array());
723+
set_inline_type_field_klasses_array(nullptr);
723724
}
724-
set_inline_type_field_klasses_array(nullptr);
725725

726726
if (null_marker_offsets_array() != nullptr) {
727727
MetadataFactory::free_array<int>(loader_data, null_marker_offsets_array());
728+
set_null_marker_offsets_array(nullptr);
728729
}
729730

730731
// If a method from a redefined class is using this constant pool, don't
@@ -766,6 +767,7 @@ void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) {
766767
!loadable_descriptors()->is_shared()) {
767768
MetadataFactory::free_array<jushort>(loader_data, loadable_descriptors());
768769
}
770+
set_loadable_descriptors(nullptr);
769771

770772
// We should deallocate the Annotations instance if it's not in shared spaces.
771773
if (annotations() != nullptr && !annotations()->is_shared()) {

Diff for: test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/RedefineLeakThrowable.java

+3-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,6 @@
2626
* @bug 8308762
2727
* @library /test/lib
2828
* @summary Test that redefinition of class containing Throwable refs does not leak constant pool
29-
* @requires os.family == "aix"
3029
* @requires vm.jvmti
3130
* @requires vm.flagless
3231
* @modules java.base/jdk.internal.misc
@@ -36,20 +35,8 @@
3635
* @run main/othervm/timeout=6000 -javaagent:redefineagent.jar -XX:MetaspaceSize=23m -XX:MaxMetaspaceSize=23m RedefineLeakThrowable
3736
*/
3837

39-
/*
40-
* @test
41-
* @bug 8308762
42-
* @library /test/lib
43-
* @summary Test that redefinition of class containing Throwable refs does not leak constant pool
44-
* @requires os.family != "aix"
45-
* @requires vm.jvmti
46-
* @requires vm.flagless
47-
* @modules java.base/jdk.internal.misc
48-
* @modules java.instrument
49-
* java.compiler
50-
* @run main RedefineClassHelper
51-
* @run main/othervm/timeout=6000 -javaagent:redefineagent.jar -XX:MetaspaceSize=17m -XX:MaxMetaspaceSize=17m RedefineLeakThrowable
52-
*/
38+
39+
// MaxMetaspaceSize=23m allows InMemoryJavaCompiler to load even if CDS is off.
5340

5441
class Tester {
5542
void test() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8336829
27+
* @library /test/lib
28+
* @summary Test that redefinition of a value class containing Throwable refs does not leak constant pool
29+
* @enablePreview
30+
* @modules java.base/jdk.internal.misc
31+
* @modules java.instrument
32+
* java.compiler
33+
* @run main RedefineClassHelper
34+
* @run main/othervm/timeout=6000 --enable-preview -Xlog:class+load,gc+metaspace+freelist+oom:rt.log -javaagent:redefineagent.jar -XX:MetaspaceSize=23m -XX:MaxMetaspaceSize=23m RedefineLeakThrowableValue
35+
*/
36+
37+
import jdk.test.lib.compiler.InMemoryJavaCompiler;
38+
39+
value class Tester {
40+
void test() {
41+
try {
42+
int i = 42;
43+
} catch (Throwable t) {
44+
t.printStackTrace();
45+
}
46+
}
47+
}
48+
49+
public class RedefineLeakThrowableValue {
50+
51+
static final String NEW_TESTER =
52+
"value class Tester {" +
53+
" void test() {" +
54+
" try {" +
55+
" int i = 42;" +
56+
" } catch (Throwable t) {" +
57+
" t.printStackTrace();" +
58+
" }" +
59+
" }" +
60+
"}";
61+
62+
63+
public static void main(String argv[]) throws Exception {
64+
String java_version = System.getProperty("java.specification.version");
65+
// Load InMemoryJavaCompiler outside the redefinition loop to prevent random lambdas that load and fill up metaspace.
66+
byte[] bytecodes = InMemoryJavaCompiler.compile("Tester", NEW_TESTER,
67+
"-source", java_version, "--enable-preview",
68+
"--add-exports", "java.base/jdk.internal.vm.annotation=ALL-UNNAMED");
69+
for (int i = 0; i < 700; i++) {
70+
RedefineClassHelper.redefineClass(Tester.class, bytecodes);
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)