< prev index next >

src/java.base/share/classes/jdk/internal/org/objectweb/asm/MethodWriter.java

Print this page




2044         } else {
2045             stackMap.putByte(8).putShort(((Label) type).position);
2046         }
2047     }
2048 
2049     // ------------------------------------------------------------------------
2050     // Utility methods: dump bytecode array
2051     // ------------------------------------------------------------------------
2052 
2053     /**
2054      * Returns the size of the bytecode of this method.
2055      *
2056      * @return the size of the bytecode of this method.
2057      */
2058     final int getSize() {
2059         if (classReaderOffset != 0) {
2060             return 6 + classReaderLength;
2061         }
2062         int size = 8;
2063         if (code.length > 0) {
2064             if (code.length > 65536) {
2065                 throw new RuntimeException("Method code too large!");
2066             }
2067             cw.newUTF8("Code");
2068             size += 18 + code.length + 8 * handlerCount;
2069             if (localVar != null) {
2070                 cw.newUTF8("LocalVariableTable");
2071                 size += 8 + localVar.length;
2072             }
2073             if (localVarType != null) {
2074                 cw.newUTF8("LocalVariableTypeTable");
2075                 size += 8 + localVarType.length;
2076             }
2077             if (lineNumber != null) {
2078                 cw.newUTF8("LineNumberTable");
2079                 size += 8 + lineNumber.length;
2080             }
2081             if (stackMap != null) {
2082                 boolean zip = (cw.version & 0xFFFF) >= Opcodes.V1_6;
2083                 cw.newUTF8(zip ? "StackMapTable" : "StackMap");
2084                 size += 8 + stackMap.length;


2718         // updates the stack map frame labels
2719         if (compute == FRAMES) {
2720             Label l = labels;
2721             while (l != null) {
2722                 /*
2723                  * Detects the labels that are just after an IF instruction that
2724                  * has been resized with the IFNOT GOTO_W pattern. These labels
2725                  * are now the target of a jump instruction (the IFNOT
2726                  * instruction). Note that we need the original label position
2727                  * here. getNewOffset must therefore never have been called for
2728                  * this label.
2729                  */
2730                 u = l.position - 3;
2731                 if (u >= 0 && resize[u]) {
2732                     l.status |= Label.TARGET;
2733                 }
2734                 getNewOffset(allIndexes, allSizes, l);
2735                 l = l.successor;
2736             }
2737             // Update the offsets in the uninitialized types

2738             for (i = 0; i < cw.typeTable.length; ++i) {
2739                 Item item = cw.typeTable[i];
2740                 if (item != null && item.type == ClassWriter.TYPE_UNINIT) {
2741                     item.intVal = getNewOffset(allIndexes, allSizes, 0,
2742                             item.intVal);
2743                 }
2744             }

2745             // The stack map frames are not serialized yet, so we don't need
2746             // to update them. They will be serialized in visitMaxs.
2747         } else if (frameCount > 0) {
2748             /*
2749              * Resizing an existing stack map frame table is really hard. Not
2750              * only the table must be parsed to update the offets, but new
2751              * frames may be needed for jump instructions that were inserted by
2752              * this method. And updating the offsets or inserting frames can
2753              * change the format of the following frames, in case of packed
2754              * frames. In practice the whole table must be recomputed. For this
2755              * the frames are marked as potentially invalid. This will cause the
2756              * whole class to be reread and rewritten with the COMPUTE_FRAMES
2757              * option (see the ClassWriter.toByteArray method). This is not very
2758              * efficient but is much easier and requires much less code than any
2759              * other method I can think of.
2760              */
2761             cw.invalidFrames = true;
2762         }
2763         // updates the exception handler block labels
2764         Handler h = firstHandler;




2044         } else {
2045             stackMap.putByte(8).putShort(((Label) type).position);
2046         }
2047     }
2048 
2049     // ------------------------------------------------------------------------
2050     // Utility methods: dump bytecode array
2051     // ------------------------------------------------------------------------
2052 
2053     /**
2054      * Returns the size of the bytecode of this method.
2055      *
2056      * @return the size of the bytecode of this method.
2057      */
2058     final int getSize() {
2059         if (classReaderOffset != 0) {
2060             return 6 + classReaderLength;
2061         }
2062         int size = 8;
2063         if (code.length > 0) {
2064             if (code.length > 65535) {
2065                 throw new RuntimeException("Method code too large!");
2066             }
2067             cw.newUTF8("Code");
2068             size += 18 + code.length + 8 * handlerCount;
2069             if (localVar != null) {
2070                 cw.newUTF8("LocalVariableTable");
2071                 size += 8 + localVar.length;
2072             }
2073             if (localVarType != null) {
2074                 cw.newUTF8("LocalVariableTypeTable");
2075                 size += 8 + localVarType.length;
2076             }
2077             if (lineNumber != null) {
2078                 cw.newUTF8("LineNumberTable");
2079                 size += 8 + lineNumber.length;
2080             }
2081             if (stackMap != null) {
2082                 boolean zip = (cw.version & 0xFFFF) >= Opcodes.V1_6;
2083                 cw.newUTF8(zip ? "StackMapTable" : "StackMap");
2084                 size += 8 + stackMap.length;


2718         // updates the stack map frame labels
2719         if (compute == FRAMES) {
2720             Label l = labels;
2721             while (l != null) {
2722                 /*
2723                  * Detects the labels that are just after an IF instruction that
2724                  * has been resized with the IFNOT GOTO_W pattern. These labels
2725                  * are now the target of a jump instruction (the IFNOT
2726                  * instruction). Note that we need the original label position
2727                  * here. getNewOffset must therefore never have been called for
2728                  * this label.
2729                  */
2730                 u = l.position - 3;
2731                 if (u >= 0 && resize[u]) {
2732                     l.status |= Label.TARGET;
2733                 }
2734                 getNewOffset(allIndexes, allSizes, l);
2735                 l = l.successor;
2736             }
2737             // Update the offsets in the uninitialized types
2738             if (cw.typeTable != null) {
2739                 for (i = 0; i < cw.typeTable.length; ++i) {
2740                     Item item = cw.typeTable[i];
2741                     if (item != null && item.type == ClassWriter.TYPE_UNINIT) {
2742                         item.intVal = getNewOffset(allIndexes, allSizes, 0,
2743                                 item.intVal);
2744                     }
2745                 }
2746             }
2747             // The stack map frames are not serialized yet, so we don't need
2748             // to update them. They will be serialized in visitMaxs.
2749         } else if (frameCount > 0) {
2750             /*
2751              * Resizing an existing stack map frame table is really hard. Not
2752              * only the table must be parsed to update the offets, but new
2753              * frames may be needed for jump instructions that were inserted by
2754              * this method. And updating the offsets or inserting frames can
2755              * change the format of the following frames, in case of packed
2756              * frames. In practice the whole table must be recomputed. For this
2757              * the frames are marked as potentially invalid. This will cause the
2758              * whole class to be reread and rewritten with the COMPUTE_FRAMES
2759              * option (see the ClassWriter.toByteArray method). This is not very
2760              * efficient but is much easier and requires much less code than any
2761              * other method I can think of.
2762              */
2763             cw.invalidFrames = true;
2764         }
2765         // updates the exception handler block labels
2766         Handler h = firstHandler;


< prev index next >