Search in sources :

Example 1 with ClassInitializationInfo

use of com.oracle.svm.core.classinitialization.ClassInitializationInfo in project graal by oracle.

the class DynamicHubInitializer method buildRuntimeInitializationInfo.

private ClassInitializationInfo buildRuntimeInitializationInfo(AnalysisType type) {
    assert !type.isInitialized();
    try {
        /*
             * Check if there are any linking errors. This method throws an error even if linking
             * already failed in a previous attempt.
             */
        type.link();
    } catch (VerifyError e) {
        /* Synthesize a VerifyError to be thrown at run time. */
        AnalysisMethod throwVerifyError = metaAccess.lookupJavaMethod(ExceptionSynthesizer.throwExceptionMethod(VerifyError.class));
        registerAsCompiled(throwVerifyError);
        return new ClassInitializationInfo(new MethodPointer(throwVerifyError));
    } catch (Throwable t) {
        /*
             * All other linking errors will be reported as NoClassDefFoundError when initialization
             * is attempted at run time.
             */
        return ClassInitializationInfo.FAILED_INFO_SINGLETON;
    }
    /*
         * Now we now that there are no linking errors, we can register the class initialization
         * information.
         */
    assert type.isLinked();
    CFunctionPointer classInitializerFunction = null;
    AnalysisMethod classInitializer = type.getClassInitializer();
    if (classInitializer != null) {
        assert classInitializer.getCode() != null;
        registerAsCompiled(classInitializer);
        classInitializerFunction = new MethodPointer(classInitializer);
    }
    return new ClassInitializationInfo(classInitializerFunction);
}
Also used : AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) MethodPointer(com.oracle.svm.core.meta.MethodPointer) ClassInitializationInfo(com.oracle.svm.core.classinitialization.ClassInitializationInfo) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer)

Example 2 with ClassInitializationInfo

use of com.oracle.svm.core.classinitialization.ClassInitializationInfo in project graal by oracle.

the class ClassInitializationFeature method initializeSafeDelayedClasses.

/**
 * Initializes all classes that are considered delayed by the system. Classes specified by the
 * user will not be delayed.
 */
private Set<Class<?>> initializeSafeDelayedClasses(TypeInitializerGraph initGraph) {
    Set<Class<?>> provenSafe = new HashSet<>();
    classInitializationSupport.setConfigurationSealed(false);
    classInitializationSupport.classesWithKind(RUN_TIME).stream().filter(t -> metaAccess.optionalLookupJavaType(t).isPresent()).filter(t -> metaAccess.lookupJavaType(t).isReachable()).filter(t -> classInitializationSupport.canBeProvenSafe(t)).forEach(c -> {
        AnalysisType type = metaAccess.lookupJavaType(c);
        if (!initGraph.isUnsafe(type)) {
            classInitializationSupport.forceInitializeHosted(c, "proven safe to initialize", true);
            /*
                                 * See if initialization worked--it can fail due to implicit
                                 * exceptions.
                                 */
            if (!classInitializationSupport.shouldInitializeAtRuntime(c)) {
                provenSafe.add(c);
                ClassInitializationInfo initializationInfo = type.getClassInitializer() == null ? ClassInitializationInfo.NO_INITIALIZER_INFO_SINGLETON : ClassInitializationInfo.INITIALIZED_INFO_SINGLETON;
                DynamicHub hub = ((SVMHost) universe.hostVM()).dynamicHub(type);
                hub.setClassInitializationInfo(initializationInfo);
                universe.getHeapScanner().rescanField(hub, dynamicHubClassInitializationInfoField);
            }
        }
    });
    return provenSafe;
}
Also used : RUN_TIME(com.oracle.svm.hosted.classinitialization.InitKind.RUN_TIME) BeforeAnalysisAccessImpl(com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl) SubstrateOptionsParser(com.oracle.svm.core.option.SubstrateOptionsParser) Arrays(java.util.Arrays) GraalFeature(com.oracle.svm.core.graal.GraalFeature) SubstrateOptions(com.oracle.svm.core.SubstrateOptions) NodeLoweringProvider(com.oracle.svm.core.graal.snippets.NodeLoweringProvider) AutomaticFeature(com.oracle.svm.core.annotate.AutomaticFeature) BUILD_TIME(com.oracle.svm.hosted.classinitialization.InitKind.BUILD_TIME) RERUN(com.oracle.svm.hosted.classinitialization.InitKind.RERUN) AnalysisUniverse(com.oracle.graal.pointsto.meta.AnalysisUniverse) DynamicHub(com.oracle.svm.core.hub.DynamicHub) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Pair(org.graalvm.collections.Pair) SVMHost(com.oracle.svm.hosted.SVMHost) TimerCollection(com.oracle.graal.pointsto.util.TimerCollection) Map(java.util.Map) AnalysisMetaAccess(com.oracle.graal.pointsto.meta.AnalysisMetaAccess) UserError(com.oracle.svm.core.util.UserError) ClassInitializationInfo(com.oracle.svm.core.classinitialization.ClassInitializationInfo) EnsureClassInitializedSnippets(com.oracle.svm.core.classinitialization.EnsureClassInitializedSnippets) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) PrintWriter(java.io.PrintWriter) OptionValues(org.graalvm.compiler.options.OptionValues) SubstrateForeignCallsProvider(com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider) Timer(com.oracle.graal.pointsto.util.Timer) RuntimeConfiguration(com.oracle.svm.core.graal.meta.RuntimeConfiguration) ReportUtils(com.oracle.graal.pointsto.reports.ReportUtils) Set(java.util.Set) FeatureImpl(com.oracle.svm.hosted.FeatureImpl) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) List(java.util.List) SnippetRuntime(com.oracle.svm.core.snippets.SnippetRuntime) Node(org.graalvm.compiler.graph.Node) UnsupportedFeatureException(com.oracle.graal.pointsto.constraints.UnsupportedFeatureException) Comparator(java.util.Comparator) Providers(org.graalvm.compiler.phases.util.Providers) AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) SVMHost(com.oracle.svm.hosted.SVMHost) DynamicHub(com.oracle.svm.core.hub.DynamicHub) ClassInitializationInfo(com.oracle.svm.core.classinitialization.ClassInitializationInfo) HashSet(java.util.HashSet)

