Skip to content

Commit

Permalink
Parse annotations without initializing them
Browse files Browse the repository at this point in the history
  • Loading branch information
loicottet committed Jun 15, 2022
1 parent e7e34f3 commit 2554dcd
Show file tree
Hide file tree
Showing 87 changed files with 2,508 additions and 1,180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package org.graalvm.compiler.nodes;

import static jdk.vm.ci.services.Services.IS_BUILDING_NATIVE_IMAGE;
import static jdk.vm.ci.services.Services.IS_IN_NATIVE_IMAGE;

import java.util.ArrayList;
Expand Down Expand Up @@ -506,7 +507,7 @@ private StructuredGraph(String name,
}

private static boolean checkIsSubstitutionInvariants(ResolvedJavaMethod method, boolean isSubstitution) {
if (!IS_IN_NATIVE_IMAGE) {
if (!IS_IN_NATIVE_IMAGE && !IS_BUILDING_NATIVE_IMAGE) {
if (method != null) {
if (method.getAnnotation(Snippet.class) != null) {
assert isSubstitution : "Graph for method " + method.format("%H.%n(%p)") +
Expand Down
5 changes: 4 additions & 1 deletion substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@
"sun.text.spi",
"jdk.internal.reflect",
"sun.util.cldr",
"sun.util.locale"
"sun.util.locale",
"sun.invoke.util",
],
"jdk.internal.vm.ci" : [
"jdk.vm.ci.meta",
Expand Down Expand Up @@ -1130,6 +1131,8 @@
"com.oracle.svm.hosted.agent to java.instrument",
"com.oracle.svm.truffle.api to org.graalvm.truffle",
"com.oracle.svm.core.option to com.oracle.svm_enterprise.ml_dataset",
"com.oracle.svm.core.annotate",
"com.oracle.svm.core.graal.code",
"* to org.graalvm.nativeimage.base,jdk.internal.vm.compiler,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.configure,org.graalvm.nativeimage.librarysupport,org.graalvm.nativeimage.junitsupport,org.graalvm.nativeimage.llvm,org.graalvm.nativeimage.agent.jvmtibase,org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.agent.diagnostics,com.oracle.svm.svm_enterprise",
],
"opens" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
import org.graalvm.compiler.replacements.nodes.ObjectClone;
import org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode;
import org.graalvm.compiler.word.WordCastNode;
import org.graalvm.util.GuardedAnnotationAccess;
import com.oracle.svm.util.GuardedAnnotationAccess;

import com.oracle.graal.pointsto.PointsToAnalysis;
import com.oracle.graal.pointsto.flow.LoadFieldTypeFlow.LoadInstanceFieldTypeFlow;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2022, 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
* 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 com.oracle.graal.pointsto.infrastructure;

import java.lang.reflect.AnnotatedElement;

import com.oracle.svm.util.AnnotationWrapper;

import jdk.vm.ci.meta.ResolvedJavaField;

public interface WrappedJavaField extends WrappedElement, ResolvedJavaField, AnnotationWrapper {

@Override
ResolvedJavaField getWrapped();

@Override
default AnnotatedElement getAnnotationRoot() {
return getWrapped();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,19 @@
*/
package com.oracle.graal.pointsto.infrastructure;

import java.lang.reflect.AnnotatedElement;

import com.oracle.svm.util.AnnotationWrapper;

import jdk.vm.ci.meta.ResolvedJavaMethod;

public interface WrappedJavaMethod extends WrappedElement, ResolvedJavaMethod {
public interface WrappedJavaMethod extends WrappedElement, ResolvedJavaMethod, AnnotationWrapper {

@Override
ResolvedJavaMethod getWrapped();

@Override
default AnnotatedElement getAnnotationRoot() {
return getWrapped();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,19 @@
*/
package com.oracle.graal.pointsto.infrastructure;

import java.lang.reflect.AnnotatedElement;

import com.oracle.svm.util.AnnotationWrapper;

import jdk.vm.ci.meta.ResolvedJavaType;

public interface WrappedJavaType extends WrappedElement, ResolvedJavaType {
public interface WrappedJavaType extends WrappedElement, ResolvedJavaType, AnnotationWrapper {

@Override
ResolvedJavaType getWrapped();

@Override
default AnnotatedElement getAnnotationRoot() {
return getWrapped();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
package com.oracle.graal.pointsto.meta;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Set;
Expand All @@ -34,24 +34,25 @@
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

import org.graalvm.compiler.debug.GraalError;
import org.graalvm.util.GuardedAnnotationAccess;

import com.oracle.graal.pointsto.api.DefaultUnsafePartition;
import com.oracle.graal.pointsto.api.HostVM;
import com.oracle.graal.pointsto.api.PointstoOptions;
import com.oracle.graal.pointsto.flow.ContextInsensitiveFieldTypeFlow;
import com.oracle.graal.pointsto.flow.FieldTypeFlow;
import com.oracle.graal.pointsto.infrastructure.OriginalFieldProvider;
import com.oracle.graal.pointsto.infrastructure.WrappedJavaField;
import com.oracle.graal.pointsto.typestate.TypeState;
import com.oracle.graal.pointsto.util.AtomicUtils;
import com.oracle.graal.pointsto.util.ConcurrentLightHashSet;
import com.oracle.svm.util.AnnotationWrapper;
import com.oracle.svm.util.UnsafePartitionKind;

import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.ResolvedJavaField;
import jdk.vm.ci.meta.ResolvedJavaType;

public abstract class AnalysisField extends AnalysisElement implements ResolvedJavaField, OriginalFieldProvider {
public abstract class AnalysisField extends AnalysisElement implements WrappedJavaField, OriginalFieldProvider, AnnotationWrapper {

@SuppressWarnings("rawtypes")//
private static final AtomicReferenceFieldUpdater<AnalysisField, Object> OBSERVERS_UPDATER = //
Expand Down Expand Up @@ -167,6 +168,11 @@ private static AnalysisType getDeclaredType(AnalysisUniverse universe, ResolvedJ
return universe.lookup(resolvedType);
}

@Override
public ResolvedJavaField getWrapped() {
return wrapped;
}

public void copyAccessInfos(AnalysisField other) {
isAccessedUpdater.set(this, other.isAccessed);
isUnsafeAccessedUpdater.set(this, other.isUnsafeAccessed);
Expand Down Expand Up @@ -482,18 +488,8 @@ public boolean isStatic() {
}

@Override
public Annotation[] getAnnotations() {
return GuardedAnnotationAccess.getAnnotations(wrapped);
}

@Override
public Annotation[] getDeclaredAnnotations() {
return GuardedAnnotationAccess.getDeclaredAnnotations(wrapped);
}

@Override
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
return GuardedAnnotationAccess.getAnnotation(wrapped, annotationClass);
public AnnotatedElement getAnnotationRoot() {
return wrapped;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.graalvm.compiler.nodes.GraphDecoder;
import org.graalvm.compiler.nodes.StructuredGraph;
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
import org.graalvm.util.GuardedAnnotationAccess;

import com.oracle.graal.pointsto.BigBang;
import com.oracle.graal.pointsto.api.PointstoOptions;
Expand Down Expand Up @@ -572,21 +571,6 @@ public ConstantPool getConstantPool() {
return getUniverse().lookup(wrapped.getConstantPool(), getDeclaringClass());
}

@Override
public Annotation[] getAnnotations() {
return GuardedAnnotationAccess.getAnnotations(wrapped);
}

@Override
public Annotation[] getDeclaredAnnotations() {
return GuardedAnnotationAccess.getDeclaredAnnotations(wrapped);
}

@Override
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
return GuardedAnnotationAccess.getAnnotation(wrapped, annotationClass);
}

@Override
public Annotation[][] getParameterAnnotations() {
return wrapped.getParameterAnnotations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
package com.oracle.graal.pointsto.meta;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -42,7 +41,6 @@

import org.graalvm.compiler.debug.GraalError;
import org.graalvm.compiler.graph.Node;
import org.graalvm.util.GuardedAnnotationAccess;
import org.graalvm.word.WordBase;

import com.oracle.graal.pointsto.BigBang;
Expand Down Expand Up @@ -1100,21 +1098,6 @@ public AnalysisField[] getStaticFields() {
return convertFields(wrapped.getStaticFields(), new ArrayList<>(), false);
}

@Override
public Annotation[] getAnnotations() {
return GuardedAnnotationAccess.getAnnotations(wrapped);
}

@Override
public Annotation[] getDeclaredAnnotations() {
return GuardedAnnotationAccess.getDeclaredAnnotations(wrapped);
}

@Override
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
return GuardedAnnotationAccess.getAnnotation(wrapped, annotationClass);
}

@Override
public String getSourceFileName() {
// getSourceFileName is not implemented for primitive types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
import org.graalvm.nativeimage.c.constant.CEnum;
import org.graalvm.nativeimage.c.function.CEntryPoint;
import org.graalvm.util.GuardedAnnotationAccess;
import com.oracle.svm.util.GuardedAnnotationAccess;

import com.oracle.svm.core.FrameAccess;
import com.oracle.svm.core.ReservedRegisters;
Expand Down
2 changes: 1 addition & 1 deletion substratevm/src/com.oracle.svm.core/.checkstyle_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<metadata name="net.sf.eclipsecs.core.comment" value="Disallow calls to AnnotatedElement.get(Declared)Annotation(s)."/>
<property name="severity" value="error"/>
<property name="format" value="(?&lt;!AnnotationAccess)\.(getAnnotation|getAnnotations|getDeclaredAnnotation|getDeclaredAnnotations|isAnnotationPresent)\b"/>
<property name="message" value="Direct calls to java.lang.reflect.AnnotatedElement.get(Declared)Annotation(s) are restricted. Use either org.graalvm.util.GuardedAnnotationAccess or org.graalvm.util.DirectAnnotationAccess methods. (Use &quot;// Checkstyle: allow direct annotation access... // Checkstyle: disallow direct annotation access&quot; to disable this check.)"/>
<property name="message" value="Direct calls to java.lang.reflect.AnnotatedElement.get(Declared)Annotation(s) are restricted. Use either com.oracle.svm.util.GuardedAnnotationAccess or com.oracle.svm.util.DirectAnnotationAccess methods. (Use &quot;// Checkstyle: allow direct annotation access... // Checkstyle: disallow direct annotation access&quot; to disable this check.)"/>
<property name="ignoreComments" value="true"/>
</module>
<module name="SuppressionCommentFilter">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.util.GuardedAnnotationAccess;
import com.oracle.svm.util.GuardedAnnotationAccess;

import com.oracle.svm.core.CalleeSavedRegisters;
import com.oracle.svm.core.snippets.SubstrateForeignCallTarget;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import org.graalvm.compiler.api.replacements.Fold;
import org.graalvm.nativeimage.c.function.CFunction;
import org.graalvm.nativeimage.c.function.InvokeCFunctionPointer;
import org.graalvm.util.DirectAnnotationAccess;
import org.graalvm.util.GuardedAnnotationAccess;
import com.oracle.svm.util.DirectAnnotationAccess;
import com.oracle.svm.util.GuardedAnnotationAccess;
import org.graalvm.word.WordBase;

import com.oracle.svm.core.snippets.KnownIntrinsics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import java.lang.reflect.Field;
import java.util.Arrays;

import org.graalvm.util.DirectAnnotationAccess;
import com.oracle.svm.util.DirectAnnotationAccess;

import com.oracle.svm.core.util.VMError;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.util.GuardedAnnotationAccess;
import com.oracle.svm.util.GuardedAnnotationAccess;

public interface LibCBase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.graalvm.compiler.api.replacements.Fold;
import org.graalvm.compiler.core.common.NumUtil;
import org.graalvm.nativeimage.c.constant.CEnum;
import org.graalvm.util.GuardedAnnotationAccess;
import com.oracle.svm.util.GuardedAnnotationAccess;
import org.graalvm.word.WordBase;

import com.oracle.svm.core.SubstrateTargetDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.hosted.Feature;
import org.graalvm.util.DirectAnnotationAccess;
import com.oracle.svm.util.DirectAnnotationAccess;

import com.oracle.svm.core.SubstrateTargetDescription;
import com.oracle.svm.core.config.ConfigurationValues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.graalvm.compiler.phases.tiers.MidTierContext;
import org.graalvm.nativeimage.c.function.CFunction;
import org.graalvm.nativeimage.c.function.InvokeCFunctionPointer;
import org.graalvm.util.DirectAnnotationAccess;
import com.oracle.svm.util.DirectAnnotationAccess;

import com.oracle.svm.core.annotate.Uninterruptible;
import com.oracle.svm.core.graal.code.SubstrateBackend;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.graalvm.compiler.nodes.memory.address.AddressNode;
import org.graalvm.compiler.word.WordOperationPlugin;
import org.graalvm.compiler.word.WordTypes;
import org.graalvm.util.GuardedAnnotationAccess;
import com.oracle.svm.util.GuardedAnnotationAccess;
import org.graalvm.word.LocationIdentity;

import jdk.vm.ci.meta.JavaKind;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import org.graalvm.compiler.word.WordTypes;
import org.graalvm.nativeimage.c.function.InvokeCFunctionPointer;
import org.graalvm.util.GuardedAnnotationAccess;
import com.oracle.svm.util.GuardedAnnotationAccess;

import com.oracle.svm.core.util.UserError;

Expand Down
Loading

0 comments on commit 2554dcd

Please sign in to comment.