Skip to content

Commit

Permalink
Drop JDKSupport accessor.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Feb 15, 2022
1 parent b7ba2fa commit 2f86964
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 182 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,7 +30,6 @@ final class GraalRuntimeAccessor extends Accessor {

private static final GraalRuntimeAccessor ACCESSOR = new GraalRuntimeAccessor();

static final JDKSupport JDK = ACCESSOR.jdkSupport();
static final NodeSupport NODES = ACCESSOR.nodeSupport();
static final SourceSupport SOURCE = ACCESSOR.sourceSupport();
static final InstrumentSupport INSTRUMENT = ACCESSOR.instrumentSupport();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -685,7 +685,7 @@ public <T> T getCapability(Class<T> capability) {
return capability.cast(tvmci);
} else if (capability == LayoutFactory.class) {
LayoutFactory layoutFactory = loadObjectLayoutFactory();
GraalRuntimeAccessor.JDK.exportTo(layoutFactory.getClass());
ModuleUtil.exportTo(layoutFactory.getClass());
return capability.cast(layoutFactory);
} else if (capability == TVMCI.Test.class) {
return capability.cast(getTestTvmci());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -22,19 +22,27 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package org.graalvm.compiler.truffle.runtime.debug;
package org.graalvm.compiler.truffle.runtime;

import com.oracle.truffle.api.impl.Accessor;
import java.util.Set;

final class CompilerDebugAccessor extends Accessor {
public final class ModuleUtil {

private static final CompilerDebugAccessor ACCESSOR = new CompilerDebugAccessor();

private CompilerDebugAccessor() {
public static void exportTo(Class<?> client) {
Module truffleModule = ModuleUtil.class.getModule();
exportFromTo(truffleModule, client.getModule());
}

static JDKSupport jdkServicesAccessor() {
return ACCESSOR.jdkSupport();
private static void exportFromTo(Module truffleModule, Module clientModule) {
if (truffleModule != clientModule) {
Set<String> packages = truffleModule.getPackages();
for (String pkg : packages) {
boolean exported = truffleModule.isExported(pkg, clientModule);
if (!exported) {
truffleModule.addExports(pkg, clientModule);
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.graalvm.compiler.truffle.jfr.InvalidationEvent;
import org.graalvm.compiler.truffle.runtime.AbstractGraalTruffleRuntimeListener;
import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime;
import org.graalvm.compiler.truffle.runtime.ModuleUtil;
import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget;
import org.graalvm.compiler.truffle.runtime.TruffleInlining;
import org.graalvm.compiler.truffle.runtime.serviceprovider.TruffleRuntimeServices;
Expand Down Expand Up @@ -68,7 +69,7 @@ public final class JFRListener extends AbstractGraalTruffleRuntimeListener {
if (provider == null) {
factory = null;
} else {
CompilerDebugAccessor.jdkServicesAccessor().exportTo(provider.getClass());
ModuleUtil.exportTo(provider.getClass());
factory = provider == null ? null : provider.getEventFactory();
}
}
Expand Down
2 changes: 1 addition & 1 deletion truffle/mx.truffle/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@
],
"exports" : [
# Qualified exports
"com.oracle.truffle.api* to com.oracle.truffle.regex, jdk.internal.vm.compiler, com.oracle.graal.graal_enterprise, org.graalvm.nativeimage.builder",
"com.oracle.truffle.api* to com.oracle.truffle.regex, jdk.internal.vm.compiler, jdk.internal.vm.compiler.truffle.jfr, com.oracle.graal.graal_enterprise, org.graalvm.nativeimage.builder",
"com.oracle.truffle.api.impl to org.graalvm.locator",
"com.oracle.truffle.api to org.graalvm.locator, com.oracle.truffle.truffle_nfi, org.graalvm.nativeimage.builder",
"com.oracle.truffle.object to jdk.internal.vm.compiler, com.oracle.graal.graal_enterprise",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ final class InstrumentAccessor extends Accessor {

static final NodeSupport NODES = ACCESSOR.nodeSupport();
static final SourceSupport SOURCE = ACCESSOR.sourceSupport();
static final JDKSupport JDK = ACCESSOR.jdkSupport();
static final LanguageSupport LANGUAGE = ACCESSOR.languageSupport();
static final EngineSupport ENGINE = ACCESSOR.engineSupport();
static final InteropSupport INTEROP = ACCESSOR.interopSupport();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -49,10 +49,6 @@ final class LibraryAccessor extends Accessor {
private LibraryAccessor() {
}

static JDKSupport jdkServicesAccessor() {
return ACCESSOR.jdkSupport();
}

static NodeSupport nodeAccessor() {
return ACCESSOR.nodeSupport();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -78,7 +78,6 @@ final class LanguageAccessor extends Accessor {
static final NodeSupport NODES = ACCESSOR.nodeSupport();
static final SourceSupport SOURCE = ACCESSOR.sourceSupport();
static final InstrumentSupport INSTRUMENT = ACCESSOR.instrumentSupport();
static final JDKSupport JDK = ACCESSOR.jdkSupport();
static final EngineSupport ENGINE = ACCESSOR.engineSupport();
static final InteropSupport INTEROP = ACCESSOR.interopSupport();
static final RuntimeSupport RUNTIME = ACCESSOR.runtimeSupport();
Expand Down Expand Up @@ -110,10 +109,6 @@ static IOSupport ioAccess() {
return ACCESSOR.ioSupport();
}

static JDKSupport jdkServicesAccessor() {
return ACCESSOR.jdkSupport();
}

static final class LanguageImpl extends LanguageSupport {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -42,11 +42,13 @@

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.Set;

import com.oracle.truffle.api.impl.Accessor;
import com.oracle.truffle.api.impl.DefaultTruffleRuntime;

/**
Expand Down Expand Up @@ -118,30 +120,32 @@ public TruffleRuntime run() {
}
}

List<Iterable<TruffleRuntimeAccess>> loaders = TruffleAccessor.jdkServicesAccessor().getTruffleRuntimeLoaders(TruffleRuntimeAccess.class);
List<Iterable<TruffleRuntimeAccess>> loaders = Collections.singletonList(ServiceLoader.load(TruffleRuntimeAccess.class));
TruffleRuntimeAccess access = selectTruffleRuntimeAccess(loaders);

if (access != null) {
TruffleAccessor.jdkServicesAccessor().exportTo(access.getClass());
exportTo(access.getClass());
return access.getRuntime();
}
return new DefaultTruffleRuntime();
}
});
}
}

/*
* Truffle accessor for use during truffle initialization to avoid cyclic dependencies.
*/
final class TruffleAccessor extends Accessor {

static final TruffleAccessor ACCESSOR = new TruffleAccessor();

private TruffleAccessor() {
private static void exportTo(Class<?> client) {
Module truffleModule = Truffle.class.getModule();
exportFromTo(truffleModule, client.getModule());
}

static JDKSupport jdkServicesAccessor() {
return ACCESSOR.jdkSupport();
private static void exportFromTo(Module truffleModule, Module clientModule) {
if (truffleModule != clientModule) {
Set<String> packages = truffleModule.getPackages();
for (String pkg : packages) {
boolean exported = truffleModule.isExported(pkg, clientModule);
if (!exported) {
truffleModule.addExports(pkg, clientModule);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1125,44 +1125,6 @@ public AbstractFastThreadLocal getContextThreadLocal() {
}
}

public static final class JDKSupport {

private JDKSupport() {
}

public void exportTo(ClassLoader loader, String moduleName) {
TruffleJDKServices.exportTo(loader, moduleName);
}

public void exportTo(Class<?> client) {
TruffleJDKServices.exportTo(client);
}

public <Service> List<Iterable<Service>> getTruffleRuntimeLoaders(Class<Service> serviceClass) {
return TruffleJDKServices.getTruffleRuntimeLoaders(serviceClass);
}

public <S> void addUses(Class<S> service) {
TruffleJDKServices.addUses(service);
}

public void addReads(Class<?> client) {
TruffleJDKServices.addReads(client);
}

public Object getUnnamedModule(ClassLoader classLoader) {
return TruffleJDKServices.getUnnamedModule(classLoader);
}

public boolean verifyModuleVisibility(Object lookupModule, Class<?> memberClass) {
return TruffleJDKServices.verifyModuleVisibility(lookupModule, memberClass);
}

public boolean isNonTruffleClass(Class<?> clazz) {
return TruffleJDKServices.isNonTruffleClass(clazz);
}
}

// A separate class to break the cycle such that Accessor can fully initialize
// before ...Accessor classes static initializers run, which call methods from Accessor.
private static class Constants {
Expand Down Expand Up @@ -1208,8 +1170,6 @@ private static <T> T loadSupport(String className) {
}
}

private static final Accessor.JDKSupport JDKSERVICES = new JDKSupport();

protected Accessor() {
String thisClassName = this.getClass().getName();
if ("com.oracle.truffle.api.LanguageAccessor".equals(thisClassName) ||
Expand All @@ -1232,7 +1192,6 @@ protected Accessor() {
"com.oracle.truffle.api.impl.TVMCIAccessor".equals(thisClassName) ||
"com.oracle.truffle.api.impl.DefaultRuntimeAccessor".equals(thisClassName) ||
"org.graalvm.compiler.truffle.runtime.GraalRuntimeAccessor".equals(thisClassName) ||
"org.graalvm.compiler.truffle.runtime.debug.CompilerDebugAccessor".equals(thisClassName) ||
"com.oracle.truffle.api.dsl.DSLAccessor".equals(thisClassName) ||
"com.oracle.truffle.api.impl.ImplAccessor".equals(thisClassName) ||
"com.oracle.truffle.api.memory.MemoryFenceAccessor".equals(thisClassName) ||
Expand Down Expand Up @@ -1291,10 +1250,6 @@ public final IOSupport ioSupport() {
return Constants.IO;
}

public final JDKSupport jdkSupport() {
return JDKSERVICES;
}

/**
* Don't call me. I am here only to let NetBeans debug any Truffle project.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -64,7 +64,6 @@ final class DefaultRuntimeAccessor extends Accessor {
static final SourceSupport SOURCE = ACCESSOR.sourceSupport();
static final InstrumentSupport INSTRUMENT = ACCESSOR.instrumentSupport();
static final LanguageSupport LANGUAGE = ACCESSOR.languageSupport();
static final JDKSupport JDK = ACCESSOR.jdkSupport();
static final EngineSupport ENGINE = ACCESSOR.engineSupport();
static final InteropSupport INTEROP = ACCESSOR.interopSupport();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public final class DefaultTruffleRuntime implements TruffleRuntime {
private final ThreadLocal<DefaultFrameInstance> stackTraces = new ThreadLocal<>();
private final DefaultTVMCI tvmci = new DefaultTVMCI();

private final TVMCI.Test<Closeable, CallTarget> testTvmci = new TVMCI.Test<Closeable, CallTarget>() {
private final TVMCI.Test<Closeable, CallTarget> testTvmci = new TVMCI.Test<>() {

@Override
protected Closeable createTestContext(String testName) {
Expand Down Expand Up @@ -269,7 +269,10 @@ private static final class Loader {

@SuppressWarnings("unchecked")
static <S> Iterable<S> load(Class<S> service) {
TruffleJDKServices.addUses(service);
Module truffleModule = DefaultTruffleRuntime.class.getModule();
if (!truffleModule.canUse(service)) {
truffleModule.addUses(service);
}
if (LOAD_METHOD != null) {
try {
return (Iterable<S>) LOAD_METHOD.invoke(null, service);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -61,7 +61,6 @@ final class HostAccessor extends Accessor {
static final SourceSupport SOURCE = ACCESSOR.sourceSupport();
static final InstrumentSupport INSTRUMENT = ACCESSOR.instrumentSupport();
static final LanguageSupport LANGUAGE = ACCESSOR.languageSupport();
static final JDKSupport JDKSERVICES = ACCESSOR.jdkSupport();
static final InteropSupport INTEROP = ACCESSOR.interopSupport();
static final ExceptionSupport EXCEPTION = ACCESSOR.exceptionSupport();
static final RuntimeSupport RUNTIME = ACCESSOR.runtimeSupport();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -101,7 +101,7 @@ private HostClassCache(AbstractHostAccess polyglotAccess, APIAccess apiAccess, H
this.iteratorAccess = apiAccess.isIteratorAccessible(hostAccess);
this.mapAccess = apiAccess.isMapAccessible(hostAccess);
this.targetMappings = groupMappings(apiAccess, conf);
this.unnamedModule = HostAccessor.JDKSERVICES.getUnnamedModule(classLoader);
this.unnamedModule = HostContext.getUnnamedModule(classLoader);
}

Object getUnnamedModule() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public HostMethodDesc apply(HostMethodDesc m1, HostMethodDesc m2) {
}

private static boolean isClassAccessible(Class<?> declaringClass, HostClassCache hostAccess) {
return Modifier.isPublic(declaringClass.getModifiers()) && HostAccessor.JDKSERVICES.verifyModuleVisibility(hostAccess.getUnnamedModule(), declaringClass);
return Modifier.isPublic(declaringClass.getModifiers()) && HostContext.verifyModuleVisibility(hostAccess.getUnnamedModule(), declaringClass);
}

private static HostMethodDesc collectPublicConstructors(HostClassCache hostAccess, Class<?> type) {
Expand Down
Loading

0 comments on commit 2f86964

Please sign in to comment.