Skip to content

Commit 6825521

Browse files
committed
Replace raw arrays with List
1 parent b0fe5a0 commit 6825521

23 files changed

+493
-553
lines changed

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/DebugInfo.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2009, 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
@@ -22,6 +22,7 @@
2222
*/
2323
package jdk.vm.ci.code;
2424

25+
import java.util.List;
2526
import java.util.Objects;
2627

2728
/**
@@ -40,21 +41,19 @@ public final class DebugInfo {
4041

4142
private final BytecodePosition bytecodePosition;
4243
private ReferenceMap referenceMap;
43-
private final VirtualObject[] virtualObjectMapping;
44+
private final List<VirtualObject> virtualObjectMapping;
4445
private RegisterSaveLayout calleeSaveInfo;
4546

4647
/**
4748
* Creates a new {@link DebugInfo} from the given values.
4849
*
49-
* @param codePos the {@linkplain BytecodePosition code position} or {@linkplain BytecodeFrame
50-
* frame} info
51-
* @param virtualObjectMapping the mapping of {@link VirtualObject}s to their real values. This
52-
* array is now owned by this object and must not be mutated by the caller.
50+
* @param codePos the {@linkplain BytecodePosition code position} or {@linkplain BytecodeFrame
51+
* frame} info
52+
* @param virtualObjectMapping the mapping of {@link VirtualObject}s to their real values.
5353
*/
54-
@SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "caller transfers ownership of `virtualObjectMapping`")
5554
public DebugInfo(BytecodePosition codePos, VirtualObject[] virtualObjectMapping) {
5655
this.bytecodePosition = codePos;
57-
this.virtualObjectMapping = virtualObjectMapping;
56+
this.virtualObjectMapping = virtualObjectMapping == null ? List.of() : List.of(virtualObjectMapping);
5857
}
5958

