Skip to content

Commit

Permalink
make JVMCI aware that some klass pointers are not compressible
Browse files Browse the repository at this point in the history
  • Loading branch information
dougxc committed Sep 11, 2024
1 parent 0b3f2e6 commit d151bfa
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/hotspot/share/jvmci/jvmciCodeInstaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ narrowKlass CodeInstaller::record_narrow_metadata_reference(CodeSection* section
int index = _oop_recorder->find_index(klass);
section->relocate(dest, metadata_Relocation::spec(index));
JVMCI_event_3("narrowKlass[%d of %d] = %s", index, _oop_recorder->metadata_count(), klass->name()->as_C_string());
guarantee(CompressedKlassPointers::is_in_encoding_range(klass), "klass cannot be compressed: %s", klass->external_name());
return CompressedKlassPointers::encode(klass);
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,17 @@ private DirectHotSpotObjectConstantImpl(Object object, boolean compressed) {

@Override
public JavaConstant compress() {
assert !compressed;
if (compressed) {
throw new IllegalArgumentException("already compressed: " + this);
}
return new DirectHotSpotObjectConstantImpl(object, true);
}

@Override
public JavaConstant uncompress() {
assert compressed;
if (!compressed) {
throw new IllegalArgumentException("not compressed: " + this);
}
return new DirectHotSpotObjectConstantImpl(object, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ public boolean isCompressed() {
return true;
}

@Override
public boolean isCompressible() {
return false;
}

@Override
public Constant compress() {
throw new IllegalArgumentException();
throw new IllegalArgumentException("not compressible");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,29 @@
*/
public interface HotSpotConstant extends Constant {

/**
* Determines if this constant is compressed.
*/
boolean isCompressed();

/**
* Determines if this constant is compressible.
*/
boolean isCompressible();

/**
* Gets a compressed version of this uncompressed constant.
*
* @throws IllegalArgumentException if this is a compressed constant
* or this constant is not compressible
*/
Constant compress();

/**
* Gets an uncompressed version of this compressed constant.
*
* @throws IllegalArgumentException if this is an uncompressed constant
* or this constant is not compressible
*/
Constant uncompress();
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ static MetaspaceObject getMetaspaceObject(Constant constant) {
private HotSpotMetaspaceConstantImpl(MetaspaceObject metaspaceObject, boolean compressed) {
this.metaspaceObject = metaspaceObject;
this.compressed = compressed;
if (compressed && !isCompressible()) {
throw new IllegalArgumentException("constant cannot be compressed: " + metaspaceObject);
}
}

@Override
Expand Down Expand Up @@ -83,17 +86,31 @@ public boolean isCompressed() {
return compressed;
}

@Override
public boolean isCompressible() {
if (metaspaceObject instanceof HotSpotResolvedJavaType t && !t.isArray()) {
// As of JDK-8338526, interface and abstract types are not stored
// in compressible metaspace.
return !t.isInterface() && !t.isAbstract();
}
return true;
}

@Override
public Constant compress() {
assert !isCompressed();
if (compressed) {
throw new IllegalArgumentException("already compressed: " + this);
}
HotSpotMetaspaceConstantImpl res = HotSpotMetaspaceConstantImpl.forMetaspaceObject(metaspaceObject, true);
assert res.isCompressed();
return res;
}

@Override
public Constant uncompress() {
assert isCompressed();
if (!compressed) {
throw new IllegalArgumentException("not compressed: " + this);
}
HotSpotMetaspaceConstantImpl res = HotSpotMetaspaceConstantImpl.forMetaspaceObject(metaspaceObject, false);
assert !res.isCompressed();
return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public boolean isCompressed() {
return compressed;
}

@Override
public boolean isCompressible() {
return true;
}

@Override
public abstract JavaConstant compress();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,17 @@ static void clearHandle(long handle) {

@Override
public JavaConstant compress() {
assert !compressed;
if (compressed) {
throw new IllegalArgumentException("already compressed: " + this);
}
return new IndirectHotSpotObjectConstantImpl(this, true);
}

@Override
public JavaConstant uncompress() {
assert compressed;
if (!compressed) {
throw new IllegalArgumentException("not compressed: " + this);
}
return new IndirectHotSpotObjectConstantImpl(this, false);
}

Expand Down

0 comments on commit d151bfa

Please sign in to comment.