diff options
author | Andy Clement <aclement@vmware.com> | 2012-03-19 11:57:01 -0700 |
---|---|---|
committer | Andy Clement <aclement@vmware.com> | 2012-03-19 11:57:01 -0700 |
commit | 80de31e4da0415134aac8ab2fc492de58fb6bd03 (patch) | |
tree | 885a90619888110594fe93dbbc3bc4ccf07843d0 | |
parent | 42035aea54234894721cca2858035002c7bfa9c7 (diff) | |
download | aspectj-80de31e4da0415134aac8ab2fc492de58fb6bd03.tar.gz aspectj-80de31e4da0415134aac8ab2fc492de58fb6bd03.zip |
invokedynamic support in bcel
25 files changed, 884 insertions, 11 deletions
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/Constants.java b/bcel-builder/src/org/aspectj/apache/bcel/Constants.java index a46daf157..2604d8e54 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/Constants.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/Constants.java @@ -127,10 +127,14 @@ public interface Constants { 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 @@ -346,6 +350,7 @@ public interface Constants { 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; @@ -533,7 +538,7 @@ public interface Constants { "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, @@ -603,13 +608,14 @@ public interface Constants { 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. diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Attribute.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Attribute.java index bc30b719c..939fa36be 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Attribute.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Attribute.java @@ -157,6 +157,8 @@ public abstract class Attribute implements Cloneable, Node, Serializable { 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(); } diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/BootstrapMethods.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/BootstrapMethods.java new file mode 100644 index 000000000..04b1c764b --- /dev/null +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/BootstrapMethods.java @@ -0,0 +1,240 @@ +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; + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ClassVisitor.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ClassVisitor.java index 0957bfba8..c411cb5d6 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ClassVisitor.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ClassVisitor.java @@ -88,8 +88,14 @@ public interface ClassVisitor { 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); @@ -126,6 +132,8 @@ public interface ClassVisitor { public void visitSourceFile(SourceFile obj); public void visitSynthetic(Synthetic obj); + + public void visitBootstrapMethods(BootstrapMethods obj); public void visitUnknown(Unknown obj); diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Constant.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Constant.java index eedcc98f2..2110bdc08 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Constant.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Constant.java @@ -129,6 +129,12 @@ public abstract class Constant implements Cloneable, Node { 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); } diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantInvokeDynamic.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantInvokeDynamic.java new file mode 100644 index 000000000..be71b4e8e --- /dev/null +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantInvokeDynamic.java @@ -0,0 +1,128 @@ +/* ==================================================================== + * 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); + } + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantMethodHandle.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantMethodHandle.java new file mode 100644 index 000000000..fe5623f33 --- /dev/null +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantMethodHandle.java @@ -0,0 +1,124 @@ +/* ==================================================================== + * 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); + } + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantMethodType.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantMethodType.java new file mode 100644 index 000000000..867e7eb0a --- /dev/null +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantMethodType.java @@ -0,0 +1,121 @@ +/* ==================================================================== + * 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); + } + +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Utility.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Utility.java index 6845139a3..98f5952ae 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Utility.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Utility.java @@ -995,7 +995,13 @@ public abstract class Utility { + 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: diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldOrMethod.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldOrMethod.java index bf2c73299..4987969c3 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldOrMethod.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldOrMethod.java @@ -53,6 +53,7 @@ package org.aspectj.apache.bcel.generic; * 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; @@ -66,7 +67,7 @@ import org.aspectj.apache.bcel.classfile.ConstantUtf8; */ public abstract class FieldOrMethod extends InstructionCP { - private String signature; + protected String signature; private String name; private String classname; @@ -79,7 +80,8 @@ public abstract class FieldOrMethod extends InstructionCP { */ 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(); } diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/Instruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/Instruction.java index e610253ac..113be06ee 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/Instruction.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/Instruction.java @@ -208,6 +208,9 @@ public class Instruction implements Cloneable, Serializable, Constants { 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; diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionFactory.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionFactory.java index c327af96c..4ff25bd55 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionFactory.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionFactory.java @@ -99,6 +99,8 @@ public class InstructionFactory implements InstructionConstants { 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); } @@ -125,6 +127,8 @@ public class InstructionFactory implements InstructionConstants { 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); } diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/InvokeDynamic.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/InvokeDynamic.java new file mode 100644 index 000000000..7083500d0 --- /dev/null +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/InvokeDynamic.java @@ -0,0 +1,116 @@ +/* ==================================================================== + * 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; + } + +} diff --git a/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/DescendingVisitor.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/DescendingVisitor.java index 3c8483120..d8b6ba1ac 100644 --- a/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/DescendingVisitor.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/DescendingVisitor.java @@ -58,6 +58,7 @@ import java.util.Stack; 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; @@ -67,7 +68,10 @@ import org.aspectj.apache.bcel.classfile.ConstantFieldref; 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; @@ -326,6 +330,22 @@ public class DescendingVisitor implements ClassVisitor { 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); diff --git a/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/EmptyClassVisitor.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/EmptyClassVisitor.java index 5dbe317b8..cbfd079ca 100644 --- a/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/EmptyClassVisitor.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/EmptyClassVisitor.java @@ -55,6 +55,7 @@ package org.aspectj.apache.bcel.verifier; */ 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; @@ -63,7 +64,10 @@ import org.aspectj.apache.bcel.classfile.ConstantFieldref; 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; @@ -118,6 +122,9 @@ public class EmptyClassVisitor implements ClassVisitor { 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) {} @@ -130,6 +137,7 @@ public class EmptyClassVisitor implements ClassVisitor { 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) {} diff --git a/lib/asm/asm-4.0.jar b/lib/asm/asm-4.0.jar Binary files differnew file mode 100644 index 000000000..6d63075eb --- /dev/null +++ b/lib/asm/asm-4.0.jar diff --git a/lib/asm/asm-4.0.renamed.jar b/lib/asm/asm-4.0.renamed.jar Binary files differnew file mode 100644 index 000000000..bb506ad1b --- /dev/null +++ b/lib/asm/asm-4.0.renamed.jar diff --git a/lib/asm/build.xml b/lib/asm/build.xml index 2502b3b61..ce3b4a7aa 100644 --- a/lib/asm/build.xml +++ b/lib/asm/build.xml @@ -3,9 +3,9 @@ <!-- 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> diff --git a/lib/bcel/bcel-src.zip b/lib/bcel/bcel-src.zip Binary files differindex eeded5ee7..b512f9051 100644 --- a/lib/bcel/bcel-src.zip +++ b/lib/bcel/bcel-src.zip diff --git a/lib/bcel/bcel-verifier-src.zip b/lib/bcel/bcel-verifier-src.zip Binary files differindex 443b9d8ac..c764a9a28 100644 --- a/lib/bcel/bcel-verifier-src.zip +++ b/lib/bcel/bcel-verifier-src.zip diff --git a/lib/bcel/bcel-verifier.jar b/lib/bcel/bcel-verifier.jar Binary files differindex 0391a965a..fed7db520 100644 --- a/lib/bcel/bcel-verifier.jar +++ b/lib/bcel/bcel-verifier.jar diff --git a/lib/bcel/bcel.jar b/lib/bcel/bcel.jar Binary files differindex a029381b5..c439c0776 100644 --- a/lib/bcel/bcel.jar +++ b/lib/bcel/bcel.jar diff --git a/tests/src/org/aspectj/systemtest/ajc170/IndyTests.java b/tests/src/org/aspectj/systemtest/ajc170/IndyTests.java new file mode 100644 index 000000000..24503ce1b --- /dev/null +++ b/tests/src/org/aspectj/systemtest/ajc170/IndyTests.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * 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"); + } + +} diff --git a/tests/src/org/aspectj/systemtest/ajc170/indy.xml b/tests/src/org/aspectj/systemtest/ajc170/indy.xml new file mode 100644 index 000000000..0e1b85a12 --- /dev/null +++ b/tests/src/org/aspectj/systemtest/ajc170/indy.xml @@ -0,0 +1,28 @@ +<!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> diff --git a/weaver/.classpath b/weaver/.classpath index 803dcce59..aeb0703e6 100644 --- a/weaver/.classpath +++ b/weaver/.classpath @@ -13,6 +13,6 @@ <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> |