Skip to content

Commit 5ad07fd

Browse files
committed
Avoid reading known annotation during startup for libtruffle attach.
1 parent a84ef58 commit 5ad07fd

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/InternalResourceCache.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ boolean requiresEagerUnpack() {
203203
* the Truffle runtime is created and accessor classes are initialized. For this reason, it
204204
* cannot use {@code EngineSupport} to call this method, nor can this method use any accessor.
205205
*/
206-
static Path installRuntimeResource(InternalResource resource) throws IOException {
207-
InternalResourceCache cache = createRuntimeResourceCache(resource);
206+
static Path installRuntimeResource(InternalResource resource, String id) throws IOException {
207+
InternalResourceCache cache = createRuntimeResourceCache(resource, id);
208208
synchronized (cache) {
209209
Path result = cache.path;
210210
if (result == null) {
@@ -215,14 +215,21 @@ static Path installRuntimeResource(InternalResource resource) throws IOException
215215
}
216216
}
217217

218-
private static InternalResourceCache createRuntimeResourceCache(InternalResource resource) {
219-
InternalResource.Id id = resource.getClass().getAnnotation(InternalResource.Id.class);
220-
assert id != null : resource.getClass() + " must be annotated by @InternalResource.Id";
221-
InternalResourceCache cache = new InternalResourceCache(PolyglotEngineImpl.ENGINE_ID, id.value(), () -> resource);
218+
private static InternalResourceCache createRuntimeResourceCache(InternalResource resource, String id) {
219+
assert verifyAnnotationConsistency(resource, id) : resource.getClass() + " must be annotated by @InternalResource.Id(\"" + id + "\"";
220+
InternalResourceCache cache = new InternalResourceCache(PolyglotEngineImpl.ENGINE_ID, id, () -> resource);
222221
InternalResourceRoots.initializeRuntimeResource(cache);
223222
return cache;
224223
}
225224

225+
private static boolean verifyAnnotationConsistency(InternalResource resource, String expectedId) {
226+
InternalResource.Id id = resource.getClass().getAnnotation(InternalResource.Id.class);
227+
if (id == null) {
228+
return false;
229+
}
230+
return id.value().equals(expectedId);
231+
}
232+
226233
private static InternalResource.Env createInternalResourceEnvReflectively(InternalResource resource) {
227234
try {
228235
Constructor<InternalResource.Env> newEnv = InternalResource.Env.class.getDeclaredConstructor(InternalResource.class, BooleanSupplier.class);

truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/JDKSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private static ModulesAccessor initializeModuleAccessor() {
119119
return null;
120120
}
121121
try {
122-
Path truffleAttachRoot = InternalResourceCache.installRuntimeResource(new LibTruffleAttachResource());
122+
Path truffleAttachRoot = InternalResourceCache.installRuntimeResource(new LibTruffleAttachResource(), LibTruffleAttachResource.ID);
123123
Path libAttach = truffleAttachRoot.resolve("bin").resolve(System.mapLibraryName("truffleattach"));
124124
attachLibPath = libAttach.toString();
125125
} catch (IOException ioe) {

0 commit comments

Comments
 (0)