6059
public DebugInfo(BytecodePosition codePos) {
@@ -91,8 +90,8 @@ public String toString() {
9190

9291
/**
9392
* @return The code position (including all inlined methods) of this debug info. If this is a
94-
* {@link BytecodeFrame} instance, then it is also the deoptimization information for
95-
* each inlined frame.
93+
* {@link BytecodeFrame} instance, then it is also the deoptimization information for
94+
* each inlined frame.
9695
*/
9796
public BytecodePosition getBytecodePosition() {
9897
return bytecodePosition;
@@ -102,7 +101,7 @@ public ReferenceMap getReferenceMap() {
102101
return referenceMap;
103102
}
104103

105-
public VirtualObject[] getVirtualObjectMapping() {
104+
public List<VirtualObject> getVirtualObjectMapping() {
106105
return virtualObjectMapping;
107106
}
108107

@@ -132,11 +131,8 @@ public boolean equals(Object obj) {
132131
if (this == obj) {
133132
return true;
134133
}
135-
if (obj instanceof DebugInfo) {
136-
DebugInfo that = (DebugInfo) obj;
137-
if (Objects.equals(this.bytecodePosition, that.bytecodePosition) && Objects.equals(this.calleeSaveInfo, that.calleeSaveInfo) && Objects.equals(this.referenceMap, that.referenceMap)) {
138-
return true;
139-
}
134+
if (obj instanceof DebugInfo that) {
135+
return Objects.equals(this.bytecodePosition, that.bytecodePosition) && Objects.equals(this.calleeSaveInfo, that.calleeSaveInfo) && Objects.equals(this.referenceMap, that.referenceMap);
140136
}
141137
return false;
142138
}

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/VirtualObject.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 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
@@ -24,6 +24,7 @@
2424

2525
import java.util.Collections;
2626
import java.util.IdentityHashMap;
27+
import java.util.List;
2728
import java.util.Set;
2829

2930
import jdk.vm.ci.common.JVMCIError;
@@ -43,7 +44,7 @@ public final class VirtualObject implements JavaValue {
4344
private JavaValue[] values;
4445
private JavaKind[] slotKinds;
4546
private final int id;
46-
private boolean isAutoBox;
47+
private final boolean isAutoBox;
4748

4849
/**
4950
* Creates a new {@link VirtualObject} for the given type, with the given fields. If
@@ -89,8 +90,7 @@ private VirtualObject(ResolvedJavaType type, int id, boolean isAutoBox) {
8990
}
9091

9192
private static StringBuilder appendValue(StringBuilder buf, JavaValue value, Set<VirtualObject> visited) {
92-
if (value instanceof VirtualObject) {
93-
VirtualObject vo = (VirtualObject) value;
93+
if (value instanceof VirtualObject vo) {
9494
buf.append("vobject:").append(vo.type.toJavaName(false)).append(':').append(vo.id);
9595
if (!visited.contains(vo)) {
9696
visited.add(vo);
@@ -107,22 +107,22 @@ private static StringBuilder appendValue(StringBuilder buf, JavaValue value, Set
107107
appendValue(buf, vo.values[i], visited);
108108
}
109109
} else {
110-
ResolvedJavaField[] fields = vo.type.getInstanceFields(true);
110+
List<ResolvedJavaField> fields = vo.type.getInstanceFields(true);
111111
int fieldIndex = 0;
112112
for (int i = 0; i < vo.values.length; i++, fieldIndex++) {
113113
if (i != 0) {
114114
buf.append(',');
115115
}
116-
if (fieldIndex >= fields.length) {
116+
if (fieldIndex >= fields.size()) {
117117
buf.append("<missing field>");
118118
} else {
119-
ResolvedJavaField field = fields[fieldIndex];
119+
ResolvedJavaField field = fields.get(fieldIndex);
120120
buf.append(field.getName());
121121
if (vo.slotKinds[i].getSlotCount() == 2 && field.getType().getJavaKind().getSlotCount() == 1) {
122-
if (fieldIndex + 1 >= fields.length) {
122+
if (fieldIndex + 1 >= fields.size()) {
123123
buf.append("/<missing field>");
124124
} else {
125-
ResolvedJavaField field2 = fields[++fieldIndex];
125+
ResolvedJavaField field2 = fields.get(++fieldIndex);
126126
buf.append('/').append(field2.getName());
127127
}
128128
}
@@ -131,8 +131,8 @@ private static StringBuilder appendValue(StringBuilder buf, JavaValue value, Set
131131
appendValue(buf, vo.values[i], visited);
132132
}
133133
// Extra fields
134-
for (; fieldIndex < fields.length; fieldIndex++) {
135-
buf.append(fields[fieldIndex].getName()).append("=<missing value>");
134+
for (; fieldIndex < fields.size(); fieldIndex++) {
135+
buf.append(fields.get(fieldIndex).getName()).append("=<missing value>");
136136
}
137137
}
138138
}
@@ -154,25 +154,25 @@ default JavaKind getStorageKind(ResolvedJavaField field) {
154154

155155
public void verifyLayout(LayoutVerifier verifier) {
156156
if (!type.isArray()) {
157-
ResolvedJavaField[] fields = type.getInstanceFields(true);
157+
List<ResolvedJavaField> fields = type.getInstanceFields(true);
158158
int fieldIndex = 0;
159159
for (int i = 0; i < values.length; i++, fieldIndex++) {
160160
JavaKind slotKind = slotKinds[i];
161-
if (fieldIndex >= fields.length) {
161+
if (fieldIndex >= fields.size()) {
162162
throw new JVMCIError("Not enough fields for the values provided for %s", toString());
163163
} else {
164-
ResolvedJavaField field = fields[fieldIndex];
164+
ResolvedJavaField field = fields.get(fieldIndex);
165165
JavaKind fieldKind = verifier.getStorageKind(field);
166166
if (slotKind.getSlotCount() == 2 && fieldKind == JavaKind.Int) {
167167
int offset = verifier.getOffset(field);
168168
if (offset % 8 != 0) {
169169
throw new JVMCIError("Double word value stored across two ints must be aligned %s", toString());
170170
}
171171

172-
if (fieldIndex + 1 >= fields.length) {
172+
if (fieldIndex + 1 >= fields.size()) {
173173
throw new JVMCIError("Missing second field for double word value stored in two ints %s", toString());
174174
}
175-
ResolvedJavaField field2 = fields[fieldIndex + 1];
175+
ResolvedJavaField field2 = fields.get(fieldIndex + 1);
176176
if (field2.getType().getJavaKind() != JavaKind.Int) {
177177
throw new JVMCIError("Second field for double word value stored in two ints must be int but got %s in %s", field2.getType().getJavaKind(), toString());
178178
}
@@ -187,7 +187,7 @@ public void verifyLayout(LayoutVerifier verifier) {
187187
}
188188
}
189189
// Extra fields
190-
if (fieldIndex < fields.length) {
190+
if (fieldIndex < fields.size()) {
191191
throw new JVMCIError("Not enough values provided for fields in %s", this);
192192
}
193193
} else if (type.getComponentType().getJavaKind() == JavaKind.Byte) {
@@ -289,8 +289,7 @@ public boolean equals(Object o) {
289289
if (o == this) {
290290
return true;
291291
}
292-
if (o instanceof VirtualObject) {
293-
VirtualObject l = (VirtualObject) o;
292+
if (o instanceof VirtualObject l) {
294293
if (!l.type.equals(type) || l.values.length != values.length) {
295294
return false;
296295
}

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/AnnotationDataDecoder.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 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
@@ -63,6 +63,9 @@ public ErrorData newErrorValue(String description) {
6363
return new ErrorData(description);
6464
}
6565

66+
/**
67+
* Aggregate {@link ResolvedJavaType} inputs in an array as argument to varargs method.
68+
*/
6669
static ResolvedJavaType[] asArray(ResolvedJavaType type1, ResolvedJavaType type2, ResolvedJavaType... types) {
6770
ResolvedJavaType[] filter = new ResolvedJavaType[2 + types.length];
6871
filter[0] = type1;

0 commit comments

Comments
 (0)