Skip to content

Commit dc9621a

Browse files
committed
avoid duplicate but empty arrays
1 parent d1b8bb1 commit dc9621a

File tree

16 files changed

+45
-31
lines changed

16 files changed

+45
-31
lines changed

sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/c/function/CFunctionPointer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -119,6 +119,8 @@ public abstract class AnalysisMethod extends AnalysisElement implements WrappedJ
119119
private static final AtomicReferenceFieldUpdater<AnalysisMethod, Boolean> reachableInCurrentLayerUpdater = AtomicReferenceFieldUpdater
120120
.newUpdater(AnalysisMethod.class, Boolean.class, "reachableInCurrentLayer");
121121

122+
public static final AnalysisMethod[] EMPTY_ARRAY = new AnalysisMethod[0];
123+
122124
public record Signature(String name, AnalysisType[] parameterTypes) {
123125
}
124126

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ public abstract class AnalysisType extends AnalysisElement implements WrappedJav
115115

116116
private static final AtomicReferenceFieldUpdater<AnalysisType, Object> RESOLVED_METHODS_UPDATER = AtomicReferenceFieldUpdater.newUpdater(AnalysisType.class, Object.class, "resolvedMethods");
117117

118+
public static final AnalysisType[] EMPTY_ARRAY = new AnalysisType[0];
119+
118120
protected final AnalysisUniverse universe;
119121
private final ResolvedJavaType wrapped;
120122
private final String qualifiedName;
@@ -360,7 +362,7 @@ private AnalysisType[] convertTypes(ResolvedJavaType[] originalTypes) {
360362
}
361363
result.add(universe.lookup(originalType));
362364
}
363-
return result.toArray(new AnalysisType[result.size()]);
365+
return result.toArray(AnalysisType.EMPTY_ARRAY);
364366
}
365367

366368
public AnalysisType getArrayClass(int dim) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -471,7 +471,7 @@ public AnalysisMethod[] lookup(JavaMethod[] inputs) {
471471
}
472472
}
473473
}
474-
return result.toArray(new AnalysisMethod[result.size()]);
474+
return result.toArray(AnalysisMethod.EMPTY_ARRAY);
475475
}
476476

477477
@Override

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtractor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ private AnnotationValue[][] getParameterAnnotationDataFromRoot(Executable rootEl
279279
ByteBuffer buf = ByteBuffer.wrap(rawParameterAnnotations);
280280
try {
281281
int numParameters = buf.get() & 0xFF;
282+
if (numParameters == 0) {
283+
return NO_PARAMETER_ANNOTATIONS;
284+
}
282285
AnnotationValue[][] parameterAnnotations = new AnnotationValue[numParameters][];
283286
for (int i = 0; i < numParameters; i++) {
284287
List<AnnotationValue> parameterAnnotationList = new ArrayList<>();

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/RestrictHeapAccessCalleesImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void aggregateMethods(Collection<AnalysisMethod> methods) {
114114
}
115115
MethodAggregator visitor = new MethodAggregator(aggregation, assertionErrorConstructorList);
116116
AnalysisMethodCalleeWalker walker = new AnalysisMethodCalleeWalker();
117-
for (AnalysisMethod method : aggregation.keySet().toArray(new AnalysisMethod[0])) {
117+
for (AnalysisMethod method : aggregation.keySet().toArray(AnalysisMethod.EMPTY_ARRAY)) {
118118
walker.walkMethod(method, visitor);
119119
}
120120
calleeToCallerMap = Collections.unmodifiableMap(aggregation);

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/RuntimeMetadataEncoderImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,8 @@ public void addRecordComponentsLookupError(HostedType declaringClass, Throwable
720720
}
721721

722722
private static HostedType[] getParameterTypes(HostedMethod method) {
723-
HostedType[] parameterTypes = new HostedType[method.getSignature().getParameterCount(false)];
723+
int len = method.getSignature().getParameterCount(false);
724+
HostedType[] parameterTypes = len == 0 ? HostedType.EMPTY_ARRAY : new HostedType[len];
724725
for (int i = 0; i < parameterTypes.length; ++i) {
725726
parameterTypes[i] = method.getSignature().getParameterType(i);
726727
}
@@ -737,7 +738,7 @@ private static String[] getParameterTypeNames(HostedMethod method) {
737738

738739
private static HostedType[] getExceptionTypes(MetaAccessProvider metaAccess, Executable reflectMethod) {
739740
Class<?>[] exceptionClasses = reflectMethod.getExceptionTypes();
740-
HostedType[] exceptionTypes = new HostedType[exceptionClasses.length];
741+
HostedType[] exceptionTypes = exceptionClasses.length == 0 ? HostedType.EMPTY_ARRAY : new HostedType[exceptionClasses.length];
741742
for (int i = 0; i < exceptionClasses.length; ++i) {
742743
exceptionTypes[i] = (HostedType) metaAccess.lookupJavaType(exceptionClasses[i]);
743744
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageHeapWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public NativeImageHeapWriter(NativeImageHeap heap, ImageHeapLayoutInfo heapLayou
104104
public long writeHeap(DebugContext debug, RelocatableBuffer buffer) {
105105
try (Indent perHeapIndent = debug.logAndIndent("NativeImageHeap.writeHeap:")) {
106106
for (ObjectInfo info : heap.getObjects()) {
107-
assert !heap.isBlacklisted(info.getObject());
107+
assert !heap.isBlacklisted(info.getObject()) : "Backlisted object: " + info.getObject();
108108
if (info.getConstant().isWrittenInPreviousLayer()) {
109109
/*
110110
* Base layer constants already written in the base layer heap are only added to

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedArrayClass.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public int getArrayDimension() {
8181

8282
@Override
8383
public HostedField[] getInstanceFields(boolean includeSuperclasses) {
84-
return new HostedField[0];
84+
return HostedField.EMPTY_ARRAY;
8585
}
8686

8787
@Override

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedField.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
*/
4444
public class HostedField extends HostedElement implements OriginalFieldProvider, SharedField, WrappedJavaField {
4545

46+
static final int LOC_UNMATERIALIZED_STATIC_CONSTANT = -10;
47+
48+
public static final HostedField[] EMPTY_ARRAY = new HostedField[0];
49+
4650
public final AnalysisField wrapped;
4751

4852
private final HostedType holder;
@@ -51,8 +55,6 @@ public class HostedField extends HostedElement implements OriginalFieldProvider,
5155
protected int location;
5256
private int installedLayerNum;
5357

54-
static final int LOC_UNMATERIALIZED_STATIC_CONSTANT = -10;
55-
5658
public HostedField(AnalysisField wrapped, HostedType holder, HostedType type) {
5759
this.wrapped = wrapped;
5860
this.holder = holder;

0 commit comments

Comments
 (0)