Skip to content

Commit 721e760

Browse files
committed
Refactor: Use ArrayList instead of LinkedList
1 parent e85e3f6 commit 721e760

File tree

7 files changed

+40
-39
lines changed

7 files changed

+40
-39
lines changed

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/ClassEntry.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import java.nio.file.Path;
3838
import java.util.ArrayList;
3939
import java.util.HashMap;
40-
import java.util.LinkedList;
4140
import java.util.List;
4241
import java.util.ListIterator;
4342
import java.util.Map;
@@ -53,7 +52,7 @@ public class ClassEntry extends StructureTypeEntry {
5352
/**
5453
* Details of this class's interfaces.
5554
*/
56-
protected LinkedList<InterfaceClassEntry> interfaces;
55+
protected List<InterfaceClassEntry> interfaces;
5756
/**
5857
* Details of the associated file.
5958
*/
@@ -66,7 +65,7 @@ public class ClassEntry extends StructureTypeEntry {
6665
* A list recording details of all primary ranges included in this class sorted by ascending
6766
* address range.
6867
*/
69-
private LinkedList<PrimaryEntry> primaryEntries;
68+
private List<PrimaryEntry> primaryEntries;
7069
/**
7170
* An index identifying primary ranges which have already been encountered.
7271
*/
@@ -78,30 +77,30 @@ public class ClassEntry extends StructureTypeEntry {
7877
/**
7978
* A list of the same files.
8079
*/
81-
private LinkedList<FileEntry> localFiles;
80+
private List<FileEntry> localFiles;
8281
/**
8382
* An index of all primary and secondary dirs referenced from this class's compilation unit.
8483
*/
8584
private HashMap<DirEntry, Integer> localDirsIndex;
8685
/**
8786
* A list of the same dirs.
8887
*/
89-
private LinkedList<DirEntry> localDirs;
88+
private List<DirEntry> localDirs;
9089
/**
9190
* This flag is true iff the entry includes methods that are deopt targets.
9291
*/
9392
private boolean includesDeoptTarget;
9493

9594
public ClassEntry(String className, FileEntry fileEntry, int size) {
9695
super(className, size);
97-
this.interfaces = new LinkedList<>();
96+
this.interfaces = new ArrayList<>();
9897
this.fileEntry = fileEntry;
99-
this.methods = new LinkedList<>();
100-
this.primaryEntries = new LinkedList<>();
98+
this.methods = new ArrayList<>();
99+
this.primaryEntries = new ArrayList<>();
101100
this.primaryIndex = new HashMap<>();
102-
this.localFiles = new LinkedList<>();
101+
this.localFiles = new ArrayList<>();
103102
this.localFilesIndex = new HashMap<>();
104-
this.localDirs = new LinkedList<>();
103+
this.localDirs = new ArrayList<>();
105104
this.localDirsIndex = new HashMap<>();
106105
if (fileEntry != null) {
107106
localFiles.add(fileEntry);
@@ -231,7 +230,7 @@ public FileEntry getFileEntry() {
231230
return fileEntry;
232231
}
233232

234-
public LinkedList<PrimaryEntry> getPrimaryEntries() {
233+
public List<PrimaryEntry> getPrimaryEntries() {
235234
return primaryEntries;
236235
}
237236

@@ -240,11 +239,11 @@ public Object primaryIndexFor(Range primaryRange) {
240239
return primaryIndex.get(primaryRange);
241240
}
242241

243-
public LinkedList<DirEntry> getLocalDirs() {
242+
public List<DirEntry> getLocalDirs() {
244243
return localDirs;
245244
}
246245

247-
public LinkedList<FileEntry> getLocalFiles() {
246+
public List<FileEntry> getLocalFiles() {
248247
return localFiles;
249248
}
250249

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/DebugInfoBase.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
import java.nio.ByteOrder;
3030
import java.nio.file.Path;
3131
import java.nio.file.Paths;
32+
import java.util.ArrayList;
3233
import java.util.HashMap;
33-
import java.util.LinkedList;
34+
import java.util.List;
3435
import java.util.Map;
3536

3637
import org.graalvm.compiler.debug.DebugContext;
@@ -89,15 +90,15 @@ public abstract class DebugInfoBase {
8990
/**
9091
* List of class entries detailing class info for primary ranges.
9192
*/
92-
private LinkedList<TypeEntry> types = new LinkedList<>();
93+
private List<TypeEntry> types = new ArrayList<>();
9394
/**
9495
* index of already seen classes.
9596
*/
9697
private Map<String, TypeEntry> typesIndex = new HashMap<>();
9798
/**
9899
* List of class entries detailing class info for primary ranges.
99100
*/
100-
private LinkedList<ClassEntry> primaryClasses = new LinkedList<>();
101+
private List<ClassEntry> primaryClasses = new ArrayList<>();
101102
/**
102103
* index of already seen classes.
103104
*/
@@ -109,7 +110,7 @@ public abstract class DebugInfoBase {
109110
/**
110111
* List of of files which contain primary or secondary ranges.
111112
*/
112-
private LinkedList<FileEntry> files = new LinkedList<>();
113+
private List<FileEntry> files = new ArrayList<>();
113114
/**
114115
* Flag set to true if heap references are stored as addresses relative to a heap base register
115116
* otherwise false.
@@ -426,16 +427,16 @@ public ByteOrder getByteOrder() {
426427
return byteOrder;
427428
}
428429

429-
public LinkedList<TypeEntry> getTypes() {
430+
public List<TypeEntry> getTypes() {
430431
return types;
431432
}
432433

433-
public LinkedList<ClassEntry> getPrimaryClasses() {
434+
public List<ClassEntry> getPrimaryClasses() {
434435
return primaryClasses;
435436
}
436437

437438
@SuppressWarnings("unused")
438-
public LinkedList<FileEntry> getFiles() {
439+
public List<FileEntry> getFiles() {
439440
return files;
440441
}
441442

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/InterfaceClassEntry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugTypeInfo.DebugTypeKind;
3232
import org.graalvm.compiler.debug.DebugContext;
3333

34-
import java.util.LinkedList;
34+
import java.util.ArrayList;
3535
import java.util.List;
3636
import java.util.stream.Stream;
3737

@@ -40,7 +40,7 @@ public class InterfaceClassEntry extends ClassEntry {
4040

4141
public InterfaceClassEntry(String className, FileEntry fileEntry, int size) {
4242
super(className, fileEntry, size);
43-
implementors = new LinkedList<>();
43+
implementors = new ArrayList<>();
4444
}
4545

4646
@Override

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/PrimaryEntry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugFrameSizeChange;
3030

31-
import java.util.LinkedList;
31+
import java.util.ArrayList;
3232
import java.util.List;
3333

3434
/**
@@ -59,7 +59,7 @@ public class PrimaryEntry {
5959
public PrimaryEntry(Range primary, List<DebugFrameSizeChange> frameSizeInfos, int frameSize, ClassEntry classEntry) {
6060
this.primary = primary;
6161
this.classEntry = classEntry;
62-
this.subranges = new LinkedList<>();
62+
this.subranges = new ArrayList<>();
6363
this.frameSizeInfos = frameSizeInfos;
6464
this.frameSize = frameSize;
6565
}

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/StructureTypeEntry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
import java.lang.reflect.Modifier;
3333
import java.nio.file.Path;
34-
import java.util.LinkedList;
34+
import java.util.ArrayList;
3535
import java.util.List;
3636
import java.util.stream.Stream;
3737

@@ -47,7 +47,7 @@ public abstract class StructureTypeEntry extends TypeEntry {
4747

4848
public StructureTypeEntry(String typeName, int size) {
4949
super(typeName, size);
50-
this.fields = new LinkedList<>();
50+
this.fields = new ArrayList<>();
5151
}
5252

5353
public Stream<FieldEntry> fields() {

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/elf/dwarf/DwarfARangesSectionImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import com.oracle.objectfile.debugentry.Range;
3535
import org.graalvm.compiler.debug.DebugContext;
3636

37-
import java.util.LinkedList;
37+
import java.util.List;
3838
import java.util.Map;
3939

4040
/**
@@ -102,7 +102,7 @@ public void createContent() {
102102
* Align to 2 * address size.
103103
*/
104104
pos += DW_AR_HEADER_PAD_SIZE;
105-
LinkedList<PrimaryEntry> classPrimaryEntries = classEntry.getPrimaryEntries();
105+
List<PrimaryEntry> classPrimaryEntries = classEntry.getPrimaryEntries();
106106
if (classEntry.includesDeoptTarget()) {
107107
/* Deopt targets are in a higher address range so delay emit for them. */
108108
for (PrimaryEntry classPrimaryEntry : classPrimaryEntries) {
@@ -123,7 +123,7 @@ public void createContent() {
123123
* Align to 2 * address size.
124124
*/
125125
pos += DW_AR_HEADER_PAD_SIZE;
126-
LinkedList<PrimaryEntry> classPrimaryEntries = classEntry.getPrimaryEntries();
126+
List<PrimaryEntry> classPrimaryEntries = classEntry.getPrimaryEntries();
127127
for (PrimaryEntry classPrimaryEntry : classPrimaryEntries) {
128128
if (classPrimaryEntry.getPrimary().isDeoptTarget()) {
129129
pos += 2 * 8;
@@ -167,7 +167,7 @@ public void writeContent(DebugContext context) {
167167
int lastpos = pos;
168168
int length = DW_AR_HEADER_SIZE + DW_AR_HEADER_PAD_SIZE - 4;
169169
int cuIndex = getCUIndex(classEntry);
170-
LinkedList<PrimaryEntry> classPrimaryEntries = classEntry.getPrimaryEntries();
170+
List<PrimaryEntry> classPrimaryEntries = classEntry.getPrimaryEntries();
171171
/*
172172
* Count only real methods, omitting deopt targets.
173173
*/
@@ -218,7 +218,7 @@ public void writeContent(DebugContext context) {
218218
int lastpos = pos;
219219
int length = DW_AR_HEADER_SIZE + DW_AR_HEADER_PAD_SIZE - 4;
220220
int cuIndex = getDeoptCUIndex(classEntry);
221-
LinkedList<PrimaryEntry> classPrimaryEntries = classEntry.getPrimaryEntries();
221+
List<PrimaryEntry> classPrimaryEntries = classEntry.getPrimaryEntries();
222222
/*
223223
* Count only linkage stubs.
224224
*/

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/elf/dwarf/DwarfInfoSectionImpl.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import java.lang.reflect.Modifier;
3030
import java.util.LinkedList;
31+
import java.util.List;
3132
import java.util.Map;
3233
import java.util.Set;
3334

@@ -439,7 +440,7 @@ private int writePrimaryClassUnit(DebugContext context, ClassEntry classEntry, b
439440
String compilationDirectory = classEntry.getCachePath();
440441
log(context, " [0x%08x] comp_dir 0x%x (%s)", pos, debugStringIndex(compilationDirectory), compilationDirectory);
441442
pos = writeAttrStrp(compilationDirectory, buffer, pos);
442-
LinkedList<PrimaryEntry> classPrimaryEntries = classEntry.getPrimaryEntries();
443+
List<PrimaryEntry> classPrimaryEntries = classEntry.getPrimaryEntries();
443444
/*
444445
* Specify hi and lo for the compile unit which means we also need to ensure methods within
445446
* it are listed in ascending address order.
@@ -654,7 +655,7 @@ private int writeField(DebugContext context, StructureTypeEntry entry, FieldEntr
654655

655656
private int writeMethodDeclarations(DebugContext context, ClassEntry classEntry, byte[] buffer, int p) {
656657
int pos = p;
657-
LinkedList<PrimaryEntry> classPrimaryEntries = classEntry.getPrimaryEntries();
658+
List<PrimaryEntry> classPrimaryEntries = classEntry.getPrimaryEntries();
658659
for (PrimaryEntry primaryEntry : classPrimaryEntries) {
659660
Range range = primaryEntry.getPrimary();
660661
/*
@@ -913,7 +914,7 @@ private int writeInterfaceType(DebugContext context, InterfaceClassEntry interfa
913914

914915
private int writeMethodLocations(DebugContext context, ClassEntry classEntry, byte[] buffer, int p) {
915916
int pos = p;
916-
LinkedList<PrimaryEntry> classPrimaryEntries = classEntry.getPrimaryEntries();
917+
List<PrimaryEntry> classPrimaryEntries = classEntry.getPrimaryEntries();
917918
for (PrimaryEntry primaryEntry : classPrimaryEntries) {
918919
Range range = primaryEntry.getPrimary();
919920
if (!range.isDeoptTarget()) {
@@ -1181,7 +1182,7 @@ private int writeArrayTypes(DebugContext context, ArrayTypeEntry arrayTypeEntry,
11811182
private int writeDeoptMethodsCU(DebugContext context, ClassEntry classEntry, byte[] buffer, int p) {
11821183
int pos = p;
11831184
assert classEntry.includesDeoptTarget();
1184-
LinkedList<PrimaryEntry> classPrimaryEntries = classEntry.getPrimaryEntries();
1185+
List<PrimaryEntry> classPrimaryEntries = classEntry.getPrimaryEntries();
11851186
String fileName = classEntry.getFileName();
11861187
int lineIndex = getLineIndex(classEntry);
11871188
int abbrevCode = (fileName.length() > 0 ? DwarfDebugInfo.DW_ABBREV_CODE_class_unit1 : DwarfDebugInfo.DW_ABBREV_CODE_class_unit2);
@@ -1266,10 +1267,10 @@ private int writeCUHeader(byte[] buffer, int p) {
12661267
}
12671268
}
12681269

1269-
private static int findLo(LinkedList<PrimaryEntry> classPrimaryEntries, boolean isDeoptTargetCU) {
1270+
private static int findLo(List<PrimaryEntry> classPrimaryEntries, boolean isDeoptTargetCU) {
12701271
if (!isDeoptTargetCU) {
12711272
/* First entry is the one we want. */
1272-
return classPrimaryEntries.getFirst().getPrimary().getLo();
1273+
return classPrimaryEntries.get(0).getPrimary().getLo();
12731274
} else {
12741275
/* Need the first entry which is a deopt target. */
12751276
for (PrimaryEntry primaryEntry : classPrimaryEntries) {
@@ -1284,10 +1285,10 @@ private static int findLo(LinkedList<PrimaryEntry> classPrimaryEntries, boolean
12841285
return 0;
12851286
}
12861287

1287-
private static int findHi(LinkedList<PrimaryEntry> classPrimaryEntries, boolean includesDeoptTarget, boolean isDeoptTargetCU) {
1288+
private static int findHi(List<PrimaryEntry> classPrimaryEntries, boolean includesDeoptTarget, boolean isDeoptTargetCU) {
12881289
if (isDeoptTargetCU || !includesDeoptTarget) {
12891290
/* Either way the last entry is the one we want. */
1290-
return classPrimaryEntries.getLast().getPrimary().getHi();
1291+
return classPrimaryEntries.get(classPrimaryEntries.size() - 1).getPrimary().getHi();
12911292
} else {
12921293
/* Need the last entry which is not a deopt target. */
12931294
int hi = 0;

0 commit comments

Comments
 (0)