Skip to content

Commit

Permalink
[GR-60346] Separate .class file parser symbols from Espresso symbols.
Browse files Browse the repository at this point in the history
PullRequest: graal/19517
  • Loading branch information
mukel committed Jan 16, 2025
2 parents d9266a9 + a48fde0 commit ff759bc
Show file tree
Hide file tree
Showing 177 changed files with 3,941 additions and 3,492 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
import com.oracle.truffle.espresso.classfile.constantpool.NameAndTypeConstant;
import com.oracle.truffle.espresso.classfile.constantpool.StringConstant;
import com.oracle.truffle.espresso.classfile.constantpool.Utf8Constant;
import com.oracle.truffle.espresso.classfile.descriptors.ModifiedUTF8;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.ModifiedUTF8;

/**
* Immutable, shareable constant-pool representation.
Expand Down Expand Up @@ -243,11 +243,11 @@ public final double doubleAt(int index, String description) {
}
}

public final <T> Symbol<T> symbolAt(int index) {
return symbolAt(index, null);
public final <T> Symbol<T> symbolAtUnsafe(int index) {
return symbolAtUnsafe(index, null);
}

public final <T> Symbol<T> symbolAt(int index, String description) {
public final <T> Symbol<T> symbolAtUnsafe(int index, String description) {
try {
final Utf8Constant constant = (Utf8Constant) at(index);
return constant.unsafeSymbolValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.Objects;

import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Type;
import com.oracle.truffle.espresso.classfile.descriptors.Type;

/**
* Represents an exception handler within the bytecodes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public int getMinorVersion() {
return minorVersion;
}

ImmutableConstantPool patchForHiddenClass(int thisKlassIndex, Symbol<?> newName) {
public ImmutableConstantPool patchForHiddenClass(int thisKlassIndex, Symbol<?> newName) {
int newNamePos = constants.length;
Utf8Constant newNameConstant = new Utf8Constant(newName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.espresso.classfile.descriptors.ErrorUtil;
import com.oracle.truffle.espresso.classfile.descriptors.StaticSymbols;
import com.oracle.truffle.espresso.classfile.descriptors.Name;
import com.oracle.truffle.espresso.classfile.descriptors.ParserSymbols;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Type;
import com.oracle.truffle.espresso.classfile.descriptors.Type;

/**
* Denotes the basic kinds of types in CRI, including the all the Java primitive types, for example,
Expand Down Expand Up @@ -105,8 +105,8 @@ public enum JavaKind {
this.primitiveJavaClass = primitiveJavaClass;
this.boxedJavaClass = boxedJavaClass;
this.basicType = basicType;
this.type = (primitiveJavaClass != null) ? StaticSymbols.putType("" + typeChar) : null;
this.name = StaticSymbols.putName(javaName);
this.type = (primitiveJavaClass != null) ? ParserSymbols.SYMBOLS.putType("" + typeChar) : null;
this.name = ParserSymbols.SYMBOLS.putName(javaName);
this.unwrapMethodName = (primitiveJavaClass != null) ? javaName + "Value" : null;
this.unwrapMethodDesc = (primitiveJavaClass != null) ? "()" + typeChar : null;
this.wrapperValueOfDesc = (primitiveJavaClass != null) ? "(" + typeChar + ")Ljava/lang/" + boxedJavaClass.getSimpleName() + ";" : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@

import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.espresso.classfile.attributes.Attribute;
import com.oracle.truffle.espresso.classfile.descriptors.Name;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Type;
import com.oracle.truffle.espresso.classfile.descriptors.Types;
import com.oracle.truffle.espresso.classfile.descriptors.Type;
import com.oracle.truffle.espresso.classfile.descriptors.TypeSymbols;

public final class ParserField {
public static final ParserField[] EMPTY_ARRAY = new ParserField[0];
Expand All @@ -42,6 +42,7 @@ public final class ParserField {
private final int flags;
private final Symbol<Name> name;
private final Symbol<Type> type;

@CompilationFinal(dimensions = 1) //
private final Attribute[] attributes;

Expand Down Expand Up @@ -85,6 +86,6 @@ public boolean isFinal() {
}

public JavaKind getKind() {
return Types.getJavaKind(type);
return TypeSymbols.getJavaKind(type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.espresso.classfile.attributes.Attribute;
import com.oracle.truffle.espresso.classfile.descriptors.Name;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Type;
import com.oracle.truffle.espresso.classfile.descriptors.Type;

/**
* Immutable raw representation of classes in Espresso, this is the output of the parser, super
Expand Down Expand Up @@ -133,6 +133,10 @@ public Attribute getAttribute(Symbol<Name> attributeName) {
return null;
}

public Attribute[] getAttributes() {
return attributes;
}

public int getThisKlassIndex() {
return thisKlassIndex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.espresso.classfile.attributes.Attribute;
import com.oracle.truffle.espresso.classfile.descriptors.Name;
import com.oracle.truffle.espresso.classfile.descriptors.Signature;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Signature;

/**
* Immutable raw representation of methods in Espresso, this is the output of the parser.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

import com.oracle.truffle.espresso.classfile.constantpool.Utf8Constant;
import com.oracle.truffle.espresso.classfile.descriptors.ByteSequence;
import com.oracle.truffle.espresso.classfile.descriptors.Name;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Type;
import com.oracle.truffle.espresso.classfile.descriptors.Type;
import com.oracle.truffle.espresso.classfile.perf.TimerCollection;

public interface ParsingContext {
Expand All @@ -50,8 +50,6 @@ public interface ParsingContext {

Utf8Constant getOrCreateUtf8Constant(ByteSequence bytes);

long getNewKlassId();

interface Logger {
void log(String message);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import java.util.Objects;

import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.espresso.classfile.descriptors.Name;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;

public class Attribute {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
package com.oracle.truffle.espresso.classfile.attributes;

import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.espresso.classfile.descriptors.Name;
import com.oracle.truffle.espresso.classfile.descriptors.ParserSymbols.ParserNames;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;

public final class BootstrapMethodsAttribute extends Attribute {

public static final Symbol<Name> NAME = Name.BootstrapMethods;
public static final Symbol<Name> NAME = ParserNames.BootstrapMethods;

public Entry[] getEntries() {
return entries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@
import com.oracle.truffle.espresso.classfile.ClassfileParser;
import com.oracle.truffle.espresso.classfile.ExceptionHandler;
import com.oracle.truffle.espresso.classfile.bytecode.BytecodeStream;
import com.oracle.truffle.espresso.classfile.descriptors.Name;
import com.oracle.truffle.espresso.classfile.descriptors.ParserSymbols.ParserNames;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;

public final class CodeAttribute extends Attribute {

public static final Symbol<Name> NAME = Name.Code;
public static final Symbol<Name> NAME = ParserNames.Code;

private final int majorVersion;

Expand Down Expand Up @@ -99,7 +100,7 @@ public ExceptionHandler[] getExceptionHandlers() {

public StackMapTableAttribute getStackMapFrame() {
for (Attribute attr : attributes) {
if (attr.getName() == Name.StackMapTable) {
if (attr.getName() == ParserNames.StackMapTable) {
return (StackMapTableAttribute) attr;
}
}
Expand Down Expand Up @@ -152,7 +153,7 @@ private static byte computeFlags(byte[] code) {

public LineNumberTableAttribute getLineNumberTableAttribute() {
for (Attribute attr : attributes) {
if (attr.getName() == Name.LineNumberTable) {
if (attr.getName() == ParserNames.LineNumberTable) {
return (LineNumberTableAttribute) attr;
}
}
Expand All @@ -161,7 +162,7 @@ public LineNumberTableAttribute getLineNumberTableAttribute() {

public LocalVariableTable getLocalvariableTable() {
for (Attribute attr : attributes) {
if (attr.getName() == Name.LocalVariableTable) {
if (attr.getName() == ParserNames.LocalVariableTable) {
return (LocalVariableTable) attr;
}
}
Expand All @@ -170,7 +171,7 @@ public LocalVariableTable getLocalvariableTable() {

public LocalVariableTable getLocalvariableTypeTable() {
for (Attribute attr : attributes) {
if (attr.getName() == Name.LocalVariableTypeTable) {
if (attr.getName() == ParserNames.LocalVariableTypeTable) {
return (LocalVariableTable) attr;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
*/
package com.oracle.truffle.espresso.classfile.attributes;

