From d3a2da86ba78c764eb7e4799c50871b182929d40 Mon Sep 17 00:00:00 2001 From: "igor%mir2.org" Date: Wed, 25 Aug 2004 17:22:02 +0000 Subject: [PATCH] Fixing bug 256865: changing ByteCode constants to int from byte so switches over them would not crash widely installed versions of GCJ like GCJ 3.3.*. --- .../src/org/mozilla/classfile/ByteCode.java | 154 +++++++++--------- .../mozilla/classfile/ClassFileWriter.java | 59 +++---- .../mozilla/javascript/optimizer/Codegen.java | 14 +- 3 files changed, 109 insertions(+), 118 deletions(-) diff --git a/js/rhino/src/org/mozilla/classfile/ByteCode.java b/js/rhino/src/org/mozilla/classfile/ByteCode.java index 790adc11f935..e7bee3bb25e9 100644 --- a/js/rhino/src/org/mozilla/classfile/ByteCode.java +++ b/js/rhino/src/org/mozilla/classfile/ByteCode.java @@ -47,7 +47,7 @@ public class ByteCode { /** * The byte opcodes defined by the Java Virtual Machine. */ - public static final byte + public static final int NOP = 0x00, ACONST_NULL = 0x01, ICONST_M1 = 0x02, @@ -176,83 +176,83 @@ public class ByteCode { LUSHR = 0x7D, IAND = 0x7E, LAND = 0x7F, - IOR = (byte)0x80, - LOR = (byte)0x81, - IXOR = (byte)0x82, - LXOR = (byte)0x83, - IINC = (byte)0x84, - I2L = (byte)0x85, - I2F = (byte)0x86, - I2D = (byte)0x87, - L2I = (byte)0x88, - L2F = (byte)0x89, - L2D = (byte)0x8A, - F2I = (byte)0x8B, - F2L = (byte)0x8C, - F2D = (byte)0x8D, - D2I = (byte)0x8E, - D2L = (byte)0x8F, - D2F = (byte)0x90, - I2B = (byte)0x91, - I2C = (byte)0x92, - I2S = (byte)0x93, - LCMP = (byte)0x94, - FCMPL = (byte)0x95, - FCMPG = (byte)0x96, - DCMPL = (byte)0x97, - DCMPG = (byte)0x98, - IFEQ = (byte)0x99, - IFNE = (byte)0x9A, - IFLT = (byte)0x9B, - IFGE = (byte)0x9C, - IFGT = (byte)0x9D, - IFLE = (byte)0x9E, - IF_ICMPEQ = (byte)0x9F, - IF_ICMPNE = (byte)0xA0, - IF_ICMPLT = (byte)0xA1, - IF_ICMPGE = (byte)0xA2, - IF_ICMPGT = (byte)0xA3, - IF_ICMPLE = (byte)0xA4, - IF_ACMPEQ = (byte)0xA5, - IF_ACMPNE = (byte)0xA6, - GOTO = (byte)0xA7, - JSR = (byte)0xA8, - RET = (byte)0xA9, - TABLESWITCH = (byte)0xAA, - LOOKUPSWITCH = (byte)0xAB, - IRETURN = (byte)0xAC, - LRETURN = (byte)0xAD, - FRETURN = (byte)0xAE, - DRETURN = (byte)0xAF, - ARETURN = (byte)0xB0, - RETURN = (byte)0xB1, - GETSTATIC = (byte)0xB2, - PUTSTATIC = (byte)0xB3, - GETFIELD = (byte)0xB4, - PUTFIELD = (byte)0xB5, - INVOKEVIRTUAL = (byte)0xB6, - INVOKESPECIAL = (byte)0xB7, - INVOKESTATIC = (byte)0xB8, - INVOKEINTERFACE = (byte)0xB9, - NEW = (byte)0xBB, - NEWARRAY = (byte)0xBC, - ANEWARRAY = (byte)0xBD, - ARRAYLENGTH = (byte)0xBE, - ATHROW = (byte)0xBF, - CHECKCAST = (byte)0xC0, - INSTANCEOF = (byte)0xC1, - MONITORENTER = (byte)0xC2, - MONITOREXIT = (byte)0xC3, - WIDE = (byte)0xC4, - MULTIANEWARRAY = (byte)0xC5, - IFNULL = (byte)0xC6, - IFNONNULL = (byte)0xC7, - GOTO_W = (byte)0xC8, - JSR_W = (byte)0xC9, - BREAKPOINT = (byte)0xCA, + IOR = 0x80, + LOR = 0x81, + IXOR = 0x82, + LXOR = 0x83, + IINC = 0x84, + I2L = 0x85, + I2F = 0x86, + I2D = 0x87, + L2I = 0x88, + L2F = 0x89, + L2D = 0x8A, + F2I = 0x8B, + F2L = 0x8C, + F2D = 0x8D, + D2I = 0x8E, + D2L = 0x8F, + D2F = 0x90, + I2B = 0x91, + I2C = 0x92, + I2S = 0x93, + LCMP = 0x94, + FCMPL = 0x95, + FCMPG = 0x96, + DCMPL = 0x97, + DCMPG = 0x98, + IFEQ = 0x99, + IFNE = 0x9A, + IFLT = 0x9B, + IFGE = 0x9C, + IFGT = 0x9D, + IFLE = 0x9E, + IF_ICMPEQ = 0x9F, + IF_ICMPNE = 0xA0, + IF_ICMPLT = 0xA1, + IF_ICMPGE = 0xA2, + IF_ICMPGT = 0xA3, + IF_ICMPLE = 0xA4, + IF_ACMPEQ = 0xA5, + IF_ACMPNE = 0xA6, + GOTO = 0xA7, + JSR = 0xA8, + RET = 0xA9, + TABLESWITCH = 0xAA, + LOOKUPSWITCH = 0xAB, + IRETURN = 0xAC, + LRETURN = 0xAD, + FRETURN = 0xAE, + DRETURN = 0xAF, + ARETURN = 0xB0, + RETURN = 0xB1, + GETSTATIC = 0xB2, + PUTSTATIC = 0xB3, + GETFIELD = 0xB4, + PUTFIELD = 0xB5, + INVOKEVIRTUAL = 0xB6, + INVOKESPECIAL = 0xB7, + INVOKESTATIC = 0xB8, + INVOKEINTERFACE = 0xB9, + NEW = 0xBB, + NEWARRAY = 0xBC, + ANEWARRAY = 0xBD, + ARRAYLENGTH = 0xBE, + ATHROW = 0xBF, + CHECKCAST = 0xC0, + INSTANCEOF = 0xC1, + MONITORENTER = 0xC2, + MONITOREXIT = 0xC3, + WIDE = 0xC4, + MULTIANEWARRAY = 0xC5, + IFNULL = 0xC6, + IFNONNULL = 0xC7, + GOTO_W = 0xC8, + JSR_W = 0xC9, + BREAKPOINT = 0xCA, - IMPDEP1 = (byte)0xFE, - IMPDEP2 = (byte)0xFF; + IMPDEP1 = 0xFE, + IMPDEP2 = 0xFF; /** * Types for the NEWARRAY opcode. diff --git a/js/rhino/src/org/mozilla/classfile/ClassFileWriter.java b/js/rhino/src/org/mozilla/classfile/ClassFileWriter.java index e261d0c21474..bd1a82a774d3 100644 --- a/js/rhino/src/org/mozilla/classfile/ClassFileWriter.java +++ b/js/rhino/src/org/mozilla/classfile/ClassFileWriter.java @@ -322,7 +322,7 @@ public class ClassFileWriter { lineNumberTableLength + variableTableLength; - byte codeAttribute[] = new byte[attrLength]; + byte[] codeAttribute = new byte[attrLength]; int index = 0; int codeAttrIndex = itsConstantPool.addUtf8("Code"); index = putInt16(codeAttrIndex, codeAttribute, index); @@ -425,7 +425,7 @@ public class ClassFileWriter { * * @param theOpCode the opcode of the bytecode */ - public void add(byte theOpCode) { + public void add(int theOpCode) { if (opcodeCount(theOpCode) != 0) throw new IllegalArgumentException("Unexpected operands"); int newStack = itsStackTop + stackChange(theOpCode); @@ -447,7 +447,7 @@ public class ClassFileWriter { * @param theOpCode the opcode of the bytecode * @param theOperand the operand of the bytecode */ - public void add(byte theOpCode, int theOperand) { + public void add(int theOpCode, int theOperand) { if (DEBUGCODE) { System.out.println("Add "+bytecodeStr(theOpCode) +", "+Integer.toHexString(theOperand)); @@ -524,7 +524,7 @@ public class ClassFileWriter { if (!(0 <= theOperand && theOperand < 256)) throw new IllegalArgumentException("out of range index"); addToCodeBuffer(theOpCode); - addToCodeBuffer((byte)theOperand); + addToCodeBuffer(theOperand); break; case ByteCode.GETFIELD : @@ -552,7 +552,7 @@ public class ClassFileWriter { addToCodeInt16(theOperand); } else { addToCodeBuffer(theOpCode); - addToCodeBuffer((byte)theOperand); + addToCodeBuffer(theOperand); } break; @@ -576,7 +576,7 @@ public class ClassFileWriter { } else { addToCodeBuffer(theOpCode); - addToCodeBuffer((byte)theOperand); + addToCodeBuffer(theOperand); } break; @@ -645,7 +645,7 @@ public class ClassFileWriter { * @param theOperand1 the first operand of the bytecode * @param theOperand2 the second operand of the bytecode */ - public void add(byte theOpCode, int theOperand1, int theOperand2) { + public void add(int theOpCode, int theOperand1, int theOperand2) { if (DEBUGCODE) { System.out.println("Add "+bytecodeStr(theOpCode) +", "+Integer.toHexString(theOperand1) @@ -669,8 +669,8 @@ public class ClassFileWriter { else { addToCodeBuffer(ByteCode.WIDE); addToCodeBuffer(ByteCode.IINC); - addToCodeBuffer((byte)theOperand1); - addToCodeBuffer((byte)theOperand2); + addToCodeBuffer(theOperand1); + addToCodeBuffer(theOperand2); } } else if (theOpCode == ByteCode.MULTIANEWARRAY) { @@ -681,7 +681,7 @@ public class ClassFileWriter { addToCodeBuffer(ByteCode.MULTIANEWARRAY); addToCodeInt16(theOperand1); - addToCodeBuffer((byte)theOperand2); + addToCodeBuffer(theOperand2); } else { throw new IllegalArgumentException( @@ -696,7 +696,7 @@ public class ClassFileWriter { } - public void add(byte theOpCode, String className) { + public void add(int theOpCode, String className) { if (DEBUGCODE) { System.out.println("Add "+bytecodeStr(theOpCode) +", "+className); @@ -727,7 +727,7 @@ public class ClassFileWriter { } - public void add(byte theOpCode, String className, String fieldName, + public void add(int theOpCode, String className, String fieldName, String fieldType) { if (DEBUGCODE) { @@ -765,16 +765,7 @@ public class ClassFileWriter { } } - /** - * @deprecated Use {@link #addInvoke} instead - */ - public void add(byte theOpCode, String className, String methodName, - String parametersType, String returnType) - { - addInvoke(theOpCode, className, methodName, parametersType+returnType); - } - - public void addInvoke(byte theOpCode, String className, String methodName, + public void addInvoke(int theOpCode, String className, String methodName, String methodType) { if (DEBUGCODE) { @@ -802,8 +793,8 @@ public class ClassFileWriter { className, methodName, methodType); addToCodeInt16(ifMethodRefIndex); - addToCodeBuffer((byte)(parameterCount + 1)); - addToCodeBuffer((byte)0); + addToCodeBuffer(parameterCount + 1); + addToCodeBuffer(0); } else { short methodRefIndex = itsConstantPool.addMethodRef( @@ -1054,20 +1045,20 @@ public class ClassFileWriter { add(ByteCode.ALOAD_0); } - private void xop(byte shortOp, byte op, int local) + private void xop(int shortOp, int op, int local) { switch (local) { case 0: add(shortOp); break; case 1: - add((byte)(shortOp + 1)); + add(shortOp + 1); break; case 2: - add((byte)(shortOp + 2)); + add(shortOp + 2); break; case 3: - add((byte)(shortOp + 3)); + add(shortOp + 3); break; default: add(op, local); @@ -1091,7 +1082,7 @@ public class ClassFileWriter { int N = addReservedCodeSpace(1 + padSize + 4 * (1 + 2 + entryCount)); int switchStart = N; - itsCodeBuffer[N++] = ByteCode.TABLESWITCH; + itsCodeBuffer[N++] = (byte)ByteCode.TABLESWITCH; while (padSize != 0) { itsCodeBuffer[N++] = 0; --padSize; @@ -1152,7 +1143,7 @@ public class ClassFileWriter { switchStart+" is outside a possible range of tableswitch" +" in already generated code"); } - if (!(itsCodeBuffer[switchStart] == ByteCode.TABLESWITCH)) { + if ((0xFF & itsCodeBuffer[switchStart]) != ByteCode.TABLESWITCH) { throw new IllegalArgumentException( switchStart+" is not offset of tableswitch statement"); } @@ -1289,10 +1280,10 @@ public class ClassFileWriter { } } - private void addToCodeBuffer(byte b) + private void addToCodeBuffer(int b) { int N = addReservedCodeSpace(1); - itsCodeBuffer[N] = b; + itsCodeBuffer[N] = (byte)b; } private void addToCodeInt16(int value) @@ -2292,7 +2283,7 @@ public class ClassFileWriter { throw new IllegalArgumentException("Bad opcode: "+opcode); } */ - private static String bytecodeStr(byte code) + private static String bytecodeStr(int code) { if (DEBUGSTACK || DEBUGCODE) { switch (code) { @@ -2534,7 +2525,7 @@ public class ClassFileWriter { private int itsLineNumberTable[]; // pack start_pc & line_number together private int itsLineNumberTableTop; - private byte itsCodeBuffer[] = new byte[256]; + private byte[] itsCodeBuffer = new byte[256]; private int itsCodeBufferTop; private ConstantPool itsConstantPool; diff --git a/js/rhino/src/org/mozilla/javascript/optimizer/Codegen.java b/js/rhino/src/org/mozilla/javascript/optimizer/Codegen.java index a691b0e176db..072755663388 100644 --- a/js/rhino/src/org/mozilla/javascript/optimizer/Codegen.java +++ b/js/rhino/src/org/mozilla/javascript/optimizer/Codegen.java @@ -566,9 +566,9 @@ public class Codegen extends Interpreter private void generateFunctionConstructor(ClassFileWriter cfw) { - final byte SCOPE_ARG = 1; - final byte CONTEXT_ARG = 2; - final byte ID_ARG = 3; + final int SCOPE_ARG = 1; + final int CONTEXT_ARG = 2; + final int ID_ARG = 3; cfw.startMethod("", FUNCTION_CONSTRUCTOR_SIGNATURE, ClassFileWriter.ACC_PUBLIC); @@ -3089,7 +3089,7 @@ Else pass the JS object in the aReg and 0.0 in the dReg. || (type == Token.MUL); } - private void visitArithmetic(Node node, byte opCode, Node child, + private void visitArithmetic(Node node, int opCode, Node child, Node parent) { int childNumberFlag = node.getIntProp(Node.ISNUMBER_PROP, -1); @@ -3339,7 +3339,7 @@ Else pass the JS object in the aReg and 0.0 in the dReg. } generateExpression(child, node); if (type == Token.SHEQ || type == Token.SHNE) { - byte testCode = (type == Token.SHEQ) + int testCode = (type == Token.SHEQ) ? ByteCode.IFNULL : ByteCode.IFNONNULL; cfw.add(testCode, trueGOTO); } else { @@ -3392,7 +3392,7 @@ Else pass the JS object in the aReg and 0.0 in the dReg. generateExpression(rChild, node); String name; - byte testCode; + int testCode; switch (type) { case Token.EQ: name = "eq"; @@ -3892,7 +3892,7 @@ Else pass the JS object in the aReg and 0.0 in the dReg. cfw.markLabel(beyond); } - private void addGoto(Node.Target target, byte jumpcode) + private void addGoto(Node.Target target, int jumpcode) { int targetLabel = getTargetLabel(target); cfw.add(jumpcode, targetLabel);