public final static byte CONSTANT_Methodref = 10;
public final static byte CONSTANT_InterfaceMethodref = 11;
public final static byte CONSTANT_NameAndType = 12;
+
+ public final static byte CONSTANT_MethodHandle = 15;
+ public final static byte CONSTANT_MethodType = 16;
+ public final static byte CONSTANT_InvokeDynamic = 18;
public final static String[] CONSTANT_NAMES = { "", "CONSTANT_Utf8", "", "CONSTANT_Integer", "CONSTANT_Float", "CONSTANT_Long",
"CONSTANT_Double", "CONSTANT_Class", "CONSTANT_String", "CONSTANT_Fieldref", "CONSTANT_Methodref",
- "CONSTANT_InterfaceMethodref", "CONSTANT_NameAndType" };
+ "CONSTANT_InterfaceMethodref", "CONSTANT_NameAndType","","","CONSTANT_MethodHandle","CONSTANT_MethodType","","CONSTANT_InvokeDynamic" };
/**
* The name of the static initializer, also called "class initialization method" or "interface initialization
public static final short INVOKENONVIRTUAL = 183; // Old name in JDK 1.0
public static final short INVOKESTATIC = 184;
public static final short INVOKEINTERFACE = 185;
+ public static final short INVOKEDYNAMIC = 186;
public static final short NEW = 187;
public static final short NEWARRAY = 188;
public static final short ANEWARRAY = 189;
"dcmpg", "ifeq", "ifne", "iflt", "ifge", "ifgt", "ifle", "if_icmpeq", "if_icmpne", "if_icmplt", "if_icmpge",
"if_icmpgt", "if_icmple", "if_acmpeq", "if_acmpne", "goto", "jsr", "ret", "tableswitch", "lookupswitch", "ireturn",
"lreturn", "freturn", "dreturn", "areturn", "return", "getstatic", "putstatic", "getfield", "putfield",
- "invokevirtual", "invokespecial", "invokestatic", "invokeinterface", ILLEGAL_OPCODE, "new", "newarray", "anewarray",
+ "invokevirtual", "invokespecial", "invokestatic", "invokeinterface", "invokedynamic", "new", "newarray", "anewarray",
"arraylength", "athrow", "checkcast", "instanceof", "monitorenter", "monitorexit", "wide", "multianewarray", "ifnull",
"ifnonnull", "goto_w", "jsr_w", "breakpoint", ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE,
public static final byte ATTR_LOCAL_VARIABLE_TYPE_TABLE = 16;
public static final byte ATTR_ENCLOSING_METHOD = 17;
public static final byte ATTR_ANNOTATION_DEFAULT = 18;
+ public static final byte ATTR_BOOTSTRAPMETHODS = 19;
- public static final short KNOWN_ATTRIBUTES = 19;
+ public static final short KNOWN_ATTRIBUTES = 20;
public static final String[] ATTRIBUTE_NAMES = { "SourceFile", "ConstantValue", "Code", "Exceptions", "LineNumberTable",
"LocalVariableTable", "InnerClasses", "Synthetic", "Deprecated", "PMGClass", "Signature", "StackMap",
"RuntimeVisibleAnnotations", "RuntimeInvisibleAnnotations", "RuntimeVisibleParameterAnnotations",
- "RuntimeInvisibleParameterAnnotations", "LocalVariableTypeTable", "EnclosingMethod", "AnnotationDefault" };
+ "RuntimeInvisibleParameterAnnotations", "LocalVariableTypeTable", "EnclosingMethod", "AnnotationDefault","BootstrapMethods" };
/**
* Constants used in the StackMap attribute.
return new LocalVariableTypeTable(idx, len, file, cpool);
case Constants.ATTR_ENCLOSING_METHOD:
return new EnclosingMethod(idx, len, file, cpool);
+ case Constants.ATTR_BOOTSTRAPMETHODS:
+ return new BootstrapMethods(idx,len,file,cpool);
default:
throw new IllegalStateException();
}
--- /dev/null
+package org.aspectj.apache.bcel.classfile;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.Constants;
+
+/**
+ * Represents the BootstrapMethods attribute in Java 7 classes.
+ *
+ * @author Andy Clement
+ */
+public final class BootstrapMethods extends Attribute {
+
+ // if 'isInPackedState' then this data needs unpacking
+ private boolean isInPackedState = false;
+ private byte[] data; // discarded once unpacked
+
+ private int numBootstrapMethods;
+ private BootstrapMethod[] bootstrapMethods;
+
+ public BootstrapMethods(BootstrapMethods c) {
+ this(c.getNameIndex(), c.getLength(), c.getBootstrapMethods(), c.getConstantPool());
+ }
+
+ public BootstrapMethods(int nameIndex, int length, BootstrapMethod[] lineNumberTable, ConstantPool constantPool) {
+ super(Constants.ATTR_BOOTSTRAPMETHODS, nameIndex, length, constantPool);
+ setBootstrapMethods(lineNumberTable);
+ isInPackedState = false;
+ }
+
+ public final void setBootstrapMethods(BootstrapMethod[] bootstrapMethods) {
+ this.data = null;
+ this.isInPackedState = false;
+ this.bootstrapMethods = bootstrapMethods;
+ this.numBootstrapMethods = bootstrapMethods==null?0:bootstrapMethods.length;
+ }
+
+ BootstrapMethods(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
+ this(name_index, length, (BootstrapMethod[])null, constant_pool);
+ data = new byte[length];
+ file.read(data);
+ isInPackedState = true;
+ }
+
+ static class BootstrapMethod {
+ private int bootstrapMethodRef;
+ private int[] bootstrapArguments;
+
+ BootstrapMethod(DataInputStream file) throws IOException {
+ this(file.readUnsignedShort(), readBootstrapArguments(file));
+ }
+
+ private static int[] readBootstrapArguments(DataInputStream dis) throws IOException {
+ int numBootstrapMethods = dis.readUnsignedShort();
+ int[] bootstrapArguments = new int[numBootstrapMethods];
+ for (int i=0;i<numBootstrapMethods;i++) {
+ bootstrapArguments[i] = dis.readUnsignedShort();
+ }
+ return bootstrapArguments;
+ }
+
+ BootstrapMethod(int bootstrapMethodRef, int[] bootstrapArguments) {
+ this.bootstrapMethodRef = bootstrapMethodRef;
+ this.bootstrapArguments = bootstrapArguments;
+ }
+
+ public final void dump(DataOutputStream file) throws IOException {
+ file.writeShort(bootstrapMethodRef);
+ int len = bootstrapArguments.length;
+ file.writeShort(len);
+ for (int i=0;i<len;i++) {
+ file.writeShort(bootstrapArguments[i]);
+ }
+ }
+ }
+
+ // Unpacks the byte array into the table
+ private void unpack() {
+ if (isInPackedState) {
+ try {
+ ByteArrayInputStream bs = new ByteArrayInputStream(data);
+ DataInputStream dis = new DataInputStream(bs);
+ int bootstrapMethodCount = dis.readUnsignedShort();
+ bootstrapMethods = new BootstrapMethod[bootstrapMethodCount];
+ for (int i = 0; i < bootstrapMethodCount; i++) {
+ bootstrapMethods[i] = new BootstrapMethod(dis);
+ }
+ dis.close();
+ data = null; // throw it away now
+ } catch (IOException e) {
+ throw new RuntimeException("Unpacking of LineNumberTable attribute failed");
+ }
+ isInPackedState = false;
+ }
+ }
+
+ /**
+ * Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class. I.e., the
+ * hierarchy of methods, fields, attributes, etc. spawns a tree of objects.
+ *
+ * @param v Visitor object
+ */
+ @Override
+ public void accept(ClassVisitor v) {
+ unpack();
+ v.visitBootstrapMethods(this);
+ }
+
+ /**
+ * Dump line number table attribute to file stream in binary format.
+ *
+ * @param file Output file stream
+ * @throws IOException
+ */
+ @Override
+ public final void dump(DataOutputStream file) throws IOException {
+ super.dump(file);
+ if (isInPackedState) {
+ file.write(data);
+ } else {
+ int blen = bootstrapMethods.length;
+ file.writeShort(blen);
+ for (int i = 0; i < blen; i++) {
+ bootstrapMethods[i].dump(file);
+ }
+ }
+ }
+
+ public final BootstrapMethod[] getBootstrapMethods() {
+ unpack();
+ return bootstrapMethods;
+ }
+
+
+ /**
+ * @return String representation.
+ */
+ @Override
+ public final String toString() {
+ throw new IllegalStateException("nyi");
+// unpack();
+// StringBuffer buf = new StringBuffer();
+// StringBuffer line = new StringBuffer();
+//
+// for (int i = 0; i < bootstrapMethodCount; i++) {
+// line.append(table[i].toString());
+//
+// if (i < bootstrapMethodCount - 1) {
+// line.append(", ");
+// }
+//
+// if (line.length() > 72) {
+// line.append('\n');
+// buf.append(line);
+// line.setLength(0);
+// }
+// }
+//
+// buf.append(line);
+//
+// return buf.toString();
+ }
+
+
+ /**
+ * @return deep copy of this attribute
+ */
+ // @Override
+ // public Attribute copy(ConstantPool constant_pool) {
+ // unpack();
+ // LineNumberTable newTable = (LineNumberTable) clone();
+ // newTable.table = new LineNumber[tableLength];
+ // for (int i = 0; i < tableLength; i++) {
+ // newTable.table[i] = table[i].copy();
+ // }
+ // newTable.cpool = constant_pool;
+ // return newTable;
+ // }
+ public final int getNumBootstrapMethods () {
+ unpack();
+ return bootstrapMethods.length;
+ }
+}
public void visitConstantLong(ConstantLong obj);
public void visitConstantMethodref(ConstantMethodref obj);
+
+ public void visitConstantMethodHandle(ConstantMethodHandle obj);
public void visitConstantNameAndType(ConstantNameAndType obj);
+
+ public void visitConstantMethodType(ConstantMethodType obj);
+
+ public void visitConstantInvokeDynamic(ConstantInvokeDynamic obj);
public void visitConstantPool(ConstantPool obj);
public void visitSourceFile(SourceFile obj);
public void visitSynthetic(Synthetic obj);
+
+ public void visitBootstrapMethods(BootstrapMethods obj);
public void visitUnknown(Unknown obj);
return new ConstantLong(dis);
case Constants.CONSTANT_Double:
return new ConstantDouble(dis);
+ case Constants.CONSTANT_MethodHandle:
+ return new ConstantMethodHandle(dis);
+ case Constants.CONSTANT_MethodType:
+ return new ConstantMethodType(dis);
+ case Constants.CONSTANT_InvokeDynamic:
+ return new ConstantInvokeDynamic(dis);
default:
throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
}
--- /dev/null
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.aspectj.apache.bcel.classfile;
+
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.Constants;
+
+/**
+ * This class is derived from the abstract <A HREF="org.aspectj.apache.bcel.classfile.Constant.html">Constant</A> class and
+ * represents a reference to the name and signature of a field or method.
+ *
+ * http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4.10
+ *
+ * @author Andy Clement
+ * @see Constant
+ */
+public final class ConstantInvokeDynamic extends Constant {
+ private final int bootstrapMethodAttrIndex;
+ private final int nameAndTypeIndex;
+
+ ConstantInvokeDynamic(DataInputStream file) throws IOException {
+ this(file.readUnsignedShort(), file.readUnsignedShort());
+ }
+
+ public ConstantInvokeDynamic(int readUnsignedShort, int nameAndTypeIndex) {
+ super(Constants.CONSTANT_InvokeDynamic);
+ this.bootstrapMethodAttrIndex = readUnsignedShort;
+ this.nameAndTypeIndex = nameAndTypeIndex;
+ }
+
+ @Override
+ public final void dump(DataOutputStream file) throws IOException {
+ file.writeByte(tag);
+ file.writeShort(bootstrapMethodAttrIndex);
+ file.writeShort(nameAndTypeIndex);
+ }
+//
+// public final byte getReferenceKind() {
+// return bootstrapMethodAttrIndex;
+// }
+//
+// public final String getName(ConstantPool cp) {
+// return cp.constantToString(getNameIndex(), Constants.CONSTANT_Utf8);
+// }
+//
+// public final int getSignatureIndex() {
+// return referenceIndex;
+// }
+//
+// public final String getSignature(ConstantPool cp) {
+// return cp.constantToString(getSignatureIndex(), Constants.CONSTANT_Utf8);
+// }
+
+ public final int getNameAndTypeIndex() {
+ return nameAndTypeIndex;
+ }
+
+ @Override
+ public final String toString() {
+ return super.toString() + "(bootstrapMethodAttrIndex=" + bootstrapMethodAttrIndex + ",nameAndTypeIndex=" + nameAndTypeIndex + ")";
+ }
+
+ @Override
+ public String getValue() {
+ return toString();
+ }
+
+ @Override
+ public void accept(ClassVisitor v) {
+ v.visitConstantInvokeDynamic(this);
+ }
+
+}
--- /dev/null
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.aspectj.apache.bcel.classfile;
+
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.Constants;
+
+/**
+ * This class is derived from the abstract <A HREF="org.aspectj.apache.bcel.classfile.Constant.html">Constant</A> class and
+ * represents a reference to the name and signature of a field or method.
+ *
+ * http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4.8
+ *
+ * @author Andy Clement
+ * @see Constant
+ */
+public final class ConstantMethodHandle extends Constant {
+ private byte referenceKind;
+ private int referenceIndex;
+
+ ConstantMethodHandle(DataInputStream file) throws IOException {
+ this(file.readByte(), file.readUnsignedShort());
+ }
+
+ public ConstantMethodHandle(byte referenceKind, int referenceIndex) {
+ super(Constants.CONSTANT_MethodHandle);
+ this.referenceKind = referenceKind;
+ this.referenceIndex = referenceIndex;
+ }
+
+ @Override
+ public final void dump(DataOutputStream file) throws IOException {
+ file.writeByte(tag);
+ file.writeByte(referenceKind);
+ file.writeShort(referenceIndex);
+ }
+
+ public final byte getReferenceKind() {
+ return referenceKind;
+ }
+
+// public final String getName(ConstantPool cp) {
+// return cp.constantToString(getNameIndex(), Constants.CONSTANT_Utf8);
+// }
+//
+// public final int getSignatureIndex() {
+// return referenceIndex;
+// }
+//
+// public final String getSignature(ConstantPool cp) {
+// return cp.constantToString(getSignatureIndex(), Constants.CONSTANT_Utf8);
+// }
+
+ @Override
+ public final String toString() {
+ return super.toString() + "(referenceKind=" + referenceKind + ",referenceIndex=" + referenceIndex + ")";
+ }
+
+ @Override
+ public String getValue() {
+ return toString();
+ }
+
+ @Override
+ public void accept(ClassVisitor v) {
+ v.visitConstantMethodHandle(this);
+ }
+
+}
--- /dev/null
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.aspectj.apache.bcel.classfile;
+
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.Constants;
+
+/**
+ * This class is derived from the abstract <A HREF="org.aspectj.apache.bcel.classfile.Constant.html">Constant</A> class and
+ * represents a reference to the name and signature of a field or method.
+ *
+ * http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4.9
+ *
+ * @author Andy Clement
+ * @see Constant
+ */
+public final class ConstantMethodType extends Constant {
+ private int descriptorIndex;
+
+ ConstantMethodType(DataInputStream file) throws IOException {
+ this(file.readUnsignedShort());
+ }
+
+ public ConstantMethodType(int descriptorIndex) {
+ super(Constants.CONSTANT_MethodType);
+ this.descriptorIndex = descriptorIndex;
+ }
+
+ @Override
+ public final void dump(DataOutputStream file) throws IOException {
+ file.writeByte(tag);
+ file.writeShort(descriptorIndex);
+ }
+
+ public final int getDescriptorIndex() {
+ return descriptorIndex;
+ }
+
+// public final String getName(ConstantPool cp) {
+// return cp.constantToString(getNameIndex(), Constants.CONSTANT_Utf8);
+// }
+//
+// public final int getSignatureIndex() {
+// return referenceIndex;
+// }
+//
+// public final String getSignature(ConstantPool cp) {
+// return cp.constantToString(getSignatureIndex(), Constants.CONSTANT_Utf8);
+// }
+
+ @Override
+ public final String toString() {
+ return super.toString() + "(descriptorIndex=" + descriptorIndex + ")";
+ }
+
+ @Override
+ public String getValue() {
+ return toString();
+ }
+
+ @Override
+ public void accept(ClassVisitor v) {
+ v.visitConstantMethodType(this);
+ }
+
+}
+ bytes.readUnsignedByte()); // Last byte is a reserved
// space
break;
-
+
+ case Constants.INVOKEDYNAMIC://http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.invokedynamic
+ index = bytes.readUnsignedShort();
+ bytes.readUnsignedShort(); // zeroes
+ buf.append("\t" + constant_pool.constantToString(index) + (verbose ? " (" + index + ")" : ""));
+ break;
+
// Operands are references to items in constant pool
case Constants.LDC_W:
case Constants.LDC2_W:
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
+import org.aspectj.apache.bcel.classfile.Constant;
import org.aspectj.apache.bcel.classfile.ConstantCP;
import org.aspectj.apache.bcel.classfile.ConstantNameAndType;
import org.aspectj.apache.bcel.classfile.ConstantPool;
*/
public abstract class FieldOrMethod extends InstructionCP {
- private String signature;
+ protected String signature;
private String name;
private String classname;
*/
public String getSignature(ConstantPool cp) {
if (signature == null) {
- ConstantCP cmr = (ConstantCP) cp.getConstant(index);
+ Constant c = cp.getConstant(index);
+ ConstantCP cmr = (ConstantCP) c;
ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex());
signature = ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex())).getValue();
}
case Constants.INVOKEINTERFACE:
obj = new INVOKEINTERFACE(bytes.readUnsignedShort(), bytes.readUnsignedByte(), bytes.readByte());
break;
+ case Constants.INVOKEDYNAMIC:
+ obj = new InvokeDynamic(bytes.readUnsignedShort(),bytes.readUnsignedShort());
+ break;
case Constants.NEWARRAY:
obj = new InstructionByte(Constants.NEWARRAY, bytes.readByte());
break;
int index;
if (kind == Constants.INVOKEINTERFACE) {
index = cp.addInterfaceMethodref(class_name, name, signature);
+ } else if (kind == Constants.INVOKEDYNAMIC){
+ throw new IllegalStateException("NYI");
} else {
index = cp.addMethodref(class_name, name, signature);
}
int index;
if (kind == Constants.INVOKEINTERFACE) {
index = cp.addInterfaceMethodref(class_name, name, signature);
+ } else if (kind == Constants.INVOKEDYNAMIC){
+ throw new IllegalStateException("NYI");
} else {
index = cp.addMethodref(class_name, name, signature);
}
--- /dev/null
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+package org.aspectj.apache.bcel.generic;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.Constants;
+import org.aspectj.apache.bcel.classfile.ConstantInvokeDynamic;
+import org.aspectj.apache.bcel.classfile.ConstantNameAndType;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.ConstantUtf8;
+
+/**
+ * INVOKEDYNAMIC
+ *
+ * @author Andy Clement
+ */
+public final class InvokeDynamic extends InvokeInstruction {
+
+ public InvokeDynamic(int index, int zeroes) {
+ super(Constants.INVOKEDYNAMIC, index);
+ }
+
+ public void dump(DataOutputStream out) throws IOException {
+ out.writeByte(opcode);
+ out.writeShort(index);
+ out.writeShort(0);
+ }
+
+ public String toString(ConstantPool cp) {
+ return super.toString(cp) + " " + index;
+ }
+
+ public boolean equals(Object other) {
+ if (!(other instanceof InvokeDynamic)) {
+ return false;
+ }
+ InvokeDynamic o = (InvokeDynamic) other;
+ return o.opcode == opcode && o.index == index;
+ }
+
+ public int hashCode() {
+ return opcode * 37 + index;
+ }
+
+ public Type getReturnType(ConstantPool cp) {
+ return Type.getReturnType(getSignature(cp));
+ }
+
+ public Type[] getArgumentTypes(ConstantPool cp) {
+ return Type.getArgumentTypes(getSignature(cp));
+ }
+
+ public String getSignature(ConstantPool cp) {
+ if (signature == null) {
+ ConstantInvokeDynamic cid = (ConstantInvokeDynamic)cp.getConstant(index);
+ ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cid.getNameAndTypeIndex());
+ signature = ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex())).getValue();
+ }
+ return signature;
+ }
+
+}
import org.aspectj.apache.bcel.classfile.AnnotationDefault;
import org.aspectj.apache.bcel.classfile.Attribute;
import org.aspectj.apache.bcel.classfile.AttributeUtils;
+import org.aspectj.apache.bcel.classfile.BootstrapMethods;
import org.aspectj.apache.bcel.classfile.Code;
import org.aspectj.apache.bcel.classfile.CodeException;
import org.aspectj.apache.bcel.classfile.Constant;
import org.aspectj.apache.bcel.classfile.ConstantFloat;
import org.aspectj.apache.bcel.classfile.ConstantInteger;
import org.aspectj.apache.bcel.classfile.ConstantInterfaceMethodref;
+import org.aspectj.apache.bcel.classfile.ConstantInvokeDynamic;
import org.aspectj.apache.bcel.classfile.ConstantLong;
+import org.aspectj.apache.bcel.classfile.ConstantMethodHandle;
+import org.aspectj.apache.bcel.classfile.ConstantMethodType;
import org.aspectj.apache.bcel.classfile.ConstantMethodref;
import org.aspectj.apache.bcel.classfile.ConstantNameAndType;
import org.aspectj.apache.bcel.classfile.ConstantPool;
constant.accept(visitor);
stack.pop();
}
+
+ public void visitConstantMethodHandle(ConstantMethodHandle constant) {
+ throw new IllegalStateException("nyi");
+ }
+
+ public void visitConstantMethodType(ConstantMethodType obj) {
+ throw new IllegalStateException("nyi");
+ }
+
+ public void visitConstantInvokeDynamic(ConstantInvokeDynamic obj) {
+ throw new IllegalStateException("nyi");
+ }
+
+ public void visitBootstrapMethods(BootstrapMethods obj) {
+ throw new IllegalStateException("nyi");
+ }
public void visitConstantNameAndType(ConstantNameAndType constant) {
stack.push(constant);
*/
import org.aspectj.apache.bcel.classfile.AnnotationDefault;
+import org.aspectj.apache.bcel.classfile.BootstrapMethods;
import org.aspectj.apache.bcel.classfile.Code;
import org.aspectj.apache.bcel.classfile.CodeException;
import org.aspectj.apache.bcel.classfile.ConstantClass;
import org.aspectj.apache.bcel.classfile.ConstantFloat;
import org.aspectj.apache.bcel.classfile.ConstantInteger;
import org.aspectj.apache.bcel.classfile.ConstantInterfaceMethodref;
+import org.aspectj.apache.bcel.classfile.ConstantInvokeDynamic;
import org.aspectj.apache.bcel.classfile.ConstantLong;
+import org.aspectj.apache.bcel.classfile.ConstantMethodHandle;
+import org.aspectj.apache.bcel.classfile.ConstantMethodType;
import org.aspectj.apache.bcel.classfile.ConstantMethodref;
import org.aspectj.apache.bcel.classfile.ConstantNameAndType;
import org.aspectj.apache.bcel.classfile.ConstantPool;
public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj) {}
public void visitConstantLong(ConstantLong obj) {}
public void visitConstantMethodref(ConstantMethodref obj) {}
+ public void visitConstantMethodHandle(ConstantMethodHandle obj) {}
+ public void visitConstantMethodType(ConstantMethodType obj) {}
+ public void visitConstantInvokeDynamic(ConstantInvokeDynamic obj) {}
public void visitConstantNameAndType(ConstantNameAndType obj) {}
public void visitConstantPool(ConstantPool obj) {}
public void visitConstantString(ConstantString obj) {}
public void visitInnerClasses(InnerClasses obj) {}
public void visitJavaClass(JavaClass obj) {}
public void visitLineNumber(LineNumber obj) {}
+ public void visitBootstrapMethods(BootstrapMethods obj) {}
public void visitLineNumberTable(LineNumberTable obj) {}
public void visitLocalVariable(LocalVariable obj) {}
public void visitLocalVariableTable(LocalVariableTable obj) {}
<!-- if you need this defining, use the jarjar-1.0.jar in this project -->
<taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask"/>
- <target name="package" description="Jarjar asm-3.3.1.jar and prefix package name with aj">
- <jarjar destfile="asm-3.3.1.renamed.jar">
- <zipfileset src="asm-3.3.1.jar"/>
+ <target name="package" description="Jarjar asm-4.0.jar and prefix package name with aj">
+ <jarjar destfile="asm-4.0.renamed.jar">
+ <zipfileset src="asm-4.0.jar"/>
<rule pattern="org.objectweb.asm.**" result="aj.org.objectweb.asm.@1"/>
</jarjar>
</target>
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2008 Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andy Clement - initial API and implementation
+ *******************************************************************************/
+package org.aspectj.systemtest.ajc170;
+
+import java.io.File;
+import java.io.IOException;
+
+import junit.framework.Test;
+
+import org.aspectj.apache.bcel.classfile.ClassParser;
+import org.aspectj.apache.bcel.classfile.Field;
+import org.aspectj.apache.bcel.classfile.JavaClass;
+import org.aspectj.testing.XMLBasedAjcTestCase;
+import org.aspectj.weaver.TypeFactory;
+import org.aspectj.weaver.UnresolvedType;
+
+/**
+ * @author Andy Clement
+ */
+public class IndyTests extends org.aspectj.testing.XMLBasedAjcTestCase {
+
+ // staticinitialization on bytecode containing methodtyperef/methodhandle/bootstrapmethods/invokedynamic
+ public void testInvokeDynamic_staticinitialization() throws IOException {
+ runTest("indy - 1");
+ }
+
+ // execution pointcuts on same bytecode
+ public void testInvokeDynamic_execution() throws IOException {
+ runTest("indy - 2");
+ }
+
+ // ---
+
+ public static Test suite() {
+ return XMLBasedAjcTestCase.loadSuite(IndyTests.class);
+ }
+
+ @Override
+ protected File getSpecFile() {
+ return new File("../tests/src/org/aspectj/systemtest/ajc170/indy.xml");
+ }
+
+}
--- /dev/null
+<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[]>
+
+<suite>
+
+ <ajc-test dir="indy/one" title="indy - 1">
+ <compile files="Code1.java,Asp.java" inpath="indy.jar" options="-1.7"/>
+ <run class="Invoker">
+ <stdout>
+ <line text="staticinitialization(Invoker.<clinit>)"/>
+ <line text="staticinitialization(Code1.<clinit>)"/>
+ <line text="foo() is running"/>
+ </stdout>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="indy/two" title="indy - 2">
+ <compile files="Code1.java,Asp.java" inpath="indy.jar" options="-1.7"/>
+ <run class="Invoker">
+ <stdout>
+ <line text="execution(void Invoker.main(String[]))"/>
+ <line text="execution(CallSite Code1.bootstrap(MethodHandles.Lookup, String, MethodType))"/>
+ <line text="execution(void Code1.foo())"/>
+ <line text="foo() is running"/>
+ </stdout>
+ </run>
+ </ajc-test>
+
+</suite>
<classpathentry kind="lib" path="/lib/bcel/bcel.jar" sourcepath="/lib/bcel/bcel-src.zip"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.aspectj.matcher"/>
- <classpathentry kind="lib" path="/lib/asm/asm-3.3.1.renamed.jar"/>
+ <classpathentry kind="lib" path="/lib/asm/asm-4.0.renamed.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>