import com.oracle.truffle.espresso.classfile.descriptors.Name;
import com.oracle.truffle.espresso.classfile.descriptors.ParserSymbols.ParserNames;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;

/**
* The ConstantValue attribute is a fixed-length attribute in the attributes table of a field_info
Expand All @@ -41,7 +42,7 @@
* structure.
*/
public final class ConstantValueAttribute extends Attribute {
public static final Symbol<Name> NAME = Name.ConstantValue;
public static final Symbol<Name> NAME = ParserNames.ConstantValue;
private final int constantValueIndex;

public ConstantValueAttribute(int constantValueIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@

package com.oracle.truffle.espresso.classfile.attributes;

import com.oracle.truffle.espresso.classfile.descriptors.Name;
import com.oracle.truffle.espresso.classfile.descriptors.ParserSymbols.ParserNames;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;

public final class EnclosingMethodAttribute extends Attribute {

public static final Symbol<Name> NAME = Name.EnclosingMethod;
public static final Symbol<Name> NAME = ParserNames.EnclosingMethod;

private final int classIndex;
private final int methodIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
*/
package com.oracle.truffle.espresso.classfile.attributes;

import com.oracle.truffle.espresso.classfile.descriptors.Name;
import com.oracle.truffle.espresso.classfile.descriptors.ParserSymbols.ParserNames;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;

public final class ExceptionsAttribute extends Attribute {

public static final Symbol<Name> NAME = Name.Exceptions;
public static final Symbol<Name> NAME = ParserNames.Exceptions;

private final int[] checkedExceptionsCPI;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@

package com.oracle.truffle.espresso.classfile.attributes;

import static com.oracle.truffle.api.CompilerDirectives.CompilationFinal;

import com.oracle.truffle.espresso.classfile.descriptors.Name;
import com.oracle.truffle.espresso.classfile.descriptors.ParserSymbols.ParserNames;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;

import static com.oracle.truffle.api.CompilerDirectives.CompilationFinal;

public final class InnerClassesAttribute extends Attribute {

public static final Symbol<Name> NAME = Name.InnerClasses;
public static final Symbol<Name> NAME = ParserNames.InnerClasses;

public static class Entry {
public final int innerClassIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
import java.util.AbstractList;
import java.util.List;

import com.oracle.truffle.espresso.classfile.descriptors.Name;
import com.oracle.truffle.espresso.classfile.descriptors.ParserSymbols.ParserNames;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;

/**
* Maps bytecode indexes to source line numbers.
Expand All @@ -35,7 +36,7 @@
*/
public final class LineNumberTableAttribute extends Attribute implements LineNumberTableRef {

public static final Symbol<Name> NAME = Name.LineNumberTable;
public static final Symbol<Name> NAME = ParserNames.LineNumberTable;

// Use an empty char array rather than null to throw IooB exceptions, rather than NPE.
public static final LineNumberTableAttribute EMPTY = new LineNumberTableAttribute(NAME, new char[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import org.graalvm.collections.Equivalence;

import com.oracle.truffle.espresso.classfile.JavaKind;
import com.oracle.truffle.espresso.classfile.descriptors.Name;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Type;
import com.oracle.truffle.espresso.classfile.descriptors.Types;
import com.oracle.truffle.espresso.classfile.descriptors.Type;
import com.oracle.truffle.espresso.classfile.descriptors.TypeSymbols;

/**
* Describes the type and bytecode index range in which a local variable is live.
Expand Down Expand Up @@ -91,7 +91,7 @@ public Symbol<Type> getType() {
}

public JavaKind getJavaKind() {
return type == null ? JavaKind.Object : Types.getJavaKind(type);
return type == null ? JavaKind.Object : TypeSymbols.getJavaKind(type);
}

public int getSlot() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
import java.util.List;

import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.espresso.classfile.descriptors.Name;
import com.oracle.truffle.espresso.classfile.descriptors.ParserSymbols.ParserNames;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;

/**
* Describes the {@link Local}s for a Java method.
Expand All @@ -36,8 +37,8 @@
*/
public final class LocalVariableTable extends Attribute implements LocalVariableTableRef {

public static final LocalVariableTable EMPTY_LVT = new LocalVariableTable(Name.LocalVariableTable, Local.EMPTY_ARRAY);
public static final LocalVariableTable EMPTY_LVTT = new LocalVariableTable(Name.LocalVariableTypeTable, Local.EMPTY_ARRAY);
public static final LocalVariableTable EMPTY_LVT = new LocalVariableTable(ParserNames.LocalVariableTable, Local.EMPTY_ARRAY);
public static final LocalVariableTable EMPTY_LVTT = new LocalVariableTable(ParserNames.LocalVariableTypeTable, Local.EMPTY_ARRAY);

@CompilationFinal(dimensions = 1) //
private final Local[] locals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
*/
package com.oracle.truffle.espresso.classfile.attributes;

import com.oracle.truffle.espresso.classfile.descriptors.Name;
import com.oracle.truffle.espresso.classfile.descriptors.ParserSymbols.ParserNames;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;

public final class MethodParametersAttribute extends Attribute {

public static final Symbol<Name> NAME = Name.MethodParameters;
public static final Symbol<Name> NAME = ParserNames.MethodParameters;

public static final MethodParametersAttribute EMPTY = new MethodParametersAttribute(NAME, Entry.EMPTY_ARRAY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@

package com.oracle.truffle.espresso.classfile.attributes;

import com.oracle.truffle.espresso.classfile.descriptors.Name;
import com.oracle.truffle.espresso.classfile.descriptors.ParserSymbols.ParserNames;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;

public class NestHostAttribute extends Attribute {
public static final Symbol<Name> NAME = Name.NestHost;
public static final Symbol<Name> NAME = ParserNames.NestHost;

public final int hostClassIndex;

Expand Down
Loading

0 comments on commit ff759bc

Please sign in to comment.