Skip to content

Commit 47f3305

Browse files
committed
Add base layer root methods.
1 parent 3622f50 commit 47f3305

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisMethod.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,14 @@ public boolean isDelayed() {
353353
return compilationBehavior == CompilationBehavior.FULLY_DELAYED_TO_APPLICATION_LAYER && buildingSharedLayer;
354354
}
355355

356-
public void setPinnedToInitialLayer() {
356+
public void setPinnedToInitialLayer(Object reason) {
357357
BigBang bigbang = getUniverse().getBigbang();
358358
AnalysisError.guarantee(bigbang.getHostVM().buildingInitialLayer(), "Methods can only be pinned to the initial layer: %s", this);
359359
boolean nonAbstractInstanceClass = !declaringClass.isArray() && declaringClass.isInstanceClass() && !declaringClass.isAbstract();
360-
AnalysisError.guarantee(nonAbstractInstanceClass, "Only methods from non abstract instance class can be delayed: %s", this);
361-
bigbang.forcedAddRootMethod(this, true, "Method is pinned to the initial layer");
360+
AnalysisError.guarantee(nonAbstractInstanceClass, "Only methods from non abstract instance class can be pinned: %s", this);
361+
bigbang.forcedAddRootMethod(this, true, "pinned to initial layer: " + reason);
362362
if (!isStatic()) {
363-
declaringClass.registerAsInstantiated(this + " is pinned to the initial layer");
363+
declaringClass.registerAsInstantiated("declared method " + this.format("%H.%n(%p)") + " is pinned to initial layer: " + reason);
364364
}
365365
setNewCompilationBehavior(CompilationBehavior.PINNED_TO_INITIAL_LAYER);
366366
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2025, 2025, 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. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.hosted.imagelayer;
26+
27+
import com.oracle.graal.pointsto.meta.AnalysisMetaAccess;
28+
import org.graalvm.nativeimage.hosted.Feature;
29+
30+
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
31+
import com.oracle.svm.core.feature.InternalFeature;
32+
import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport;
33+
import com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl;
34+
import com.oracle.svm.util.ReflectionUtil;
35+
36+
import jdk.internal.misc.Unsafe;
37+
38+
@AutomaticallyRegisteredFeature
39+
public class InitialLayerFeature implements InternalFeature {
40+
@Override
41+
public boolean isInConfiguration(Feature.IsInConfigurationAccess access) {
42+
return ImageLayerBuildingSupport.buildingInitialLayer();
43+
}
44+
45+
@Override
46+
public void beforeAnalysis(BeforeAnalysisAccess a) {
47+
BeforeAnalysisAccessImpl access = (BeforeAnalysisAccessImpl) a;
48+
49+
/*
50+
* Make sure that critical VM components are included in the base layer by registering
51+
* runtime APIs as entry points. Although the types below are part of java.base, so they
52+
* would anyway be included in every base layer created with module=java.base, this ensures
53+
* that the base layer is usable regardless of the class inclusion policy.
54+
*/
55+
String pinReason = "base layer entry point included unconditionally";
56+
AnalysisMetaAccess metaAccess = access.getMetaAccess();
57+
metaAccess.lookupJavaMethod(ReflectionUtil.lookupMethod(Unsafe.class, "getUnsafe")).setPinnedToInitialLayer(pinReason);
58+
metaAccess.lookupJavaMethod(ReflectionUtil.lookupMethod(Unsafe.class, "allocateInstance", Class.class)).setPinnedToInitialLayer(pinReason);
59+
metaAccess.lookupJavaMethod(ReflectionUtil.lookupMethod(Runtime.class, "getRuntime")).setPinnedToInitialLayer(pinReason);
60+
metaAccess.lookupJavaMethod(ReflectionUtil.lookupMethod(Runtime.class, "gc")).setPinnedToInitialLayer(pinReason);
61+
metaAccess.lookupJavaMethod(ReflectionUtil.lookupMethod(Class.class, "getResource", String.class)).setPinnedToInitialLayer(pinReason);
62+
}
63+
64+
}

0 commit comments

Comments
 (0)