Skip to content

Commit aae0f17

Browse files
committed
Minor fixes
1 parent bebfde0 commit aae0f17

File tree

7 files changed

+14
-54
lines changed

7 files changed

+14
-54
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group 'dev.xdark'
7-
version '1.9.0'
7+
version '1.9.0.1'
88

99
repositories {
1010
mavenCentral()

src/main/java/dev/xdark/ssvm/execution/Locals.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ public interface Locals {
4848
* Copies contents into this locals.
4949
*
5050
* @param locals Content to copy.
51-
* @param offset Content offset.
51+
* @param srcOffset Content srcOffset.
52+
* @param destOffset Offset to copy to.
5253
* @param length Content length.
5354
*/
54-
void copyFrom(Value[] locals, int offset, int length);
55+
void copyFrom(Value[] locals, int srcOffset, int destOffset, int length);
5556

5657
/**
5758
* @return underlying content of this LVT.

src/main/java/dev/xdark/ssvm/execution/Stack.java

-16
Original file line numberDiff line numberDiff line change
@@ -307,20 +307,4 @@ default boolean isEmpty() {
307307
* @param count Locals count.
308308
*/
309309
void sinkInto(Locals locals, int count);
310-
311-
/**
312-
* Copies contents into this stack.
313-
*
314-
* @param stack Content to copy.
315-
*/
316-
void copyFrom(Value[] stack);
317-
318-
/**
319-
* Copies contents into this stack.
320-
*
321-
* @param stack Content to copy.
322-
* @param offset Content offset.
323-
* @param length Content length.
324-
*/
325-
void copyFrom(Value[] stack, int offset, int length);
326310
}

src/main/java/dev/xdark/ssvm/execution/ThreadLocals.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public void copyFrom(Locals locals, int srcOffset, int destOffset, int length) {
5757
}
5858
return;
5959
}
60+
destOffset = table.map(destOffset);
6061
Value[] array = table.getArray();
6162
if ((!(locals instanceof ThreadLocals))) {
6263
Value[] from = locals.getTable();
@@ -68,15 +69,16 @@ public void copyFrom(Locals locals, int srcOffset, int destOffset, int length) {
6869
}
6970

7071
@Override
71-
public void copyFrom(Value[] locals, int offset, int length) {
72+
public void copyFrom(Value[] locals, int srcOffset, int destOffset, int length) {
7273
ThreadRegion table = this.table;
7374
if (table.length() == 0) {
7475
if (length != 0) {
7576
throw new IllegalStateException();
7677
}
7778
return;
7879
}
79-
System.arraycopy(locals, offset, table.getArray(), table.map(0), length);
80+
Value[] array = table.getArray();
81+
System.arraycopy(locals, srcOffset, array, table.map(destOffset), length);
8082
}
8183

8284
@Override

src/main/java/dev/xdark/ssvm/execution/ThreadStack.java

+1-28
Original file line numberDiff line numberDiff line change
@@ -151,37 +151,10 @@ public void sinkInto(Locals locals, int count) {
151151
}
152152
ThreadRegion stack = this.stack;
153153
int start = cursor - count;
154-
locals.copyFrom(stack.getArray(), stack.map(start), count);
154+
locals.copyFrom(stack.getArray(), stack.map(start), 0, count);
155155
cursor = start;
156156
}
157157

158-
@Override
159-
public void copyFrom(Value[] locals) {
160-
ThreadRegion stack = this.stack;
161-
if (stack.length() == 0) {
162-
if (locals.length != 0) {
163-
throw new IllegalStateException();
164-
}
165-
return;
166-
}
167-
Value[] array = stack.getArray();
168-
System.arraycopy(locals, 0, array, stack.map(0), locals.length);
169-
cursor += locals.length;
170-
}
171-
172-
@Override
173-
public void copyFrom(Value[] locals, int offset, int length) {
174-
ThreadRegion stack = this.stack;
175-
if (stack.length() == 0) {
176-
if (length != 0) {
177-
throw new IllegalStateException();
178-
}
179-
return;
180-
}
181-
System.arraycopy(locals, offset, stack.getArray(), stack.map(0), length);
182-
cursor += length;
183-
}
184-
185158
@Override
186159
public void dispose() {
187160
stack.dispose();

src/main/java/dev/xdark/ssvm/jit/JitHelper.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ public Value invokeStatic(Value[] locals, String owner, String name, String desc
404404
VMHelper helper = vm.getHelper();
405405
JavaMethod mn = resolveStaticMethod(owner, name, desc, ctx);
406406
Locals table = vm.getThreadStorage().newLocals(mn);
407-
table.copyFrom(locals, 0, locals.length);
407+
table.copyFrom(locals, 0, 0, locals.length);
408408
ExecutionContext result = helper.invoke(mn, table);
409409
return result.getResult();
410410
}
@@ -414,7 +414,7 @@ public Value invokeVirtual(Value[] locals, String name, String desc, ExecutionCo
414414
VMHelper helper = vm.getHelper();
415415
JavaMethod method = vm.getLinkResolver().resolveInterfaceMethod(helper.checkNotNull(locals[0]), name, desc, true);
416416
Locals table = vm.getThreadStorage().newLocals(method);
417-
table.copyFrom(locals, 0, locals.length);
417+
table.copyFrom(locals, 0, 0, locals.length);
418418
ExecutionContext result = helper.invoke(method, table);
419419
return result.getResult();
420420
}
@@ -425,7 +425,7 @@ public Value invokeInterface(Value[] locals, String owner, String name, String d
425425
InstanceJavaClass klass = (InstanceJavaClass) helper.tryFindClass(ctx.getOwner().getClassLoader(), owner, true);
426426
JavaMethod method = vm.getLinkResolver().resolveVirtualMethod(helper.checkNotNull(locals[0]).getJavaClass(), klass, name, desc);
427427
Locals table = vm.getThreadStorage().newLocals(method);
428-
table.copyFrom(locals, 0, locals.length);
428+
table.copyFrom(locals, 0, 0, locals.length);
429429
ExecutionContext result = helper.invoke(method, table);
430430
return result.getResult();
431431
}

src/main/java/dev/xdark/ssvm/natives/MethodHandleNatives.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public void init(VirtualMachine vm) {
149149
}
150150
}
151151
Locals table = vm.getThreadStorage().newLocals(vmtarget);
152-
table.copyFrom(lvt, 0, lvt.length);
152+
table.copyFrom(lvt, 0, 0, lvt.length);
153153
Value result = helper.invoke(vmtarget, table).getResult();
154154
ctx.setResult(result);
155155
return Result.ABORT;
@@ -178,7 +178,7 @@ public void init(VirtualMachine vm) {
178178
}
179179
}
180180
Locals newLocals = vm.getThreadStorage().newLocals(vmtarget.getMaxLocals());
181-
newLocals.copyFrom(table, 0, table.length - 1);
181+
newLocals.copyFrom(table, 0, 0, table.length - 1);
182182
Value result = helper.invoke(vmtarget, newLocals).getResult();
183183

184184
ctx.setResult(result);

0 commit comments

Comments
 (0)