< prev index next >

test/hotspot/jtreg/vmTestbase/vm/mlvm/patches/java.base/jdk/internal/org/objectweb/asm/ClassWriterExt.java

Print this page
rev 52456 : imported patch asm.additional


  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package jdk.internal.org.objectweb.asm;
  25 
  26 import java.lang.reflect.InaccessibleObjectException;
  27 
  28 public class ClassWriterExt extends ClassWriter {
  29     private boolean cacheInvokeDynamic = true;
  30     private boolean cacheMTypes = true;
  31     private boolean cacheMHandles = true;
  32 
  33     private final Item key = new Item();
  34 
  35     public ClassWriterExt(ClassReader cr, int flags) {
  36         super(cr, flags);
  37     }
  38 
  39     public ClassWriterExt(int flags) {
  40         super(flags);
  41     }
  42 
  43     @Override
  44     Item newInvokeDynamicItem(final String name, final String desc,
  45                     final Handle bsm, final Object... bsmArgs) {
  46         if (cacheInvokeDynamic) {
  47             return super.newInvokeDynamicItem(name, desc, bsm, bsmArgs);
  48         }
  49         int type = ClassWriter.INDY;
  50         disableItemHashTableFor(type);
  51         Item result;
  52         try {
  53             return super.newInvokeDynamicItem(name, desc, bsm, bsmArgs);
  54         } finally {
  55             restoreItemHashTableFor(type);
  56         }
  57     }
  58 
  59     @Override
  60     Item newStringishItem(final int type, final String value) {
  61         if (type != ClassWriter.MTYPE) {
  62             return super.newStringishItem(type, value);


  91         for (Item i : items) {
  92             while (i != null) {
  93                 if (i.type == type) {
  94                     i.type = -type;
  95                 }
  96                 i = i.next;
  97             }
  98         }
  99     }
 100 
 101     private void restoreItemHashTableFor(int type) {
 102         for (Item i : items) {
 103             while (i != null) {
 104                 if (i.type == -type) {
 105                     i.type = type;
 106                 }
 107                 i = i.next;
 108             }
 109         }
 110     }
 111 
 112     public void setCacheInvokeDynamic(boolean value) {

 113         cacheInvokeDynamic = value;
 114     }
 115     public void setCacheMTypes(boolean value) {

 116         cacheMTypes = value;
 117     }
 118     public void setCacheMHandles(boolean value) {

 119         cacheMHandles = value;
 120     }
 121 
 122     public int getBytecodeLength(MethodVisitor mv) {
 123         ByteVector code;
 124         try {
 125             java.lang.reflect.Field field = mv.getClass().getDeclaredField("code");
 126             field.setAccessible(true);
 127             code = (ByteVector) field.get(mv);
 128         } catch (InaccessibleObjectException | SecurityException | ReflectiveOperationException e) {
 129             throw new Error("can not read field 'code' from class " + mv.getClass(), e);
 130         }
 131         try {
 132             java.lang.reflect.Field field = code.getClass().getDeclaredField("length");
 133             field.setAccessible(true);
 134             return field.getInt(code);
 135         } catch (InaccessibleObjectException | SecurityException | ReflectiveOperationException e) {
 136             throw new Error("can not read field 'length' from class " + code.getClass(), e);
 137         }
 138     }


  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package jdk.internal.org.objectweb.asm;
  25 
  26 import java.lang.reflect.InaccessibleObjectException;
  27 
  28 public class ClassWriterExt extends ClassWriter {
  29     private boolean cacheInvokeDynamic = true;
  30     private boolean cacheMTypes = true;
  31     private boolean cacheMHandles = true;
  32 


  33     public ClassWriterExt(ClassReader cr, int flags) {
  34         super(cr, flags);
  35     }
  36 
  37     public ClassWriterExt(int flags) {
  38         super(flags);
  39     }
  40 /*
  41     @Override
  42     Item newInvokeDynamicItem(final String name, final String desc,
  43                     final Handle bsm, final Object... bsmArgs) {
  44         if (cacheInvokeDynamic) {
  45             return super.newInvokeDynamicItem(name, desc, bsm, bsmArgs);
  46         }
  47         int type = ClassWriter.INDY;
  48         disableItemHashTableFor(type);
  49         Item result;
  50         try {
  51             return super.newInvokeDynamicItem(name, desc, bsm, bsmArgs);
  52         } finally {
  53             restoreItemHashTableFor(type);
  54         }
  55     }
  56 
  57     @Override
  58     Item newStringishItem(final int type, final String value) {
  59         if (type != ClassWriter.MTYPE) {
  60             return super.newStringishItem(type, value);


  89         for (Item i : items) {
  90             while (i != null) {
  91                 if (i.type == type) {
  92                     i.type = -type;
  93                 }
  94                 i = i.next;
  95             }
  96         }
  97     }
  98 
  99     private void restoreItemHashTableFor(int type) {
 100         for (Item i : items) {
 101             while (i != null) {
 102                 if (i.type == -type) {
 103                     i.type = type;
 104                 }
 105                 i = i.next;
 106             }
 107         }
 108     }
 109 */
 110     public void setCacheInvokeDynamic(boolean value) {
 111         if (!value) throw new Error("method isn't implemented yet");
 112         cacheInvokeDynamic = value;
 113     }
 114     public void setCacheMTypes(boolean value) {
 115         if (!value) throw new Error("method isn't implemented yet");
 116         cacheMTypes = value;
 117     }
 118     public void setCacheMHandles(boolean value) {
 119         if (!value) throw new Error("method isn't implemented yet");
 120         cacheMHandles = value;
 121     }
 122 
 123     public int getBytecodeLength(MethodVisitor mv) {
 124         ByteVector code;
 125         try {
 126             java.lang.reflect.Field field = mv.getClass().getDeclaredField("code");
 127             field.setAccessible(true);
 128             code = (ByteVector) field.get(mv);
 129         } catch (InaccessibleObjectException | SecurityException | ReflectiveOperationException e) {
 130             throw new Error("can not read field 'code' from class " + mv.getClass(), e);
 131         }
 132         try {
 133             java.lang.reflect.Field field = code.getClass().getDeclaredField("length");
 134             field.setAccessible(true);
 135             return field.getInt(code);
 136         } catch (InaccessibleObjectException | SecurityException | ReflectiveOperationException e) {
 137             throw new Error("can not read field 'length' from class " + code.getClass(), e);
 138         }
 139     }
< prev index next >