Skip to content

Commit

Permalink
FINALLY is no longer implemented with JSR-RET. (Java 6+ .class files …
Browse files Browse the repository at this point in the history
…forbid JSR and RET). Another step towards Java 7+ .class files!
  • Loading branch information
aunkrig committed Feb 21, 2020
1 parent 7ef04fc commit 354abed
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 223 deletions.
5 changes: 3 additions & 2 deletions janino/src/main/java/org/codehaus/janino/CodeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ class Branch extends Relocatable {
}
int offset = this.destination.offset - this.source.offset;

@SuppressWarnings("deprecation") final int opcodeJsr = Opcode.JSR;
if (!this.expanded && (offset > Short.MAX_VALUE || offset < Short.MIN_VALUE)) {
//we want to insert the data without skewing our source position,
//so we will cache it and then restore it later.
Expand All @@ -637,7 +638,7 @@ class Branch extends Relocatable {
{
// Promotion to a wide instruction only requires 2 extra bytes. Everything else requires a new
// GOTO_W instruction after a negated if (5 extra bytes).
CodeContext.this.makeSpace(this.opcode == Opcode.GOTO || this.opcode == Opcode.JSR ? 2 : 5);
CodeContext.this.makeSpace(this.opcode == Opcode.GOTO || this.opcode == opcodeJsr ? 2 : 5);
}
CodeContext.this.popInserter();
this.source.offset = pos;
Expand All @@ -650,7 +651,7 @@ class Branch extends Relocatable {
//we fit in a 16-bit jump
ba = new byte[] { (byte) this.opcode, (byte) (offset >> 8), (byte) offset };
} else {
if (this.opcode == Opcode.GOTO || this.opcode == Opcode.JSR) {
if (this.opcode == Opcode.GOTO || this.opcode == opcodeJsr) {
ba = new byte[] {
(byte) (this.opcode + 33), // GOTO => GOTO_W; JSR => JSR_W
(byte) (offset >> 24),
Expand Down
6 changes: 0 additions & 6 deletions janino/src/main/java/org/codehaus/janino/Java.java
Original file line number Diff line number Diff line change
Expand Up @@ -3565,12 +3565,6 @@ class VariableAccessResource extends Resource {

@Override @Nullable public <R, EX extends Throwable> R
accept(Visitor.BlockStatementVisitor<R, EX> visitor) throws EX { return visitor.visitTryStatement(this); }

/**
* This one's created iff the TRY statement has a FINALLY clause when the compilation of the TRY statement
* begins.
*/
@Nullable CodeContext.Offset finallyOffset;
}

/**
Expand Down
16 changes: 13 additions & 3 deletions janino/src/main/java/org/codehaus/janino/Opcode.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private Opcode() {}

// Symbolic JVM opcodes, in alphabetical order.

// SUPPRESS CHECKSTYLE JavadocVariable:205
// SUPPRESS CHECKSTYLE JavadocVariable:216
public static final int AALOAD = 50;
public static final int AASTORE = 83;
public static final int ACONST_NULL = 1;
Expand Down Expand Up @@ -186,7 +186,12 @@ private Opcode() {}
public static final int ISUB = 100;
public static final int IUSHR = 124;
public static final int IXOR = 130;
public static final int JSR = 168;

/**
* @deprecated Only allowed until .class file version 50.0 (Java 6) JVMS 4.10.2.5
*/
@Deprecated public static final int JSR = 168;

public static final int JSR_W = 201;
public static final int L2D = 138;
public static final int L2F = 137;
Expand Down Expand Up @@ -233,7 +238,12 @@ private Opcode() {}
public static final int POP2 = 88;
public static final int PUTFIELD = 181;
public static final int PUTSTATIC = 179;
public static final int RET = 169;

/**
* @deprecated Only allowed until .class file version 50.0 (Java 6) JVMS 4.10.2.5
*/
@Deprecated public static final int RET = 169;

public static final int RETURN = 177;
public static final int SALOAD = 53;
public static final int SASTORE = 86;
Expand Down
Loading

0 comments on commit 354abed

Please sign in to comment.