Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ public ResolvedJavaType getComponentType() {
return this.equals(componentType) ? null : componentType;
}

@Override
public boolean isHidden() {
return (getMiscFlags() & config().jvmAccIsHiddenClass) != 0;
}

@Override
public List<JavaType> getPermittedSubclasses() {
if (isArray() || isPrimitive()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public ResolvedJavaType getElementalType() {
return this;
}

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

@Override
public List<JavaType> getPermittedSubclasses() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ static String getHostArchitectureName() {
final int arrayJUShortDataOffset = getFieldOffset("Array<jushort>::_data", Integer.class);
final int arrayJUShortLengthOffset = getFieldOffset("Array<jushort>::_length", Integer.class, "int");

final int jvmAccIsHiddenClass = getConstant("KlassFlags::_misc_is_hidden_class", Integer.class);
final int jvmAccHasFinalizer = getConstant("KlassFlags::_misc_has_finalizer", Integer.class);
final int jvmFieldFlagInternalShift = getConstant("FieldInfo::FieldFlags::_ff_injected", Integer.class);
final int jvmFieldFlagStableShift = getConstant("FieldInfo::FieldFlags::_ff_stable", Integer.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ default ResolvedJavaType getElementalType() {
@Override
ResolvedJavaType getArrayClass();

/**
* Returns {@code true} if and only if the underlying class is a hidden class.
*
* @return {@code true} if and only if this class is a hidden class
*
* @see Class#isHidden()
*/
boolean isHidden();

/**
* Returns an unmodifiable list of {@link JavaType} objects representing the subclasses or
* subinterfaces that are explicitly permitted to extend or implement this sealed class or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.AnnotatedElement;
Expand Down Expand Up @@ -709,6 +711,36 @@ public void getArrayClassTest() {
}
}

static class HiddenPrototype {}

@Test
public void isHiddenTest() throws IllegalAccessException {
// non-hidden class
assertFalse(TestResolvedJavaType.class.isHidden());
assertFalse(metaAccess.lookupJavaType(TestResolvedJavaType.class).isHidden());
// hidden class
Lookup lookup = MethodHandles.lookup();
byte[] bytes = getClassBytes(HiddenPrototype.class);
Class<?> c = lookup.defineHiddenClass(bytes, true).lookupClass();
assertTrue(c.isHidden());
assertTrue(metaAccess.lookupJavaType(c).isHidden());
}

static byte[] getClassBytes(Class<?> originalClass) {
try (InputStream classFile = originalClass.getResourceAsStream("TestResolvedJavaType$HiddenPrototype.class")) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];

while ((nRead = classFile.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
return buffer.toByteArray();
} catch (IOException e) {
throw new AssertionError(e);
}
}

private static sealed class SealedTestClass
permits PermittedTestClass1, PermittedTestClass3 {
}
Expand Down
Loading