Skip to content

Commit

Permalink
feat(objectionary#540): repair several unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Oct 7, 2024
1 parent a08e074 commit 029d4da
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -430,21 +430,23 @@ public int stack() {
// Invoke method instructions
case INVOKEVIRTUAL:
case INVOKESPECIAL:
case INVOKEINTERFACE:
case INVOKESTATIC:
// Stack change depends on method descriptor
// Net stack change: -args + return value(s)
// For example:
// int argsSize = getArgumentsSize(methodDescriptor);
// int returnSize = getReturnSize(methodDescriptor);
// return -argsSize + returnSize;
// For now, we'll return 0 as a placeholder
return 0;

case INVOKEDYNAMIC:
// Similar to invoke methods
case INVOKEINTERFACE: {
final String descr = String.valueOf(this.args.get(2));
final Type ret = Type.getReturnType(descr);
final Type[] types = Type.getArgumentTypes(descr);
final int args = Arrays.stream(types).mapToInt(this::typeSize).sum();
return this.typeSize(ret) - 1 - args;
}
case INVOKESTATIC: {
final String descr = String.valueOf(this.args.get(2));
final Type ret = Type.getReturnType(descr);
final Type[] types = Type.getArgumentTypes(descr);
final int args = Arrays.stream(types).mapToInt(this::typeSize).sum();
return this.typeSize(ret) - args;
}
case INVOKEDYNAMIC: {
return 0;

}
// New object
case NEW:
return 1;
Expand Down Expand Up @@ -484,6 +486,15 @@ public int stack() {
}
}

private int typeSize(final Type type) {
if (type == Type.DOUBLE_TYPE || type == Type.LONG_TYPE) {
return 2;
} else if (type == Type.VOID_TYPE) {
return 0;
}
return 1;
}


/**
* Bytecode Instruction.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ void write(final CustomClassWriter visitor) {
this.tryblocks.forEach(block -> block.writeTo(mvisitor));
this.instructions.forEach(instruction -> instruction.writeTo(mvisitor));
// mvisitor.visitMaxs(this.maxs.stack(), this.maxs.locals());
mvisitor.visitMaxs(computeStack(), computeLocals());
mvisitor.visitMaxs(this.computeStack(), this.computeLocals());
}
mvisitor.visitEnd();
} catch (final NegativeArraySizeException exception) {
Expand Down

0 comments on commit 029d4da

Please sign in to comment.