aboutsummaryrefslogtreecommitdiffstats
path: root/bcel-builder
diff options
context:
space:
mode:
authorAndy Clement <aclement@gopivotal.com>2014-09-30 10:50:54 -0700
committerAndy Clement <aclement@gopivotal.com>2014-09-30 10:50:54 -0700
commite26c781374ac7afeaf8859baf4fc55d7dfb7b3a7 (patch)
tree7e4ae365c26dbc16428c4c7f575a2e8b9b67c41e /bcel-builder
parentd0b8c7a1bfbc2b2f92b22bcf63598ab2442781b6 (diff)
downloadaspectj-e26c781374ac7afeaf8859baf4fc55d7dfb7b3a7.tar.gz
aspectj-e26c781374ac7afeaf8859baf4fc55d7dfb7b3a7.zip
445395: more support for invokedynamic
Diffstat (limited to 'bcel-builder')
-rw-r--r--bcel-builder/src/org/aspectj/apache/bcel/ConstantsInitializer.java5
-rw-r--r--bcel-builder/src/org/aspectj/apache/bcel/ExceptionConstants.java1
-rw-r--r--bcel-builder/src/org/aspectj/apache/bcel/classfile/BootstrapMethods.java10
-rw-r--r--bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantInvokeDynamic.java4
-rw-r--r--bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java39
-rw-r--r--bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionList.java3
6 files changed, 58 insertions, 4 deletions
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/ConstantsInitializer.java b/bcel-builder/src/org/aspectj/apache/bcel/ConstantsInitializer.java
index 9e19c417d..b9bc0d49f 100644
--- a/bcel-builder/src/org/aspectj/apache/bcel/ConstantsInitializer.java
+++ b/bcel-builder/src/org/aspectj/apache/bcel/ConstantsInitializer.java
@@ -337,6 +337,11 @@ public class ConstantsInitializer {
| Constants.INDEXED;
Constants.instExcs[Constants.INVOKEVIRTUAL] = ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION_INVOKESPECIAL_INVOKEVIRTUAL;
+ Constants.instFlags[Constants.INVOKEDYNAMIC] = Constants.EXCEPTION_THROWER | Constants.CP_INST | Constants.LOADCLASS_INST
+ | Constants.INDEXED;
+ // TBD
+ // Constants.instExcs[Constants.INVOKEDYNAMIC] = ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION_INVOKESPECIAL_INVOKEVIRTUAL;
+
//@formatter:off
char[] lengths = // . = varies in length, / = undefined
("1111111111111111" + // nop > dconst_1
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/ExceptionConstants.java b/bcel-builder/src/org/aspectj/apache/bcel/ExceptionConstants.java
index 34455be35..0c918c8ea 100644
--- a/bcel-builder/src/org/aspectj/apache/bcel/ExceptionConstants.java
+++ b/bcel-builder/src/org/aspectj/apache/bcel/ExceptionConstants.java
@@ -135,6 +135,7 @@ public interface ExceptionConstants {
ILLEGAL_ACCESS_ERROR, ABSTRACT_METHOD_ERROR, UNSATISFIED_LINK_ERROR };
public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION_INVOKESPECIAL_INVOKEVIRTUAL = { INCOMPATIBLE_CLASS_CHANGE_ERROR,
NULL_POINTER_EXCEPTION, ABSTRACT_METHOD_ERROR, UNSATISFIED_LINK_ERROR };
+// public static final Class[] EXCS_INVOKEDYNAMIC = { BOOTSTRAP_METHOD_ERROR};
public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION_INVOKESTATIC = { INCOMPATIBLE_CLASS_CHANGE_ERROR,
UNSATISFIED_LINK_ERROR };
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/BootstrapMethods.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/BootstrapMethods.java
index b4638bc29..a5216f2ef 100644
--- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/BootstrapMethods.java
+++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/BootstrapMethods.java
@@ -99,7 +99,7 @@ public final class BootstrapMethods extends Attribute {
isInPackedState = true;
}
- static class BootstrapMethod {
+ public static class BootstrapMethod {
private int bootstrapMethodRef;
private int[] bootstrapArguments;
@@ -116,7 +116,7 @@ public final class BootstrapMethods extends Attribute {
return bootstrapArguments;
}
- BootstrapMethod(int bootstrapMethodRef, int[] bootstrapArguments) {
+ public BootstrapMethod(int bootstrapMethodRef, int[] bootstrapArguments) {
this.bootstrapMethodRef = bootstrapMethodRef;
this.bootstrapArguments = bootstrapArguments;
}
@@ -138,6 +138,12 @@ public final class BootstrapMethods extends Attribute {
}
}
+ public final int getLength() {
+ return 2 /*bootstrapMethodRef*/+
+ 2 /*number of arguments*/+
+ 2 * bootstrapArguments.length;
+ }
+
}
// Unpacks the byte array into the table
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantInvokeDynamic.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantInvokeDynamic.java
index be71b4e8e..0d263aa65 100644
--- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantInvokeDynamic.java
+++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantInvokeDynamic.java
@@ -109,6 +109,10 @@ public final class ConstantInvokeDynamic extends Constant {
public final int getNameAndTypeIndex() {
return nameAndTypeIndex;
}
+
+ public final int getBootstrapMethodAttrIndex() {
+ return bootstrapMethodAttrIndex;
+ }
@Override
public final String toString() {
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java
index fe27b5fe5..4e160ba3d 100644
--- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java
+++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java
@@ -586,6 +586,20 @@ public class ConstantPool implements Node {
return addNameAndType(u8.getValue(), u8_2.getValue());
}
+
+ case Constants.CONSTANT_InvokeDynamic: {
+ ConstantInvokeDynamic cid = (ConstantInvokeDynamic)c;
+ int index1 = cid.getBootstrapMethodAttrIndex();
+ ConstantNameAndType cnat = (ConstantNameAndType)constants[cid.getNameAndTypeIndex()];
+ ConstantUtf8 name = (ConstantUtf8) constants[cnat.getNameIndex()];
+ ConstantUtf8 signature = (ConstantUtf8) constants[cnat.getSignatureIndex()];
+ int index2 = addNameAndType(name.getValue(), signature.getValue());
+ return addInvokeDynamic(index1,index2);
+ }
+
+ case Constants.CONSTANT_MethodHandle:
+ ConstantMethodHandle cmh = (ConstantMethodHandle)c;
+ return addMethodHandle(cmh.getReferenceKind(),addConstant(constants[cmh.getReferenceIndex()],cp));
case Constants.CONSTANT_Utf8:
return addUtf8(((ConstantUtf8) c).getValue());
@@ -601,6 +615,10 @@ public class ConstantPool implements Node {
case Constants.CONSTANT_Integer:
return addInteger(((ConstantInteger) c).getValue());
+
+ case Constants.CONSTANT_MethodType:
+ ConstantMethodType cmt = (ConstantMethodType)c;
+ return addMethodType(addConstant(constants[cmt.getDescriptorIndex()],cp));
case Constants.CONSTANT_InterfaceMethodref:
case Constants.CONSTANT_Methodref:
@@ -636,6 +654,20 @@ public class ConstantPool implements Node {
throw new RuntimeException("Unknown constant type " + c);
}
}
+
+ public int addMethodHandle(byte referenceKind, int referenceIndex) {
+ adjustSize();
+ int ret = poolSize;
+ pool[poolSize++] = new ConstantMethodHandle(referenceKind, referenceIndex);
+ return ret;
+ }
+
+ public int addMethodType(int descriptorIndex) {
+ adjustSize();
+ int ret = poolSize;
+ pool[poolSize++] = new ConstantMethodType(descriptorIndex);
+ return ret;
+ }
// OPTIMIZE should put it in the cache now
public int addMethodref(String class_name, String method_name, String signature) {
@@ -651,6 +683,13 @@ public class ConstantPool implements Node {
pool[poolSize++] = new ConstantMethodref(class_index, name_and_type_index);
return ret;
}
+
+ public int addInvokeDynamic(int bootstrapMethodIndex, int constantNameAndTypeIndex) {
+ adjustSize();
+ int ret = poolSize;
+ pool[poolSize++] = new ConstantInvokeDynamic(bootstrapMethodIndex, constantNameAndTypeIndex);
+ return ret;
+ }
public int addInterfaceMethodref(String class_name, String method_name, String signature) {
int ret = lookupInterfaceMethodref(class_name, method_name, signature);
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionList.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionList.java
index 25f97836f..b08a2b77c 100644
--- a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionList.java
+++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionList.java
@@ -1150,7 +1150,6 @@ public class InstructionList implements Serializable {
public void replaceConstantPool(ConstantPool old_cp, ConstantPool new_cp) {
for (InstructionHandle ih = start; ih != null; ih = ih.next) {
Instruction i = ih.instruction;
-
if (i.isConstantPoolInstruction()) {
InstructionCP ci = (InstructionCP) i;
Constant c = old_cp.getConstant(ci.getIndex());
@@ -1165,7 +1164,7 @@ public class InstructionList implements Serializable {
}
/**
- * Delete contents of list. Provides besser memory utilization, because the system then may reuse the instruction handles. This
+ * Delete contents of list. Provides better memory utilization, because the system then may reuse the instruction handles. This
* method is typically called right after <href="MethodGen.html#getMethod()">MethodGen.getMethod()</a>.
*/
public void dispose() {