Skip to content

Commit fa00b24

Browse files
committed
8365823: Revert storing abstract and interface Klasses to non-class metaspace
Reviewed-by: kvn, shade, stuefe
1 parent 2bff417 commit fa00b24

File tree

19 files changed

+38
-97
lines changed

19 files changed

+38
-97
lines changed

src/hotspot/share/ci/ciKlass.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class ciKlass : public ciType {
107107
bool is_in_encoding_range() {
108108
Klass* k = get_Klass();
109109
bool is_in_encoding_range = CompressedKlassPointers::is_encodable(k);
110-
assert(is_in_encoding_range || k->is_interface() || k->is_abstract(), "sanity");
110+
assert(is_in_encoding_range, "sanity");
111111
return is_in_encoding_range;
112112
}
113113

src/hotspot/share/classfile/classFileParser.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5929,15 +5929,6 @@ bool ClassFileParser::is_java_lang_ref_Reference_subclass() const {
59295929
return _super_klass->reference_type() != REF_NONE;
59305930
}
59315931

5932-
// Returns true if the future Klass will need to be addressable with a narrow Klass ID.
5933-
bool ClassFileParser::klass_needs_narrow_id() const {
5934-
// Classes that are never instantiated need no narrow Klass Id, since the
5935-
// only point of having a narrow id is to put it into an object header. Keeping
5936-
// never instantiated classes out of class space lessens the class space pressure.
5937-
// For more details, see JDK-8338526.
5938-
return !is_interface() && !is_abstract();
5939-
}
5940-
59415932
// ----------------------------------------------------------------------------
59425933
// debugging
59435934

src/hotspot/share/classfile/classFileParser.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,6 @@ class ClassFileParser {
515515

516516
bool is_hidden() const { return _is_hidden; }
517517
bool is_interface() const { return _access_flags.is_interface(); }
518-
bool is_abstract() const { return _access_flags.is_abstract(); }
519-
520-
// Returns true if the Klass to be generated will need to be addressable
521-
// with a narrow Klass ID.
522-
bool klass_needs_narrow_id() const;
523518

524519
ClassLoaderData* loader_data() const { return _loader_data; }
525520
const Symbol* class_name() const { return _class_name; }

src/hotspot/share/classfile/systemDictionaryShared.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ DEBUG_ONLY(bool SystemDictionaryShared::_class_loading_may_happen = true;)
8989
#ifdef ASSERT
9090
static void check_klass_after_loading(const Klass* k) {
9191
#ifdef _LP64
92-
if (k != nullptr && UseCompressedClassPointers && k->needs_narrow_id()) {
92+
if (k != nullptr && UseCompressedClassPointers) {
9393
CompressedKlassPointers::check_encodable(k);
9494
}
9595
#endif

src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceIdKlassQueue.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "jfr/support/jfrThreadLocal.hpp"
3030
#include "jfr/utilities/jfrEpochQueue.inline.hpp"
3131
#include "jfr/utilities/jfrTypes.hpp"
32+
#include "memory/metaspace.hpp"
3233
#include "oops/compressedKlass.inline.hpp"
3334
#include "utilities/macros.hpp"
3435

@@ -73,14 +74,13 @@ static size_t element_size(bool compressed) {
7374
return compressed ? NARROW_ELEMENT_SIZE : ELEMENT_SIZE;
7475
}
7576

76-
static bool can_compress_element(const Klass* klass) {
77-
return CompressedKlassPointers::is_encodable(klass) &&
78-
JfrTraceId::load_raw(klass) < uncompressed_threshold;
77+
static bool can_compress_element(traceid id) {
78+
return Metaspace::using_class_space() && id < uncompressed_threshold;
7979
}
8080

8181
static size_t element_size(const Klass* klass) {
8282
assert(klass != nullptr, "invariant");
83-
return element_size(can_compress_element(klass));
83+
return element_size(can_compress_element(JfrTraceId::load_raw(klass)));
8484
}
8585

8686
static bool is_unloaded(traceid id, bool previous_epoch) {
@@ -136,8 +136,7 @@ static inline void store_traceid(JfrEpochQueueNarrowKlassElement* element, trace
136136
}
137137

138138
static void store_compressed_element(traceid id, const Klass* klass, u1* pos) {
139-
assert(can_compress_element(klass), "invariant");
140-
assert(id == JfrTraceId::load_raw(klass), "invariant");
139+
assert(can_compress_element(id), "invariant");
141140
JfrEpochQueueNarrowKlassElement* const element = new (pos) JfrEpochQueueNarrowKlassElement();
142141
store_traceid(element, id);
143142
element->compressed_klass = encode(klass);
@@ -153,7 +152,7 @@ static void store_element(const Klass* klass, u1* pos) {
153152
assert(pos != nullptr, "invariant");
154153
assert(klass != nullptr, "invariant");
155154
const traceid id = JfrTraceId::load_raw(klass);
156-
if (can_compress_element(klass)) {
155+
if (can_compress_element(id)) {
157156
store_compressed_element(id, klass, pos);
158157
return;
159158
}

src/hotspot/share/memory/allocation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ void* MetaspaceObj::operator new(size_t size, ClassLoaderData* loader_data,
7373
MetaspaceObj::Type type, TRAPS) throw() {
7474
// Klass has its own operator new
7575
assert(type != ClassType, "class has its own operator new");
76-
return Metaspace::allocate(loader_data, word_size, type, /*use_class_space*/ false, THREAD);
76+
return Metaspace::allocate(loader_data, word_size, type, THREAD);
7777
}
7878

7979
void* MetaspaceObj::operator new(size_t size, ClassLoaderData* loader_data,
8080
size_t word_size,
8181
MetaspaceObj::Type type) throw() {
8282
assert(!Thread::current()->is_Java_thread(), "only allowed by non-Java thread");
8383
assert(type != ClassType, "class has its own operator new");
84-
return Metaspace::allocate(loader_data, word_size, type, /*use_class_space*/ false);
84+
return Metaspace::allocate(loader_data, word_size, type);
8585
}
8686

8787
// This is used for allocating training data. We are allocating training data in many cases where a GC cannot be triggered.

src/hotspot/share/memory/metaspace.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ size_t Metaspace::max_allocation_word_size() {
872872
// is suitable for calling from non-Java threads.
873873
// Callers are responsible for checking null.
874874
MetaWord* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size,
875-
MetaspaceObj::Type type, bool use_class_space) {
875+
MetaspaceObj::Type type) {
876876
assert(word_size <= Metaspace::max_allocation_word_size(),
877877
"allocation size too large (%zu)", word_size);
878878

@@ -882,7 +882,7 @@ MetaWord* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size,
882882
// Deal with concurrent unloading failed allocation starvation
883883
MetaspaceCriticalAllocation::block_if_concurrent_purge();
884884

885-
MetadataType mdtype = use_class_space ? ClassType : NonClassType;
885+
MetadataType mdtype = (type == MetaspaceObj::ClassType) ? ClassType : NonClassType;
886886

887887
// Try to allocate metadata.
888888
MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype);
@@ -906,18 +906,18 @@ MetaWord* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size,
906906
}
907907

908908
MetaWord* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size,
909-
MetaspaceObj::Type type, bool use_class_space, TRAPS) {
909+
MetaspaceObj::Type type, TRAPS) {
910910

911911
if (HAS_PENDING_EXCEPTION) {
912912
assert(false, "Should not allocate with exception pending");
913913
return nullptr; // caller does a CHECK_NULL too
914914
}
915915
assert(!THREAD->owns_locks(), "allocating metaspace while holding mutex");
916916

917-
MetaWord* result = allocate(loader_data, word_size, type, use_class_space);
917+
MetaWord* result = allocate(loader_data, word_size, type);
918918

919919
if (result == nullptr) {
920-
MetadataType mdtype = use_class_space ? ClassType : NonClassType;
920+
MetadataType mdtype = (type == MetaspaceObj::ClassType) ? ClassType : NonClassType;
921921
tracer()->report_metaspace_allocation_failure(loader_data, word_size, type, mdtype);
922922

923923
// Allocation failed.

src/hotspot/share/memory/metaspace.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ class Metaspace : public AllStatic {
120120
static constexpr size_t min_allocation_word_size = min_allocation_alignment_words;
121121

122122
static MetaWord* allocate(ClassLoaderData* loader_data, size_t word_size,
123-
MetaspaceObj::Type type, bool use_class_space, TRAPS);
123+
MetaspaceObj::Type type, TRAPS);
124124

125125
// Non-TRAPS version of allocate which can be called by a non-Java thread, that returns
126126
// null on failure.
127127
static MetaWord* allocate(ClassLoaderData* loader_data, size_t word_size,
128-
MetaspaceObj::Type type, bool use_class_space);
128+
MetaspaceObj::Type type);
129129

130130
// Returns true if the pointer points into class space, non-class metaspace, or the
131131
// metadata portion of the CDS archive.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 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
@@ -34,14 +34,14 @@ template <typename T>
3434
inline void* Array<T>::operator new(size_t size, ClassLoaderData* loader_data, int length, TRAPS) throw() {
3535
size_t word_size = Array::size(length);
3636
return (void*) Metaspace::allocate(loader_data, word_size,
37-
MetaspaceObj::array_type(sizeof(T)), false, THREAD);
37+
MetaspaceObj::array_type(sizeof(T)), THREAD);
3838
}
3939

4040
template <typename T>
4141
inline void* Array<T>::operator new(size_t size, ClassLoaderData* loader_data, int length) throw() {
4242
size_t word_size = Array::size(length);
4343
return (void*) Metaspace::allocate(loader_data, word_size,
44-
MetaspaceObj::array_type(sizeof(T)), false);
44+
MetaspaceObj::array_type(sizeof(T)));
4545
}
4646

4747
template <typename T>

src/hotspot/share/oops/arrayKlass.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@
4141
#include "oops/oop.inline.hpp"
4242
#include "runtime/handles.inline.hpp"
4343

44-
void* ArrayKlass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw() {
45-
return Metaspace::allocate(loader_data, word_size, MetaspaceObj::ClassType, true, THREAD);
46-
}
47-
4844
ArrayKlass::ArrayKlass() {
4945
assert(CDSConfig::is_dumping_static_archive() || CDSConfig::is_using_archive(), "only for CDS");
5046
}

0 commit comments

Comments
 (0)