Skip to content

Commit 7f45ae5

Browse files
committed
[GR-68439] GraalWasm code cleanups.
PullRequest: graal/21751
2 parents da1c028 + 427eaab commit 7f45ae5

File tree

9 files changed

+58
-185
lines changed

9 files changed

+58
-185
lines changed

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/GlobalRegistry.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ public GlobalRegistry duplicate() {
192192
other.storeLong(address, value);
193193
other.storeObject(address, objectValue);
194194
}
195-
for (int i = 0; i < externalGlobals.length; i++) {
196-
other.externalGlobals[i] = this.externalGlobals[i];
197-
}
195+
System.arraycopy(this.externalGlobals, 0, other.externalGlobals, 0, externalGlobals.length);
198196
return other;
199197
}
200198

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/Linker.java

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ void resolveMemoryImport(WasmStore store, WasmInstance instance, ImportDescripto
502502
importedModuleName, importedMemoryName, instance.name()));
503503
}
504504
final WasmModule importedModule = importedInstance.module();
505-
if (importedModule.exportedMemories().size() == 0) {
505+
if (importedModule.exportedMemories().isEmpty()) {
506506
throw WasmException.create(Failure.UNKNOWN_IMPORT,
507507
String.format("The imported module '%s' does not export any memories, so cannot resolve memory '%s' imported in module '%s'.",
508508
importedModuleName, importedMemoryName, instance.name()));
@@ -791,7 +791,7 @@ void resolveTableImport(WasmStore store, WasmInstance instance, ImportDescriptor
791791
} else {
792792
final WasmModule importedModule = importedInstance.module();
793793
final String importedTableName = importDescriptor.memberName();
794-
if (importedModule.exportedTables().size() == 0) {
794+
if (importedModule.exportedTables().isEmpty()) {
795795
throw WasmException.create(Failure.UNKNOWN_IMPORT,
796796
String.format("The imported module '%s' does not export any tables, so cannot resolve table '%s' imported in module '%s'.",
797797
importedModuleName, importedTableName, instance.name()));
@@ -1048,10 +1048,9 @@ public int hashCode() {
10481048

10491049
@Override
10501050
public boolean equals(Object object) {
1051-
if (!(object instanceof ExportGlobalSym)) {
1051+
if (!(object instanceof ExportGlobalSym that)) {
10521052
return false;
10531053
}
1054-
final ExportGlobalSym that = (ExportGlobalSym) object;
10551054
return this.moduleName.equals(that.moduleName) && this.globalName.equals(that.globalName);
10561055
}
10571056
}
@@ -1076,10 +1075,9 @@ public int hashCode() {
10761075

10771076
@Override
10781077
public boolean equals(Object object) {
1079-
if (!(object instanceof InitializeGlobalSym)) {
1078+
if (!(object instanceof InitializeGlobalSym that)) {
10801079
return false;
10811080
}
1082-
final InitializeGlobalSym that = (InitializeGlobalSym) object;
10831081
return this.globalIndex == that.globalIndex && this.moduleName.equals(that.moduleName);
10841082
}
10851083
}
@@ -1139,10 +1137,9 @@ public int hashCode() {
11391137

11401138
@Override
11411139
public boolean equals(Object object) {
1142-
if (!(object instanceof ExportFunctionSym)) {
1140+
if (!(object instanceof ExportFunctionSym that)) {
11431141
return false;
11441142
}
1145-
final ExportFunctionSym that = (ExportFunctionSym) object;
11461143
return this.moduleName.equals(that.moduleName) && this.functionName.equals(that.functionName);
11471144
}
11481145
}
@@ -1170,10 +1167,9 @@ public int hashCode() {
11701167

11711168
@Override
11721169
public boolean equals(Object object) {
1173-
if (!(object instanceof ImportMemorySym)) {
1170+
if (!(object instanceof ImportMemorySym that)) {
11741171
return false;
11751172
}
1176-
final ImportMemorySym that = (ImportMemorySym) object;
11771173
return this.moduleName.equals(that.moduleName) && this.importDescriptor.equals(that.importDescriptor) && this.memoryIndex == that.memoryIndex;
11781174
}
11791175
}
@@ -1198,10 +1194,9 @@ public int hashCode() {
11981194

11991195
@Override
12001196
public boolean equals(Object object) {
1201-
if (!(object instanceof ExportMemorySym)) {
1197+
if (!(object instanceof ExportMemorySym that)) {
12021198
return false;
12031199
}
1204-
final ExportMemorySym that = (ExportMemorySym) object;
12051200
return this.moduleName.equals(that.moduleName) && this.memoryName.equals(that.memoryName);
12061201
}
12071202
}
@@ -1226,10 +1221,9 @@ public int hashCode() {
12261221

12271222
@Override
12281223
public boolean equals(Object object) {
1229-
if (!(object instanceof DataSym)) {
1224+
if (!(object instanceof DataSym that)) {
12301225
return false;
12311226
}
1232-
final DataSym that = (DataSym) object;
12331227
return this.dataSegmentId == that.dataSegmentId && this.moduleName.equals(that.moduleName);
12341228
}
12351229
}
@@ -1254,10 +1248,9 @@ public int hashCode() {
12541248

12551249
@Override
12561250
public boolean equals(Object object) {
1257-
if (!(object instanceof ImportTableSym)) {
1251+
if (!(object instanceof ImportTableSym that)) {
12581252
return false;
12591253
}
1260-
final ImportTableSym that = (ImportTableSym) object;
12611254
return this.moduleName.equals(that.moduleName) && this.importDescriptor.equals(that.importDescriptor);
12621255
}
12631256
}
@@ -1282,10 +1275,9 @@ public int hashCode() {
12821275

12831276
@Override
12841277
public boolean equals(Object object) {
1285-
if (!(object instanceof ExportTableSym)) {
1278+
if (!(object instanceof ExportTableSym that)) {
12861279
return false;
12871280
}
1288-
final ExportTableSym that = (ExportTableSym) object;
12891281
return this.moduleName.equals(that.moduleName) && this.tableName.equals(that.tableName);
12901282
}
12911283
}
@@ -1310,10 +1302,9 @@ public int hashCode() {
13101302

13111303
@Override
13121304
public boolean equals(Object object) {
1313-
if (!(object instanceof ElemSym)) {
1305+
if (!(object instanceof ElemSym that)) {
13141306
return false;
13151307
}
1316-
final ElemSym that = (ElemSym) object;
13171308
return this.elemSegmentId == that.elemSegmentId && this.moduleName.equals(that.moduleName);
13181309
}
13191310
}

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/SymbolTable.java

Lines changed: 21 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -149,62 +149,27 @@ public String toString() {
149149
}
150150
}
151151

152-
public static class TableInfo {
153-
/**
154-
* Lower bound on table size.
155-
*/
156-
public final int initialSize;
157-
158-
/**
159-
* Upper bound on table size.
160-
* <p>
161-
* <em>Note:</em> this is the upper bound defined by the module. A table instance might have
162-
* a lower internal max allowed size in practice.
163-
*/
164-
public final int maximumSize;
165-
166-
/**
167-
* The element type of the table.
168-
*/
169-
public final byte elemType;
170-
171-
public TableInfo(int initialSize, int maximumSize, byte elemType) {
172-
this.initialSize = initialSize;
173-
this.maximumSize = maximumSize;
174-
this.elemType = elemType;
175-
}
152+
/**
153+
* @param initialSize Lower bound on table size.
154+
* @param maximumSize Upper bound on table size.
155+
* <p>
156+
* <em>Note:</em> this is the upper bound defined by the module. A table instance
157+
* might have a lower internal max allowed size in practice.
158+
* @param elemType The element type of the table.
159+
*/
160+
public record TableInfo(int initialSize, int maximumSize, byte elemType) {
176161
}
177162

178-
public static class MemoryInfo {
179-
/**
180-
* Lower bound on memory size (in pages of 64 kiB).
181-
*/
182-
public final long initialSize;
183-
184-
/**
185-
* Upper bound on memory size (in pages of 64 kiB).
186-
* <p>
187-
* <em>Note:</em> this is the upper bound defined by the module. A memory instance might
188-
* have a lower internal max allowed size in practice.
189-
*/
190-
public final long maximumSize;
191-
192-
/**
193-
* If the memory uses index type 64.
194-
*/
195-
public final boolean indexType64;
196-
197-
/**
198-
* Whether the memory is shared (modifications are visible to other threads).
199-
*/
200-
public final boolean shared;
201-
202-
public MemoryInfo(long initialSize, long maximumSize, boolean indexType64, boolean shared) {
203-
this.initialSize = initialSize;
204-
this.maximumSize = maximumSize;
205-
this.indexType64 = indexType64;
206-
this.shared = shared;
207-
}
163+
/**
164+
* @param initialSize Lower bound on memory size (in pages of 64 kiB).
165+
* @param maximumSize Upper bound on memory size (in pages of 64 kiB).
166+
* <p>
167+
* <em>Note:</em> this is the upper bound defined by the module. A memory instance
168+
* might have a lower internal max allowed size in practice.
169+
* @param indexType64 If the memory uses index type 64.
170+
* @param shared Whether the memory is shared (modifications are visible to other threads).
171+
*/
172+
public record MemoryInfo(long initialSize, long maximumSize, boolean indexType64, boolean shared) {
208173
}
209174

210175
/**
@@ -985,7 +950,7 @@ void importTable(String moduleName, String tableName, int index, int initSize, i
985950

986951
void addTable(int index, int minSize, int maxSize, byte elemType, boolean referenceTypes) {
987952
if (!referenceTypes) {
988-
assertTrue(importedTables.size() == 0, "A table has already been imported in the module.", Failure.MULTIPLE_TABLES);
953+
assertTrue(importedTables.isEmpty(), "A table has already been imported in the module.", Failure.MULTIPLE_TABLES);
989954
assertTrue(tableCount == 0, "A table has already been declared in the module.", Failure.MULTIPLE_TABLES);
990955
}
991956
ensureTableCapacity(index);
@@ -1089,7 +1054,7 @@ public void importMemory(String moduleName, String memoryName, int index, long i
10891054

10901055
void addMemory(int index, long minSize, long maxSize, boolean indexType64, boolean shared, boolean multiMemory) {
10911056
if (!multiMemory) {
1092-
assertTrue(importedMemories.size() == 0, "A memory has already been imported in the module.", Failure.MULTIPLE_MEMORIES);
1057+
assertTrue(importedMemories.isEmpty(), "A memory has already been imported in the module.", Failure.MULTIPLE_MEMORIES);
10931058
assertTrue(memoryCount == 0, "A memory has already been declared in the module.", Failure.MULTIPLE_MEMORIES);
10941059
}
10951060
ensureMemoryCapacity(index);

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/WasmCustomSection.java

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -42,44 +42,10 @@
4242

4343
/**
4444
* Information about a custom section.
45+
*
46+
* @param name Name of the custom section.
47+
* @param offset Location in the custom sections array.
48+
* @param length Length of the custom section.
4549
*/
46-
public class WasmCustomSection {
47-
/**
48-
* Name of the custom section.
49-
*/
50-
private final String name;
51-
52-
/**
53-
* Location in the custom sections array.
54-
*/
55-
private final int offset;
56-
57-
/**
58-
* Length of the custom section.
59-
*/
60-
private final int length;
61-
62-
public WasmCustomSection(String name, int offset, int length) {
63-
this.name = name;
64-
this.offset = offset;
65-
this.length = length;
66-
}
67-
68-
/**
69-
* Returns the name of the custom section.
70-
*
71-
* @return name of the custom section.
72-
*/
73-
public String name() {
74-
return name;
75-
}
76-
77-
public int offset() {
78-
return offset;
79-
}
80-
81-
public int length() {
82-
return length;
83-
}
84-
50+
public record WasmCustomSection(String name, int offset, int length) {
8551
}

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/api/Vector128OpsFallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ private static byte[] i64x2_relop(byte[] vecX, byte[] vecY, int vectorOpcode) {
568568
case Bytecode.VECTOR_I64X2_LE_S -> x <= y;
569569
case Bytecode.VECTOR_I64X2_GE_S -> x >= y;
570570
default -> throw CompilerDirectives.shouldNotReachHere();
571-
} ? 0xffff_ffff_ffff_ffffL : 0x0000_0000_0000_0000l;
571+
} ? 0xffff_ffff_ffff_ffffL : 0x0000_0000_0000_0000L;
572572
byteArraySupport.putLong(vecResult, i * Long.BYTES, result);
573573
}
574574
return vecResult;

0 commit comments

Comments
 (0)