Skip to content

Commit a8009c1

Browse files
committed
[GR-59863] Move link resolver to shared module.
PullRequest: graal/19431
2 parents c799451 + 75ead13 commit a8009c1

29 files changed

+994
-282
lines changed

espresso/mx.espresso/suite.py

+14
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@
129129
"checkstyle": "com.oracle.truffle.espresso",
130130
},
131131

132+
# Shared link resolver
133+
"com.oracle.truffle.espresso.shared": {
134+
"subDir": "src",
135+
"sourceDirs": ["src"],
136+
"dependencies": [
137+
"com.oracle.truffle.espresso.classfile",
138+
],
139+
"requires": [
140+
],
141+
"javaCompliance" : "17+",
142+
"checkstyle": "com.oracle.truffle.espresso",
143+
},
144+
132145
"com.oracle.truffle.espresso": {
133146
"subDir": "src",
134147
"sourceDirs": ["src"],
@@ -137,6 +150,7 @@
137150
"truffle:TRUFFLE_NFI",
138151
"com.oracle.truffle.espresso.jdwp",
139152
"com.oracle.truffle.espresso.shadowed.asm",
153+
"com.oracle.truffle.espresso.shared",
140154
],
141155
"requires": [
142156
"java.logging",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.shared.resolver.LinkResolver;
27+
28+
/**
29+
* The errors that can happen during {@link LinkResolver resolution}.
30+
*/
31+
public enum ErrorType {
32+
IllegalAccessError,
33+
NoSuchFieldError,
34+
NoSuchMethodError,
35+
IncompatibleClassChangeError;
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
* Represents a {@link java.lang.reflect.Field}, and provides access to various runtime metadata.
28+
*
29+
* @param <C> The class providing access to the VM-side java {@link Class}.
30+
* @param <M> The class providing access to the VM-side java {@link java.lang.reflect.Method}.
31+
* @param <F> The class providing access to the VM-side java {@link java.lang.reflect.Field}.
32+
*/
33+
public interface FieldAccess<C extends TypeAccess<C, M, F>, M extends MethodAccess<C, M, F>, F extends FieldAccess<C, M, F>> extends MemberAccess<C, M, F> {
34+
/**
35+
* Whether resolution for this field access site should enforce final field only being written
36+
* in constructors or class initializer, whichever applies (see JVMS-6.5.putfield /
37+
* JVMS-6.5.putstatic).
38+
* <p>
39+
* In particular, this check was not enforced in java bytecodes in versions prior to Java 9.
40+
*/
41+
boolean shouldEnforceInitializerCheck();
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
* Represents a {@link java.lang.reflect.Member}, and provides access to various runtime
28+
* capabilities such as {@link #accessChecks(TypeAccess, TypeAccess) access control} and
29+
* {@link #loadingConstraints(TypeAccess) enforcing loading constraints}.
30+
*
31+
* @param <C> The class providing access to the VM-side java {@link Class}.
32+
* @param <M> The class providing access to the VM-side java {@link java.lang.reflect.Method}.
33+
* @param <F> The class providing access to the VM-side java {@link java.lang.reflect.Field}.
34+
*/
35+
public interface MemberAccess<C extends TypeAccess<C, M, F>, M extends MethodAccess<C, M, F>, F extends FieldAccess<C, M, F>> extends ModifiersProvider, Named {
36+
/**
37+
* @return The class in which the declaration if this member is present.
38+
*/
39+
C getDeclaringClass();
40+
41+
/**
42+
* Performs access checks for this member.
43+
*
44+
* @param accessingClass The class from which resolution is being performed.
45+
* @param holderClass The class referenced in the symbolic representation of the method, as seen
46+
* in the constant pool. May be different from {@link #getDeclaringClass()}.
47+
*/
48+
void accessChecks(C accessingClass, C holderClass);
49+
50+
/**
51+
* Performs loading constraints checks for this member.
52+
*
53+
* @param accessingClass The class from which resolution is being performed.
54+
*/
55+
void loadingConstraints(C accessingClass);
56+
}
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+
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
27+
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Signature;
28+
29+
/**
30+
* Represents a {@link java.lang.reflect.Method}, and provides access to various runtime metadata.
31+
*
32+
* @param <C> The class providing access to the VM-side java {@link Class}.
33+
* @param <M> The class providing access to the VM-side java {@link java.lang.reflect.Method}.
34+
* @param <F> The class providing access to the VM-side java {@link java.lang.reflect.Field}.
35+
*/
36+
public interface MethodAccess<C extends TypeAccess<C, M, F>, M extends MethodAccess<C, M, F>, F extends FieldAccess<C, M, F>> extends MemberAccess<C, M, F> {
37+
/**
38+
* @return The symbolic signature of this method.
39+
*/
40+
Symbol<Signature> getSymbolicSignature();
41+
42+
/**
43+
* @return {@code true} if this method represents an instance initialization method (its
44+
* {@link #getSymbolicName() name} is {@code "<init>"}), {@code false} otherwise.
45+
*/
46+
boolean isConstructor();
47+
48+
/**
49+
* @return {@code true} if this method represents a class initialization method (its
50+
* {@link #getSymbolicName() name} is {@code "<clinit>"}, and it is {@link #isStatic()
51+
* static}), {@code false} otherwise.
52+
*/
53+
boolean isClassInitializer();
54+
55+
/**
56+
* Whether loading constraints checks should be skipped for this method. An example of method
57+
* which should skip loading constraints are the polymorphic signature methods.
58+
*/
59+
boolean shouldSkipLoadingConstraints();
60+
}

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@
2020
* or visit www.oracle.com if you need additional information or have any
2121
* questions.
2222
*/
23-
package com.oracle.truffle.espresso.meta;
23+
package com.oracle.truffle.espresso.shared.meta;
2424

2525
import static java.lang.reflect.Modifier.PRIVATE;
2626
import static java.lang.reflect.Modifier.PROTECTED;
2727
import static java.lang.reflect.Modifier.PUBLIC;
2828

2929
import java.lang.reflect.Modifier;
3030

31-
import com.oracle.truffle.api.dsl.Idempotent;
32-
3331
/**
3432
* A Java element (i.e., a class, interface, field or method) that is described by a set of Java
3533
* language {@linkplain #getModifiers() modifiers}.
@@ -140,7 +138,6 @@ default boolean isNative() {
140138
/**
141139
* @see Modifier#isAbstract(int)
142140
*/
143-
@Idempotent
144141
default boolean isAbstract() {
145142
return Modifier.isAbstract(getModifiers());
146143
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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.Symbol;
27+
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;
28+
29+
/**
30+
* A {@link Named} object must provide a {@link #getSymbolicName() symbolic name}.
31+
*/
32+
public interface Named {
33+
/**
34+
* @return The symbolic name of this object.
35+
*/
36+
Symbol<Name> getSymbolicName();
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.JavaVersion;
27+
28+
/**
29+
* Provides access to some VM-specific capabilities, such as throwing exceptions, or obtaining the
30+
* implementor's supported {@link JavaVersion}.
31+
*
32+
* @param <C> The class providing access to the VM-side java {@link Class}.
33+
* @param <M> The class providing access to the VM-side java {@link java.lang.reflect.Method}.
34+
* @param <F> The class providing access to the VM-side java {@link java.lang.reflect.Field}.
35+
*/
36+
public interface RuntimeAccess<C extends TypeAccess<C, M, F>, M extends MethodAccess<C, M, F>, F extends FieldAccess<C, M, F>> {
37+
/**
38+
* This runtime's supported {@link JavaVersion}.
39+
*/
40+
JavaVersion getJavaVersion();
41+
42+
/**
43+
* Signals to the runtime that a Java error should be thrown. The type of the error to be thrown
44+
* is given by the passed {@link ErrorType}.
45+
* <p>
46+
* The caller provides an error message that can be constructed using
47+
* {@code String.format(Locale.ENGLISH, messageFormat, args)}.
48+
*/
49+
RuntimeException throwError(ErrorType error, String messageFormat, Object... args);
50+
51+
/**
52+
* Signals that an unexpected state has been reached and that the current operation must be
53+
* aborted.
54+
* <p>
55+
* The caller provides an error message that can be constructed using
56+
* {@code String.format(Locale.ENGLISH, messageFormat, args)}.
57+
*/
58+
RuntimeException fatal(String messageFormat, Object... args);
59+
}

0 commit comments

Comments
 (0)