forked from oracle/graal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GR-57999] Replace JVMCI API with Native Image API.
PullRequest: graal/18863
- Loading branch information
Showing
70 changed files
with
386 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...jdk.graal.compiler.test/src/jdk/graal/compiler/core/test/VerifyLibGraalContextChecks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright (c) 2024, 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 | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
package jdk.graal.compiler.core.test; | ||
|
||
import java.util.List; | ||
|
||
import jdk.graal.compiler.hotspot.HotSpotGraalCompilerFactory; | ||
import jdk.graal.compiler.nodes.StructuredGraph; | ||
import jdk.graal.compiler.nodes.java.LoadFieldNode; | ||
import jdk.graal.compiler.nodes.spi.CoreProviders; | ||
import jdk.graal.compiler.phases.VerifyPhase; | ||
import jdk.graal.compiler.serviceprovider.GraalServices; | ||
import jdk.vm.ci.meta.ResolvedJavaField; | ||
import jdk.vm.ci.meta.ResolvedJavaMethod; | ||
import jdk.vm.ci.meta.ResolvedJavaType; | ||
import jdk.vm.ci.services.Services; | ||
import org.graalvm.nativeimage.ImageInfo; | ||
|
||
/** | ||
* Ensures that the only code directly accessing | ||
* {@link jdk.vm.ci.services.Services#IS_IN_NATIVE_IMAGE} and | ||
* {@link jdk.vm.ci.services.Services#IS_BUILDING_NATIVE_IMAGE} is in | ||
* {@link jdk.graal.compiler.serviceprovider.GraalServices}. All other code must use one of the | ||
* following methods: | ||
* <ul> | ||
* <li>{@link GraalServices#isBuildingLibgraal()}</li> | ||
* <li>{@link GraalServices#isInLibgraal()}</li> | ||
* <li>{@link ImageInfo#inImageCode()}</li> | ||
* <li>{@link ImageInfo#inImageBuildtimeCode()}</li> | ||
* <li>{@link ImageInfo#inImageRuntimeCode()}</li> | ||
* </ul> | ||
*/ | ||
public class VerifyLibGraalContextChecks extends VerifyPhase<CoreProviders> { | ||
|
||
@Override | ||
public boolean checkContract() { | ||
return false; | ||
} | ||
|
||
static boolean isAllowedToAccess(ResolvedJavaMethod method) { | ||
if (method.getDeclaringClass().toJavaName().equals(GraalServices.class.getName())) { | ||
return method.getName().equals("isBuildingLibgraal") || method.getName().equals("isInLibgraal"); | ||
} | ||
if (method.getDeclaringClass().toJavaName().equals(HotSpotGraalCompilerFactory.class.getName())) { | ||
return method.getName().equals("createCompiler"); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
protected void verify(StructuredGraph graph, CoreProviders context) { | ||
|
||
final ResolvedJavaType servicesType = context.getMetaAccess().lookupJavaType(Services.class); | ||
servicesType.getStaticFields(); | ||
|
||
List<LoadFieldNode> loads = graph.getNodes().filter(LoadFieldNode.class).snapshot(); | ||
for (LoadFieldNode load : loads) { | ||
ResolvedJavaField field = load.field(); | ||
if (field.getDeclaringClass().toJavaName().equals(Services.class.getName())) { | ||
if (field.getName().equals("IS_BUILDING_NATIVE_IMAGE") || field.getName().equals("IS_IN_NATIVE_IMAGE")) { | ||
if (!isAllowedToAccess(graph.method())) { | ||
String recommendation = field.getName().equals("IS_BUILDING_NATIVE_IMAGE") ? "isBuildingLibgraal" : "isInLibgraal"; | ||
throw new VerificationError("reading %s in %s is prohibited - use %s.%s() instead", | ||
field.format("%H.%n"), | ||
graph.method().format("%H.%n(%p)"), | ||
GraalServices.class.getName(), | ||
recommendation); | ||
|
||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.