Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/hotspot/share/ci/ciField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,7 @@ bool ciField::is_call_site_target() {

bool ciField::is_autobox_cache() {
ciSymbol* klass_name = holder()->name();
// The box cache is disabled when boxes are value classes.
return (!Arguments::is_valhalla_enabled() &&
name() == ciSymbols::cache_field_name() &&
return (name() == ciSymbols::cache_field_name() &&
holder()->uses_default_loader() &&
(klass_name == ciSymbols::java_lang_Character_CharacterCache() ||
klass_name == ciSymbols::java_lang_Byte_ByteCache() ||
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/opto/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
} else {
guarantee(require_constant || oop_constant->should_be_constant(), "con_type must get computed");
con_type = TypeOopPtr::make_from_constant(oop_constant, require_constant);
if (Compile::current()->eliminate_boxing() && is_autobox_cache) {
if (is_autobox_cache) {
Comment thread
TobiHartmann marked this conversation as resolved.
Outdated
con_type = con_type->is_aryptr()->cast_to_autobox_cache();
}
if (stable_dimension > 0) {
Expand Down
5 changes: 0 additions & 5 deletions src/hotspot/share/runtime/deoptimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,6 @@ template<typename PrimitiveType, typename CacheType, typename BoxType> class Box
protected:
static BoxCache<PrimitiveType, CacheType, BoxType> *_singleton;
BoxCache(Thread* thread) {
assert(!Arguments::is_valhalla_enabled(), "Should not use box caches with enable preview");
InstanceKlass* ik = BoxCacheBase<CacheType>::find_cache_klass(thread, CacheType::symbol());
if (ik->is_in_error_state()) {
_low = 1;
Expand Down Expand Up @@ -1256,10 +1255,6 @@ class BooleanBoxCache : public BoxCacheBase<java_lang_Boolean> {
BooleanBoxCache* BooleanBoxCache::_singleton = nullptr;

oop Deoptimization::get_cached_box(AutoBoxObjectValue* bv, frame* fr, RegisterMap* reg_map, bool& cache_init_error, TRAPS) {
Comment thread
TobiHartmann marked this conversation as resolved.
if (Arguments::enable_preview()) {
// Box caches are not used with enable preview.
return nullptr;
}
Klass* k = java_lang_Class::as_Klass(bv->klass()->as_ConstantOopReadValue()->value()());
BasicType box_type = vmClasses::box_klass_type(k);
if (box_type != T_OBJECT) {
Expand Down
5 changes: 1 addition & 4 deletions src/java.base/share/classes/java/lang/Boolean.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,7 @@ public boolean booleanValue() {
@IntrinsicCandidate
@DeserializeConstructor
public static Boolean valueOf(boolean b) {
if (!PreviewFeatures.isEnabled()) {
return (b ? TRUE : FALSE);
}
return new Boolean(b);
return (b ? TRUE : FALSE);
}

/**
Expand Down
42 changes: 22 additions & 20 deletions src/java.base/share/classes/java/lang/Byte.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import jdk.internal.misc.CDS;
import jdk.internal.misc.PreviewFeatures;
import jdk.internal.value.DeserializeConstructor;
import jdk.internal.value.ValueClass;
import jdk.internal.vm.annotation.AOTSafeClassInitializer;
import jdk.internal.vm.annotation.IntrinsicCandidate;
import jdk.internal.vm.annotation.Stable;
Expand Down Expand Up @@ -123,25 +124,29 @@ private ByteCache() {}
static Byte[] archivedCache;

static {
if (!PreviewFeatures.isEnabled()) {
final int size = -(-128) + 127 + 1;
final int size = -(-128) + 127 + 1;

// Load and use the archived cache if it exists
// Load and use the archived cache if it exists
if (!PreviewFeatures.isEnabled()) {
CDS.initializeFromArchive(ByteCache.class);
Comment thread
TobiHartmann marked this conversation as resolved.
Outdated
if (archivedCache == null) {
Byte[] c = new Byte[size];
byte value = (byte)-128;
for(int i = 0; i < size; i++) {
c[i] = new Byte(value++);
}
archivedCache = c;
}
if (archivedCache == null) {
Byte[] c = newCacheArray(size);
byte value = (byte)-128;
for(int i = 0; i < size; i++) {
c[i] = new Byte(value++);
}
cache = archivedCache;
assert cache.length == size;
} else {
cache = null;
assert archivedCache == null;
archivedCache = c;
}
cache = archivedCache;
assert cache.length == size;
}

private static Byte[] newCacheArray(int size) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this - we should be able to revert to mainline code. The only code I think that need any update would be the old new Byte[size] should become (Byte[]) ValueClass.newReferenceArray(Byte.class, size) both with and without preview.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new Byte[size] should become (Byte[]) ValueClass.newReferenceArray(Byte.class, size) both with and without preview.

@liach That's not possible because ValueClass.newReferenceArray throws when preview is disabled because boxes are identity classes then.

if (PreviewFeatures.isEnabled()) {
return (Byte[]) ValueClass.newReferenceArray(Byte.class, size);
}
return new Byte[size];
}
}

Expand Down Expand Up @@ -173,11 +178,8 @@ private ByteCache() {}
@IntrinsicCandidate
@DeserializeConstructor
public static Byte valueOf(byte b) {
if (!PreviewFeatures.isEnabled()) {
final int offset = 128;
return ByteCache.cache[(int) b + offset];
}
return new Byte(b);
final int offset = 128;
return ByteCache.cache[(int) b + offset];
}

/**
Expand Down
39 changes: 21 additions & 18 deletions src/java.base/share/classes/java/lang/Character.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import jdk.internal.misc.CDS;
import jdk.internal.misc.PreviewFeatures;
import jdk.internal.value.DeserializeConstructor;
import jdk.internal.value.ValueClass;
import jdk.internal.vm.annotation.AOTSafeClassInitializer;
import jdk.internal.vm.annotation.IntrinsicCandidate;
import jdk.internal.vm.annotation.Stable;
Expand Down Expand Up @@ -9435,24 +9436,28 @@ private CharacterCache(){}
static Character[] archivedCache;

static {
if (!PreviewFeatures.isEnabled()) {
int size = 127 + 1;
int size = 127 + 1;

// Load and use the archived cache if it exists
// Load and use the archived cache if it exists
if (!PreviewFeatures.isEnabled()) {
Comment thread
TobiHartmann marked this conversation as resolved.
Outdated
CDS.initializeFromArchive(CharacterCache.class);
if (archivedCache == null) {
Character[] c = new Character[size];
for (int i = 0; i < size; i++) {
c[i] = new Character((char) i);
}
archivedCache = c;
}
if (archivedCache == null) {
Character[] c = newCacheArray(size);
for (int i = 0; i < size; i++) {
c[i] = new Character((char) i);
}
cache = archivedCache;
assert cache.length == size;
} else {
cache = null;
assert archivedCache == null;
archivedCache = c;
}
cache = archivedCache;
assert cache.length == size;
}

private static Character[] newCacheArray(int size) {
if (PreviewFeatures.isEnabled()) {
return (Character[]) ValueClass.newReferenceArray(Character.class, size);
}
return new Character[size];
}
}

Expand Down Expand Up @@ -9487,10 +9492,8 @@ private CharacterCache(){}
@IntrinsicCandidate
@DeserializeConstructor
public static Character valueOf(char c) {
if (!PreviewFeatures.isEnabled()) {
if (c <= 127) { // must cache
return CharacterCache.cache[(int) c];
}
if (c <= 127) { // must cache
return CharacterCache.cache[(int) c];
}
return new Character(c);
}
Expand Down
45 changes: 25 additions & 20 deletions src/java.base/share/classes/java/lang/Integer.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import jdk.internal.misc.VM;
import jdk.internal.util.DecimalDigits;
import jdk.internal.value.DeserializeConstructor;
import jdk.internal.value.ValueClass;
import jdk.internal.vm.annotation.AOTRuntimeSetup;
import jdk.internal.vm.annotation.AOTSafeClassInitializer;
import jdk.internal.vm.annotation.ForceInline;
Expand Down Expand Up @@ -913,12 +914,7 @@ private static final class IntegerCache {
static Integer[] archivedCache;

static {
if (!PreviewFeatures.isEnabled()) {
runtimeSetup();
} else {
cache = null;
assert archivedCache == null;
}
runtimeSetup();
}

@AOTRuntimeSetup
Expand All @@ -939,18 +935,22 @@ private static void runtimeSetup() {
high = h;

Integer[] precomputed = null;
if (cache != null) {
// IntegerCache has been AOT-initialized.
precomputed = cache;
} else {
// Legacy CDS archive support (to be deprecated):
// Load IntegerCache.archivedCache from archive, if possible
CDS.initializeFromArchive(IntegerCache.class);
precomputed = archivedCache;
if (!PreviewFeatures.isEnabled()) {
if (cache != null) {
// IntegerCache has been AOT-initialized.
precomputed = cache;
} else {
// Legacy CDS archive support (to be deprecated):
// Load IntegerCache.archivedCache from archive, if possible
CDS.initializeFromArchive(IntegerCache.class);
precomputed = archivedCache;
}
}

cache = loadOrInitializeCache(precomputed);
archivedCache = cache; // Legacy CDS archive support (to be deprecated)
if (!PreviewFeatures.isEnabled()) {
archivedCache = cache; // Legacy CDS archive support (to be deprecated)
Comment thread
TobiHartmann marked this conversation as resolved.
Outdated
}
// range [-128, 127] must be interned (JLS7 5.1.7)
assert IntegerCache.high >= 127;
}
Expand All @@ -963,7 +963,7 @@ private static Integer[] loadOrInitializeCache(Integer[] precomputed) {
return precomputed;
}

Integer[] c = new Integer[size];
Integer[] c = newCacheArray(size);
int j = low;
// If we loading a precomputed cache (from AOT cache or CDS archive),
// we must use all instances from it.
Expand All @@ -982,6 +982,13 @@ private static Integer[] loadOrInitializeCache(Integer[] precomputed) {
return c;
}

private static Integer[] newCacheArray(int size) {
if (PreviewFeatures.isEnabled()) {
return (Integer[]) ValueClass.newReferenceArray(Integer.class, size);
}
return new Integer[size];
}

private IntegerCache() {}
}

Expand Down Expand Up @@ -1015,10 +1022,8 @@ private IntegerCache() {}
@IntrinsicCandidate
@DeserializeConstructor
public static Integer valueOf(int i) {
if (!PreviewFeatures.isEnabled()) {
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + (-IntegerCache.low)];
}
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + (-IntegerCache.low)];
return new Integer(i);
}

Expand Down
43 changes: 23 additions & 20 deletions src/java.base/share/classes/java/lang/Long.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import jdk.internal.misc.CDS;
import jdk.internal.misc.PreviewFeatures;
import jdk.internal.value.DeserializeConstructor;
import jdk.internal.value.ValueClass;
import jdk.internal.util.DecimalDigits;
import jdk.internal.vm.annotation.AOTSafeClassInitializer;
import jdk.internal.vm.annotation.ForceInline;
Expand Down Expand Up @@ -933,25 +934,29 @@ private LongCache() {}
static Long[] archivedCache;

static {
if (!PreviewFeatures.isEnabled()) {
int size = -(-128) + 127 + 1;
int size = -(-128) + 127 + 1;

// Load and use the archived cache if it exists
// Load and use the archived cache if it exists
if (!PreviewFeatures.isEnabled()) {
CDS.initializeFromArchive(LongCache.class);
if (archivedCache == null) {
Long[] c = new Long[size];
long value = -128;
for(int i = 0; i < size; i++) {
c[i] = new Long(value++);
}
archivedCache = c;
}
if (archivedCache == null) {
Long[] c = newCacheArray(size);
long value = -128;
for(int i = 0; i < size; i++) {
c[i] = new Long(value++);
}
cache = archivedCache;
assert cache.length == size;
} else {
cache = null;
assert archivedCache == null;
archivedCache = c;
}
cache = archivedCache;
assert cache.length == size;
}

private static Long[] newCacheArray(int size) {
if (PreviewFeatures.isEnabled()) {
return (Long[]) ValueClass.newReferenceArray(Long.class, size);
}
return new Long[size];
}
}

Expand Down Expand Up @@ -985,11 +990,9 @@ private LongCache() {}
@IntrinsicCandidate
@DeserializeConstructor
public static Long valueOf(long l) {
if (!PreviewFeatures.isEnabled()) {
if (l >= -128 && l <= 127) { // will cache
final int offset = 128;
return LongCache.cache[(int) l + offset];
}
if (l >= -128 && l <= 127) { // will cache
final int offset = 128;
return LongCache.cache[(int) l + offset];
}
return new Long(l);
}
Expand Down
Loading