Example 3 with ClassInitializationInfo

use of com.oracle.svm.core.classinitialization.ClassInitializationInfo in project graal by oracle.

the class DynamicHubInitializer method buildClassInitializationInfo.

private void buildClassInitializationInfo(ImageHeapScanner heapScanner, AnalysisType type, DynamicHub hub) {
    ClassInitializationInfo info;
    if (hostVM.getClassInitializationSupport().shouldInitializeAtRuntime(type)) {
        info = buildRuntimeInitializationInfo(type);
    } else {
        assert type.isInitialized();
        info = type.getClassInitializer() == null ? ClassInitializationInfo.NO_INITIALIZER_INFO_SINGLETON : ClassInitializationInfo.INITIALIZED_INFO_SINGLETON;
    }
    hub.setClassInitializationInfo(info);
    heapScanner.rescanField(hub, dynamicHubClassInitializationInfoField);
}
Also used : ClassInitializationInfo(com.oracle.svm.core.classinitialization.ClassInitializationInfo)

Aggregations

ClassInitializationInfo (com.oracle.svm.core.classinitialization.ClassInitializationInfo)3 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)2 UnsupportedFeatureException (com.oracle.graal.pointsto.constraints.UnsupportedFeatureException)1 AnalysisMetaAccess (com.oracle.graal.pointsto.meta.AnalysisMetaAccess)1 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)1 AnalysisUniverse (com.oracle.graal.pointsto.meta.AnalysisUniverse)1 ReportUtils (com.oracle.graal.pointsto.reports.ReportUtils)1 Timer (com.oracle.graal.pointsto.util.Timer)1 TimerCollection (com.oracle.graal.pointsto.util.TimerCollection)1 SubstrateOptions (com.oracle.svm.core.SubstrateOptions)1 AutomaticFeature (com.oracle.svm.core.annotate.AutomaticFeature)1 EnsureClassInitializedSnippets (com.oracle.svm.core.classinitialization.EnsureClassInitializedSnippets)1 GraalFeature (com.oracle.svm.core.graal.GraalFeature)1 RuntimeConfiguration (com.oracle.svm.core.graal.meta.RuntimeConfiguration)1 SubstrateForeignCallsProvider (com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider)1 NodeLoweringProvider (com.oracle.svm.core.graal.snippets.NodeLoweringProvider)1 DynamicHub (com.oracle.svm.core.hub.DynamicHub)1 MethodPointer (com.oracle.svm.core.meta.MethodPointer)1 SubstrateOptionsParser (com.oracle.svm.core.option.SubstrateOptionsParser)1 SnippetRuntime (com.oracle.svm.core.snippets.SnippetRuntime)1