Skip to content

Commit e28f8e4

Browse files
rakachangilles-duboscq
authored andcommitted
[GR-60112] Pull the verifier from espresso to the shared project.
PullRequest: graal/19692
2 parents ad01302 + 7abbd68 commit e28f8e4

26 files changed

+1534
-936
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package com.oracle.truffle.espresso.shared.meta;
25+
26+
import java.io.Serial;
27+
28+
/**
29+
* Indicates that an exception was thrown during class loading.
30+
*/
31+
public class ClassLoadingException extends Exception {
32+
@Serial private static final long serialVersionUID = -6396583822642157602L;
33+
34+
private final boolean isClassNotFoundException;
35+
private final RuntimeException exception;
36+
37+
public ClassLoadingException(RuntimeException e, boolean isClassNotFoundException) {
38+
this.isClassNotFoundException = isClassNotFoundException;
39+
this.exception = e;
40+
}
41+
42+
/**
43+
* Whether {@link #getException()} represents this runtime's equivalent of
44+
* {@link ClassNotFoundException}.
45+
*/
46+
public boolean isClassNotFoundException() {
47+
return isClassNotFoundException;
48+
}
49+
50+
/**
51+
* The original exception thrown.
52+
*/
53+
public RuntimeException getException() {
54+
return exception;
55+
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package com.oracle.truffle.espresso.shared.meta;
25+
26+
/**
27+
* Provides access to certain known classes.
28+
*/
29+
public interface KnownTypes<C extends TypeAccess<C, M, F>, M extends MethodAccess<C, M, F>, F extends FieldAccess<C, M, F>> {
30+
// Checkstyle: stop method name check
31+
/**
32+
* @return The runtime's representation of {@link java.lang.Object}
33+
*/
34+
C java_lang_Object();
35+
36+
/**
37+
* @return The runtime's representation of {@link java.lang.Throwable}
38+
*/
39+
C java_lang_Throwable();
40+
41+
/**
42+
* @return The runtime's representation of {@link java.lang.Class}
43+
*/
44+
C java_lang_Class();
45+
46+
/**
47+
* @return The runtime's representation of {@link java.lang.String}
48+
*/
49+
C java_lang_String();
50+
51+
/**
52+
* @return The runtime's representation of {@link java.lang.invoke.MethodType}
53+
*/
54+
C java_lang_invoke_MethodType();
55+
56+
/**
57+
* @return The runtime's representation of {@link java.lang.invoke.MethodHandle}
58+
*/
59+
C java_lang_invoke_MethodHandle();
60+
}

espresso/src/com.oracle.truffle.espresso.shared/src/com/oracle/truffle/espresso/shared/meta/MethodAccess.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323

2424
package com.oracle.truffle.espresso.shared.meta;
2525

26+
import com.oracle.truffle.espresso.classfile.ExceptionHandler;
27+
import com.oracle.truffle.espresso.classfile.attributes.CodeAttribute;
2628
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
2729
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Signature;
30+
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Type;
2831

2932
/**
3033
* Represents a {@link java.lang.reflect.Method}, and provides access to various runtime metadata.
@@ -39,6 +42,20 @@ public interface MethodAccess<C extends TypeAccess<C, M, F>, M extends MethodAcc
3942
*/
4043
Symbol<Signature> getSymbolicSignature();
4144

45+
/**
46+
* Obtains the parsed signature for this method.
47+
* <p>
48+
* A default implementation is provided, but it is encouraged to override this method if the
49+
* representation of methods allows for a simpler computation (for example, if the method caches
50+
* its parsed signature).
51+
*
52+
* @param symbolPool The symbol pool from which this method draws its symbols.
53+
* @return The parsed signature of this method.
54+
*/
55+
default Symbol<Type>[] getParsedSymbolicSignature(SymbolPool symbolPool) {
56+
return symbolPool.getSignatures().parsed(getSymbolicSignature());
57+
}
58+
4259
/**
4360
* @return {@code true} if this method represents an instance initialization method (its
4461
* {@link #getSymbolicName() name} is {@code "<init>"}), {@code false} otherwise.
@@ -57,4 +74,14 @@ public interface MethodAccess<C extends TypeAccess<C, M, F>, M extends MethodAcc
5774
* which should skip loading constraints are the polymorphic signature methods.
5875
*/
5976
boolean shouldSkipLoadingConstraints();
77+
78+
/**
79+
* The {@link CodeAttribute} associated with this method.
80+
*/
81+
CodeAttribute getCodeAttribute();
82+
83+
/**
84+
* The {@link ExceptionHandler exception handlers} associated with this method.
85+
*/
86+
ExceptionHandler[] getExceptionHandlers();
6087
}

espresso/src/com.oracle.truffle.espresso.shared/src/com/oracle/truffle/espresso/shared/meta/RuntimeAccess.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
package com.oracle.truffle.espresso.shared.meta;
2525

2626
import com.oracle.truffle.espresso.classfile.JavaVersion;
27+
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
28+
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Type;
2729

2830
/**
2931
* Provides access to some VM-specific capabilities, such as throwing exceptions, or obtaining the
@@ -48,6 +50,31 @@ public interface RuntimeAccess<C extends TypeAccess<C, M, F>, M extends MethodAc
4850
*/
4951
RuntimeException throwError(ErrorType error, String messageFormat, Object... args);
5052

53+
/**
54+
* Performs class loading on behalf of the given accessing class.
55+
* <p>
56+
* Its defining class loader is the one to be used for loading.
57+
* <p>
58+
* Any exception that arises during class loading must be wrapped into a
59+
* {@link ClassLoadingException}, correctly specifying if the original exception is this
60+
* runtime's equivalent of {@link ClassNotFoundException}.
61+
*
62+
* @return The loaded class.
63+
*
64+
* @throws ClassLoadingException If any exception is thrown during loading
65+
*/
66+
C lookupOrLoadType(Symbol<Type> type, C accessingClass) throws ClassLoadingException;
67+
68+
/**
69+
* Obtains and returns an object containing certain VM-known classes.
70+
*/
71+
KnownTypes<C, M, F> getKnownTypes();
72+
73+
/**
74+
* Obtains and returns an object containing the various symbol pools for this runtime.
75+
*/
76+
SymbolPool getSymbolPool();
77+
5178
/**
5279
* Signals that an unexpected state has been reached and that the current operation must be
5380
* aborted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package com.oracle.truffle.espresso.shared.meta;
25+
26+
import com.oracle.truffle.espresso.classfile.descriptors.Names;
27+
import com.oracle.truffle.espresso.classfile.descriptors.Signatures;
28+
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Signature;
29+
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Type;
30+
import com.oracle.truffle.espresso.classfile.descriptors.Types;
31+
32+
/**
33+
* Provides access to various Symbol pools.
34+
*/
35+
public interface SymbolPool {
36+
/**
37+
* @return The {@link Names} pool.
38+
*/
39+
Names getNames();
40+
41+
/**
42+
* @return The {@link Type} pool.
43+
*/
44+
Types getTypes();
45+
46+
/**
47+
* @return The {@link Signature} pool.
48+
*/
49+
Signatures getSignatures();
50+
}

espresso/src/com.oracle.truffle.espresso.shared/src/com/oracle/truffle/espresso/shared/meta/TypeAccess.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
package com.oracle.truffle.espresso.shared.meta;
2525

26+
import com.oracle.truffle.espresso.classfile.ConstantPool;
2627
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
2728
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;
2829
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Signature;
@@ -42,11 +43,44 @@ public interface TypeAccess<C extends TypeAccess<C, M, F>, M extends MethodAcces
4243
*/
4344
String getJavaName();
4445

46+
/**
47+
* Returns the symbolic reference of this class.
48+
*/
49+
Symbol<Type> getSymbolicType();
50+
51+
/**
52+
* Returns whether this class and the other class share the same defining class loader.
53+
*/
54+
boolean hasSameDefiningClassLoader(C other);
55+
56+
/**
57+
* Finds the least common ancestor between this class and the other class.
58+
*/
59+
C findLeastCommonAncestor(C other);
60+
4561
/**
4662
* Returns the superclass of this class, or {@code null} if this class is {@link Object}.
4763
*/
4864
C getSuperClass();
4965

66+
/**
67+
* Returns the host class of this VM-anonymous class, or {@code null} if this class is not a
68+
* VM-anonymous class.
69+
*
70+
* @apiNote A VM-anonymous class is a class defined through
71+
* {@code Unsafe.defineAnonymousClass()} and is unrelated to the
72+
* {@link Class#isAnonymousClass() Java concept of anonymous classes}.
73+
* @implNote The concept of VM-anonymous classes was removed from Java 17 onwards, and this
74+
* method should therefore always return {@code null} for implementations of Java 17
75+
* or later.
76+
*/
77+
C getHostType();
78+
79+
/**
80+
* Returns the name of the runtime package in which this class is defined.
81+
*/
82+
Symbol<Name> getSymbolicRuntimePackage();
83+
5084
/**
5185
* Performs field lookup on this class for the given field name and field type, according to
5286
* JVMS-5.4.3.2.
@@ -145,4 +179,25 @@ public interface TypeAccess<C extends TypeAccess<C, M, F>, M extends MethodAcces
145179
default boolean isJavaLangObject() {
146180
return getSuperClass() == null;
147181
}
182+
183+
/**
184+
* Whether this class extends the "magic accessor".
185+
*/
186+
boolean isMagicAccessor();
187+
188+
/**
189+
* The {@link ConstantPool} associated with this class.
190+
*/
191+
ConstantPool getConstantPool();
192+
193+
/**
194+
* Resolves a class in the runtime constant pool of this type, then returns it. Further calls to
195+
* this method with the same cpi should not trigger class loading.
196+
*
197+
* @param cpi The constant pool index in which to find the class constant
198+
* @throws IllegalArgumentException If there is no
199+
* {@link com.oracle.truffle.espresso.classfile.constantpool.ClassConstant} in the
200+
* constant pool at index {@code cpi}.
201+
*/
202+
C resolveClassConstantInPool(int cpi);
148203
}

0 commit comments

Comments
 (0)