Skip to content

Commit 56a40f3

Browse files
committed
8343218: Add option to disable allocating interface and abstract classes in non-class metaspace
Backport-of: da3a5da81bc1d6fe1e47e3a4e65bf390ee1d39a0
1 parent 76a5c2d commit 56a40f3

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

src/hotspot/share/oops/instanceKlass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& par
472472
assert(loader_data != nullptr, "invariant");
473473

474474
InstanceKlass* ik;
475-
const bool use_class_space = parser.klass_needs_narrow_id();
475+
const bool use_class_space = UseClassMetaspaceForAllClasses || parser.klass_needs_narrow_id();
476476

477477
// Allocation
478478
if (parser.is_instance_ref_klass()) {

src/hotspot/share/oops/klass.inline.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2025, 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
@@ -182,6 +182,6 @@ inline bool Klass::needs_narrow_id() const {
182182
// never instantiated classes out of class space lessens the class space pressure.
183183
// For more details, see JDK-8338526.
184184
// Note: don't call this function before access flags are initialized.
185-
return !is_abstract() && !is_interface();
185+
return UseClassMetaspaceForAllClasses || (!is_abstract() && !is_interface());
186186
}
187187
#endif // SHARE_OOPS_KLASS_INLINE_HPP

src/hotspot/share/runtime/globals.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,10 @@ const int ObjectAlignmentInBytes = 8;
20122012
develop(uint, BinarySearchThreshold, 16, \
20132013
"Minimal number of elements in a sorted collection to prefer" \
20142014
"binary search over simple linear search." ) \
2015+
\
2016+
product(bool, UseClassMetaspaceForAllClasses, false, DIAGNOSTIC, \
2017+
"Use the class metaspace for all classes including " \
2018+
"abstract and interface classes.") \
20152019

20162020
// end of RUNTIME_FLAGS
20172021

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMetaspaceConstantImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2025, 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
@@ -95,7 +95,7 @@ public boolean isCompressible() {
9595
}
9696

9797
private boolean canBeStoredInCompressibleMetaSpace() {
98-
if (metaspaceObject instanceof HotSpotResolvedJavaType t && !t.isArray()) {
98+
if (!HotSpotVMConfig.config().useClassMetaspaceForAllClasses && metaspaceObject instanceof HotSpotResolvedJavaType t && !t.isArray()) {
9999
// As of JDK-8338526, interface and abstract types are not stored
100100
// in compressible metaspace.
101101
return !t.isInterface() && !t.isAbstract();

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2025, 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
@@ -67,6 +67,8 @@ static String getHostArchitectureName() {
6767

6868
final boolean useCompressedOops = getFlag("UseCompressedOops", Boolean.class);
6969

70+
final boolean useClassMetaspaceForAllClasses = getFlag("UseClassMetaspaceForAllClasses", Boolean.class);
71+
7072
final int objectAlignment = getFlag("ObjectAlignmentInBytes", Integer.class);
7173

7274
final int klassOffsetInBytes = getFieldValue("CompilerToVM::Data::oopDesc_klass_offset_in_bytes", Integer.class, "int");

0 commit comments

Comments
 (0)