Skip to content

Commit

Permalink
Update JDK
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Oct 28, 2024
1 parent 958be71 commit 7ca1515
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 22 deletions.
2 changes: 1 addition & 1 deletion jdk
Submodule jdk updated 385 files
3 changes: 2 additions & 1 deletion process-patch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@
s[ClassDesc\.ofInternalName][ExtraClassDesc.ofInternalName]g;
s[java(.)lang.classfile][io$1github$1dmlloyd$1classfile]g;
s[jdk(.)internal.classfile][io$1github$1dmlloyd$1classfile]g;
s[(import jdk\.internal\.constant\.(Reference|Primitive)ClassDescImpl.*)][//$1]g;
s[(import jdk\.internal\.constant\.(ReferenceClass|PrimitiveClass|ClassOrInterface)DescImpl.*)][//$1]g;
s[jdk(.)internal.constant][io$1github$1dmlloyd$1classfile$1extras$1constant]g;
s[package java\.lang\.reflect][package io.github.dmlloyd.classfile.extras.reflect]g;
s[package java\.lang\.constant][package io.github.dmlloyd.classfile.extras.constant]g;
s[src/java\.base/share/classes][src/main/java]g;
s[(import jdk\.internal\..*)][//$1]g;
s[(import sun\..*)][//$1]g;
print $_;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
*/
package io.github.dmlloyd.classfile.extras.constant;

//import jdk.internal.vm.annotation.Stable;
//import sun.invoke.util.Wrapper;

import java.lang.constant.ClassDesc;
import java.lang.constant.ConstantDesc;
import java.lang.constant.MethodTypeDesc;
Expand All @@ -41,6 +44,7 @@ public final class ConstantUtils {
public static final ClassDesc[] EMPTY_CLASSDESC = new ClassDesc[0];
public static final int MAX_ARRAY_TYPE_DESC_DIMENSIONS = 255;
public static final ClassDesc CD_module_info = binaryNameToDesc("module-info");
public static ClassDesc CD_Object_array; // set from ConstantDescs, avoid circular initialization

private static final Set<String> pointyNames = Set.of(ExtraConstantDescs.INIT_NAME, ExtraConstantDescs.CLASS_INIT_NAME);

Expand All @@ -64,6 +68,17 @@ public static ClassDesc binaryNameToDesc(String binaryName) {
return ClassDesc.of(binaryName);
}

/**
* Creates a {@linkplain ClassDesc} from a pre-validated internal name
* for a class or interface type. Validated version of {@link
* ClassDesc#ofInternalName(String)}.
*
* @param internalName a binary name
*/
public static ClassDesc internalNameToDesc(String internalName) {
return ClassDesc.ofDescriptor(concat("L", internalName, ";"));
}

/**
* Creates a ClassDesc from a Class object, requires that this class
* can always be described nominally, i.e. this class is not a
Expand All @@ -82,6 +97,17 @@ public static ClassDesc referenceClassDesc(Class<?> type) {
return type.describeConstable().orElseThrow();
}

/**
* Creates a {@linkplain ClassDesc} from a pre-validated descriptor string
* for a class or interface type or an array type.
*
* @param descriptor a field descriptor string for a class or interface type
* @jvms 4.3.2 Field Descriptors
*/
public static ClassDesc referenceClassDesc(String descriptor) {
return ClassDesc.ofDescriptor(descriptor);
}

/**
* Creates a MethodTypeDesc from a MethodType object, requires that
* the type can be described nominally, i.e. all of its return
Expand Down Expand Up @@ -112,8 +138,9 @@ public static MethodTypeDesc methodTypeDesc(Class<?> returnType, Class<?>[] para
public static String validateBinaryClassName(String name) {
for (int i = 0; i < name.length(); i++) {
char ch = name.charAt(i);
if (ch == ';' || ch == '[' || ch == '/')
throw new IllegalArgumentException("Invalid class name: " + name);
if (ch == ';' || ch == '[' || ch == '/'
|| ch == '.' && (i == 0 || i + 1 == name.length() || name.charAt(i - 1) == '.'))
throw invalidClassName(name);
}
return name;
}
Expand All @@ -130,8 +157,9 @@ public static String validateBinaryClassName(String name) {
public static String validateInternalClassName(String name) {
for (int i = 0; i < name.length(); i++) {
char ch = name.charAt(i);
if (ch == ';' || ch == '[' || ch == '.')
throw new IllegalArgumentException("Invalid class name: " + name);
if (ch == ';' || ch == '[' || ch == '.'
|| ch == '/' && (i == 0 || i + 1 == name.length() || name.charAt(i - 1) == '/'))
throw invalidClassName(name);
}
return name;
}
Expand Down Expand Up @@ -228,10 +256,24 @@ public static void validateClassOrInterface(ClassDesc classDesc) {
throw new IllegalArgumentException("not a class or interface type: " + classDesc);
}

public static int arrayDepth(String descriptorString) {
public static void validateArrayRank(int rank) {
// array rank must be representable with u1 and nonzero
if (rank == 0 || (rank & ~0xFF) != 0) {
throw new IllegalArgumentException(invalidArrayRankMessage(rank));
}
}

/**
* Retrieves the array depth on a trusted descriptor.
* Uses a simple loop with the assumption that most descriptors have
* 0 or very low array depths.
*/
public static int arrayDepth(String descriptorString, int off) {
int depth = 0;
while (descriptorString.charAt(depth) == '[')
while (descriptorString.charAt(off) == '[') {
depth++;
off++;
}
return depth;
}

Expand Down Expand Up @@ -262,6 +304,14 @@ public static ClassDesc forPrimitiveType(String descriptor, int offset) {
};
}

static String invalidArrayRankMessage(int rank) {
return "Array rank must be within [1, 255]: " + rank;
}

static IllegalArgumentException invalidClassName(String className) {
return new IllegalArgumentException("Invalid class name: ".concat(className));
}

static IllegalArgumentException badMethodDescriptor(String descriptor) {
return new IllegalArgumentException("Bad method descriptor: " + descriptor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
import java.util.Arrays;
import java.util.List;

import io.github.dmlloyd.classfile.extras.constant.ConstantUtils;

import static io.github.dmlloyd.classfile.constantpool.PoolEntry.*;
import static java.util.Objects.requireNonNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@
import java.util.Objects;
import java.util.stream.Collectors;

//import io.github.dmlloyd.classfile.extras.constant.ClassOrInterfaceDescImpl;
//import jdk.internal.util.Preconditions;

import static io.github.dmlloyd.classfile.ClassFile.ACC_STATIC;
import static io.github.dmlloyd.classfile.ClassFile.*;
import static io.github.dmlloyd.classfile.constantpool.PoolEntry.*;
import static java.lang.constant.ConstantDescs.*;
import static io.github.dmlloyd.classfile.impl.RawBytecodeHelper.*;
Expand Down Expand Up @@ -1067,7 +1068,7 @@ Frame dec1PushStack(ClassDesc desc) {
if (desc == CD_double) return decStack1PushStack(Type.DOUBLE_TYPE, Type.DOUBLE2_TYPE);
return desc == CD_void ? this
: decStack1PushStack(
desc.isPrimitive()
desc.isPrimitive()
? (desc == CD_float ? Type.FLOAT_TYPE : Type.INTEGER_TYPE)
: Type.referenceType(desc));
}
Expand Down Expand Up @@ -1272,7 +1273,7 @@ void setLocalsFromArg(String name, MethodTypeDesc methodDesc, boolean isStatic,
locals[localsSize + 1] = Type.DOUBLE2_TYPE;
localsSize += 2;
} else {
if (! desc.isPrimitive()) {
if (!desc.isPrimitive()) {
type = Type.referenceType(desc);
} else if (desc == CD_float) {
type = Type.FLOAT_TYPE;
Expand Down Expand Up @@ -1457,14 +1458,14 @@ private static record Type(int tag, ClassDesc sym, int bci) {
//frequently used types to reduce footprint
static final Type OBJECT_TYPE = referenceType(CD_Object),
THROWABLE_TYPE = referenceType(CD_Throwable),
INT_ARRAY_TYPE = referenceType(int[].class.describeConstable().orElseThrow()),
BOOLEAN_ARRAY_TYPE = referenceType(boolean[].class.describeConstable().orElseThrow()),
BYTE_ARRAY_TYPE = referenceType(byte[].class.describeConstable().orElseThrow()),
CHAR_ARRAY_TYPE = referenceType(char[].class.describeConstable().orElseThrow()),
SHORT_ARRAY_TYPE = referenceType(short[].class.describeConstable().orElseThrow()),
LONG_ARRAY_TYPE = referenceType(long[].class.describeConstable().orElseThrow()),
DOUBLE_ARRAY_TYPE = referenceType(double[].class.describeConstable().orElseThrow()),
FLOAT_ARRAY_TYPE = referenceType(float[].class.describeConstable().orElseThrow()),
INT_ARRAY_TYPE = referenceType(CD_int.arrayType()),
BOOLEAN_ARRAY_TYPE = referenceType(CD_boolean.arrayType()),
BYTE_ARRAY_TYPE = referenceType(CD_byte.arrayType()),
CHAR_ARRAY_TYPE = referenceType(CD_char.arrayType()),
SHORT_ARRAY_TYPE = referenceType(CD_short.arrayType()),
LONG_ARRAY_TYPE = referenceType(CD_long.arrayType()),
DOUBLE_ARRAY_TYPE = referenceType(CD_double.arrayType()),
FLOAT_ARRAY_TYPE = referenceType(CD_float.arrayType()),
STRING_TYPE = referenceType(CD_String),
CLASS_TYPE = referenceType(CD_Class),
METHOD_HANDLE_TYPE = referenceType(CD_MethodHandle),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/github/dmlloyd/classfile/impl/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import java.util.function.Function;

//import jdk.internal.access.SharedSecrets;
//import io.github.dmlloyd.classfile.extras.constant.ReferenceClassDescImpl;
//import io.github.dmlloyd.classfile.extras.constant.ClassOrInterfaceDescImpl;
//import jdk.internal.vm.annotation.ForceInline;
//import jdk.internal.vm.annotation.Stable;

Expand Down

0 comments on commit 7ca1515

Please sign in to comment.