aboutsummaryrefslogtreecommitdiffstats
path: root/src/proguard/classfile/util/DynamicMemberReferenceInitializer.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/proguard/classfile/util/DynamicMemberReferenceInitializer.java')
-rw-r--r--src/proguard/classfile/util/DynamicMemberReferenceInitializer.java484
1 files changed, 72 insertions, 412 deletions
diff --git a/src/proguard/classfile/util/DynamicMemberReferenceInitializer.java b/src/proguard/classfile/util/DynamicMemberReferenceInitializer.java
index 110dc43..1f57708 100644
--- a/src/proguard/classfile/util/DynamicMemberReferenceInitializer.java
+++ b/src/proguard/classfile/util/DynamicMemberReferenceInitializer.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2011 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
@@ -55,20 +55,14 @@ implements InstructionVisitor,
AttributeVisitor,
MemberVisitor
{
- /*
- private static boolean DEBUG = true;
- /*/
- private static final boolean DEBUG = false;
- //*/
+ public static final int X = InstructionSequenceMatcher.X;
+ public static final int Y = InstructionSequenceMatcher.Y;
+ public static final int Z = InstructionSequenceMatcher.Z;
- public static final int CLASS_INDEX = InstructionSequenceMatcher.X;
- public static final int MEMBER_NAME_INDEX = InstructionSequenceMatcher.Y;
- public static final int TYPE_CLASS_INDEX = InstructionSequenceMatcher.Z;
-
- public static final int PARAMETER0_CLASS_INDEX = InstructionSequenceMatcher.A;
- public static final int PARAMETER1_CLASS_INDEX = InstructionSequenceMatcher.B;
- public static final int PARAMETER2_CLASS_INDEX = InstructionSequenceMatcher.C;
- public static final int PARAMETER3_CLASS_INDEX = InstructionSequenceMatcher.D;
+ public static final int A = InstructionSequenceMatcher.A;
+ public static final int B = InstructionSequenceMatcher.B;
+ public static final int C = InstructionSequenceMatcher.C;
+ public static final int D = InstructionSequenceMatcher.D;
private final Constant[] GET_FIELD_CONSTANTS = new Constant[]
@@ -91,26 +85,6 @@ implements InstructionVisitor,
new Utf8Constant(ClassConstants.INTERNAL_METHOD_TYPE_CLASS_GET_DECLARED_FIELD),
};
- private final Constant[] GET_CONSTRUCTOR_CONSTANTS = new Constant[]
- {
- new MethodrefConstant(1, 2, null, null),
- new ClassConstant(3, null),
- new NameAndTypeConstant(4, 5),
- new Utf8Constant(ClassConstants.INTERNAL_NAME_JAVA_LANG_CLASS),
- new Utf8Constant(ClassConstants.INTERNAL_CONSTRUCTOR_NAME_CLASS_GET_CONSTRUCTOR),
- new Utf8Constant(ClassConstants.INTERNAL_CONSTRUCTOR_TYPE_CLASS_GET_CONSTRUCTOR),
- };
-
- private final Constant[] GET_DECLARED_CONSTRUCTOR_CONSTANTS = new Constant[]
- {
- new MethodrefConstant(1, 2, null, null),
- new ClassConstant(3, null),
- new NameAndTypeConstant(4, 5),
- new Utf8Constant(ClassConstants.INTERNAL_NAME_JAVA_LANG_CLASS),
- new Utf8Constant(ClassConstants.INTERNAL_CONSTRUCTOR_NAME_CLASS_GET_DECLARED_CONSTRUCTOR),
- new Utf8Constant(ClassConstants.INTERNAL_CONSTRUCTOR_TYPE_CLASS_GET_DECLARED_CONSTRUCTOR),
- };
-
private final Constant[] GET_METHOD_CONSTANTS = new Constant[]
{
new MethodrefConstant(1, 2, null, null),
@@ -131,88 +105,19 @@ implements InstructionVisitor,
new Utf8Constant(ClassConstants.INTERNAL_METHOD_TYPE_CLASS_GET_DECLARED_METHOD),
};
- private final Constant[] NEW_INTEGER_UPDATER_CONSTANTS = new Constant[]
- {
- new MethodrefConstant(1, 2, null, null),
- new ClassConstant(3, null),
- new NameAndTypeConstant(4, 5),
- new Utf8Constant(ClassConstants.INTERNAL_NAME_JAVA_UTIL_CONCURRENT_ATOMIC_ATOMIC_INTEGER_FIELD_UPDATER),
- new Utf8Constant(ClassConstants.INTERNAL_METHOD_NAME_NEW_UPDATER),
- new Utf8Constant(ClassConstants.INTERNAL_METHOD_TYPE_NEW_INTEGER_UPDATER),
- };
-
- private final Constant[] NEW_LONG_UPDATER_CONSTANTS = new Constant[]
- {
- new MethodrefConstant(1, 2, null, null),
- new ClassConstant(3, null),
- new NameAndTypeConstant(4, 5),
- new Utf8Constant(ClassConstants.INTERNAL_NAME_JAVA_UTIL_CONCURRENT_ATOMIC_ATOMIC_LONG_FIELD_UPDATER),
- new Utf8Constant(ClassConstants.INTERNAL_METHOD_NAME_NEW_UPDATER),
- new Utf8Constant(ClassConstants.INTERNAL_METHOD_TYPE_NEW_LONG_UPDATER),
- };
-
- private final Constant[] NEW_REFERENCE_UPDATER_CONSTANTS = new Constant[]
- {
- new MethodrefConstant(1, 2, null, null),
- new ClassConstant(3, null),
- new NameAndTypeConstant(4, 5),
- new Utf8Constant(ClassConstants.INTERNAL_NAME_JAVA_UTIL_CONCURRENT_ATOMIC_ATOMIC_REFERENCE_FIELD_UPDATER),
- new Utf8Constant(ClassConstants.INTERNAL_METHOD_NAME_NEW_UPDATER),
- new Utf8Constant(ClassConstants.INTERNAL_METHOD_TYPE_NEW_REFERENCE_UPDATER),
- };
-
// SomeClass.class.get[Declared]Field("someField").
private final Instruction[] CONSTANT_GET_FIELD_INSTRUCTIONS = new Instruction[]
{
- new ConstantInstruction(InstructionConstants.OP_LDC, CLASS_INDEX),
- new ConstantInstruction(InstructionConstants.OP_LDC, MEMBER_NAME_INDEX),
+ new ConstantInstruction(InstructionConstants.OP_LDC, X),
+ new ConstantInstruction(InstructionConstants.OP_LDC, Y),
new ConstantInstruction(InstructionConstants.OP_INVOKEVIRTUAL, 0),
};
-// // SomeClass.class.get[Declared]Constructor(new Class[] {}).
-// private final Instruction[] CONSTANT_GET_CONSTRUCTOR_INSTRUCTIONS0 = new Instruction[]
-// {
-// new ConstantInstruction(InstructionConstants.OP_LDC, CLASS_INDEX),
-// new SimpleInstruction(InstructionConstants.OP_ICONST_0),
-// new ConstantInstruction(InstructionConstants.OP_ANEWARRAY, 1),
-// new ConstantInstruction(InstructionConstants.OP_INVOKEVIRTUAL, 0),
-// };
-//
-// // SomeClass.class.get[Declared]Constructor(new Class[] { A.class }).
-// private final Instruction[] CONSTANT_GET_CONSTRUCTOR_INSTRUCTIONS1 = new Instruction[]
-// {
-// new ConstantInstruction(InstructionConstants.OP_LDC, CLASS_INDEX),
-// new SimpleInstruction(InstructionConstants.OP_ICONST_1),
-// new ConstantInstruction(InstructionConstants.OP_ANEWARRAY, 1),
-// new SimpleInstruction(InstructionConstants.OP_DUP),
-// new SimpleInstruction(InstructionConstants.OP_ICONST_0),
-// new ConstantInstruction(InstructionConstants.OP_LDC, PARAMETER0_CLASS_INDEX),
-// new SimpleInstruction(InstructionConstants.OP_AASTORE),
-// new ConstantInstruction(InstructionConstants.OP_INVOKEVIRTUAL, 0),
-// };
-//
-// // SomeClass.class.get[Declared]Constructor(new Class[] { A.class, B.class }).
-// private final Instruction[] CONSTANT_GET_CONSTRUCTOR_INSTRUCTIONS2 = new Instruction[]
-// {
-// new ConstantInstruction(InstructionConstants.OP_LDC, CLASS_INDEX),
-// new SimpleInstruction(InstructionConstants.OP_ICONST_2),
-// new ConstantInstruction(InstructionConstants.OP_ANEWARRAY, 1),
-// new SimpleInstruction(InstructionConstants.OP_DUP),
-// new SimpleInstruction(InstructionConstants.OP_ICONST_0),
-// new ConstantInstruction(InstructionConstants.OP_LDC, PARAMETER0_CLASS_INDEX),
-// new SimpleInstruction(InstructionConstants.OP_AASTORE),
-// new SimpleInstruction(InstructionConstants.OP_DUP),
-// new SimpleInstruction(InstructionConstants.OP_ICONST_1),
-// new ConstantInstruction(InstructionConstants.OP_LDC, PARAMETER1_CLASS_INDEX),
-// new SimpleInstruction(InstructionConstants.OP_AASTORE),
-// new ConstantInstruction(InstructionConstants.OP_INVOKEVIRTUAL, 0),
-// };
-
// SomeClass.class.get[Declared]Method("someMethod", new Class[] {}).
private final Instruction[] CONSTANT_GET_METHOD_INSTRUCTIONS0 = new Instruction[]
{
- new ConstantInstruction(InstructionConstants.OP_LDC, CLASS_INDEX),
- new ConstantInstruction(InstructionConstants.OP_LDC, MEMBER_NAME_INDEX),
+ new ConstantInstruction(InstructionConstants.OP_LDC, X),
+ new ConstantInstruction(InstructionConstants.OP_LDC, Y),
new SimpleInstruction(InstructionConstants.OP_ICONST_0),
new ConstantInstruction(InstructionConstants.OP_ANEWARRAY, 1),
new ConstantInstruction(InstructionConstants.OP_INVOKEVIRTUAL, 0),
@@ -221,13 +126,13 @@ implements InstructionVisitor,
// SomeClass.class.get[Declared]Method("someMethod", new Class[] { A.class }).
private final Instruction[] CONSTANT_GET_METHOD_INSTRUCTIONS1 = new Instruction[]
{
- new ConstantInstruction(InstructionConstants.OP_LDC, CLASS_INDEX),
- new ConstantInstruction(InstructionConstants.OP_LDC, MEMBER_NAME_INDEX),
+ new ConstantInstruction(InstructionConstants.OP_LDC, X),
+ new ConstantInstruction(InstructionConstants.OP_LDC, Y),
new SimpleInstruction(InstructionConstants.OP_ICONST_1),
new ConstantInstruction(InstructionConstants.OP_ANEWARRAY, 1),
new SimpleInstruction(InstructionConstants.OP_DUP),
new SimpleInstruction(InstructionConstants.OP_ICONST_0),
- new ConstantInstruction(InstructionConstants.OP_LDC, PARAMETER0_CLASS_INDEX),
+ new ConstantInstruction(InstructionConstants.OP_LDC, A),
new SimpleInstruction(InstructionConstants.OP_AASTORE),
new ConstantInstruction(InstructionConstants.OP_INVOKEVIRTUAL, 0),
};
@@ -235,86 +140,32 @@ implements InstructionVisitor,
// SomeClass.class.get[Declared]Method("someMethod", new Class[] { A.class, B.class }).
private final Instruction[] CONSTANT_GET_METHOD_INSTRUCTIONS2 = new Instruction[]
{
- new ConstantInstruction(InstructionConstants.OP_LDC, CLASS_INDEX),
- new ConstantInstruction(InstructionConstants.OP_LDC, MEMBER_NAME_INDEX),
+ new ConstantInstruction(InstructionConstants.OP_LDC, X),
+ new ConstantInstruction(InstructionConstants.OP_LDC, Y),
new SimpleInstruction(InstructionConstants.OP_ICONST_2),
new ConstantInstruction(InstructionConstants.OP_ANEWARRAY, 1),
new SimpleInstruction(InstructionConstants.OP_DUP),
new SimpleInstruction(InstructionConstants.OP_ICONST_0),
- new ConstantInstruction(InstructionConstants.OP_LDC, PARAMETER0_CLASS_INDEX),
+ new ConstantInstruction(InstructionConstants.OP_LDC, A),
new SimpleInstruction(InstructionConstants.OP_AASTORE),
new SimpleInstruction(InstructionConstants.OP_DUP),
new SimpleInstruction(InstructionConstants.OP_ICONST_1),
- new ConstantInstruction(InstructionConstants.OP_LDC, PARAMETER1_CLASS_INDEX),
+ new ConstantInstruction(InstructionConstants.OP_LDC, B),
new SimpleInstruction(InstructionConstants.OP_AASTORE),
new ConstantInstruction(InstructionConstants.OP_INVOKEVIRTUAL, 0),
};
- // AtomicIntegerFieldUpdater.newUpdater(A.class, "someField").
- // AtomicLongFieldUpdater.newUpdater(A.class, "someField").
- private final Instruction[] CONSTANT_NEW_PRIMITIVE_UPDATER_INSTRUCTIONS = new Instruction[]
- {
- new ConstantInstruction(InstructionConstants.OP_LDC, CLASS_INDEX),
- new ConstantInstruction(InstructionConstants.OP_LDC, MEMBER_NAME_INDEX),
- new ConstantInstruction(InstructionConstants.OP_INVOKESTATIC, 0),
- };
-
- // AtomicReferenceFieldUpdater.newUpdater(A.class, B.class, "someField").
- private final Instruction[] CONSTANT_NEW_REFERENCE_UPDATER_INSTRUCTIONS = new Instruction[]
- {
- new ConstantInstruction(InstructionConstants.OP_LDC, CLASS_INDEX),
- new ConstantInstruction(InstructionConstants.OP_LDC, TYPE_CLASS_INDEX),
- new ConstantInstruction(InstructionConstants.OP_LDC, MEMBER_NAME_INDEX),
- new ConstantInstruction(InstructionConstants.OP_INVOKESTATIC, 0),
- };
-
// get[Declared]Field("someField").
private final Instruction[] GET_FIELD_INSTRUCTIONS = new Instruction[]
{
- new ConstantInstruction(InstructionConstants.OP_LDC, MEMBER_NAME_INDEX),
- new ConstantInstruction(InstructionConstants.OP_INVOKEVIRTUAL, 0),
- };
-
-// // get[Declared]Constructor(new Class[] {}).
-// private final Instruction[] GET_CONSTRUCTOR_INSTRUCTIONS0 = new Instruction[]
-// {
-// new SimpleInstruction(InstructionConstants.OP_ICONST_0),
-// new ConstantInstruction(InstructionConstants.OP_ANEWARRAY, 1),
-// new ConstantInstruction(InstructionConstants.OP_INVOKEVIRTUAL, 0),
-// };
-
- // get[Declared]Constructor(new Class[] { A.class }).
- private final Instruction[] GET_CONSTRUCTOR_INSTRUCTIONS1 = new Instruction[]
- {
- new SimpleInstruction(InstructionConstants.OP_ICONST_1),
- new ConstantInstruction(InstructionConstants.OP_ANEWARRAY, 1),
- new SimpleInstruction(InstructionConstants.OP_DUP),
- new SimpleInstruction(InstructionConstants.OP_ICONST_0),
- new ConstantInstruction(InstructionConstants.OP_LDC, PARAMETER0_CLASS_INDEX),
- new SimpleInstruction(InstructionConstants.OP_AASTORE),
- new ConstantInstruction(InstructionConstants.OP_INVOKEVIRTUAL, 0),
- };
-
- // get[Declared]Constructor(new Class[] { A.class, B.class }).
- private final Instruction[] GET_CONSTRUCTOR_INSTRUCTIONS2 = new Instruction[]
- {
- new SimpleInstruction(InstructionConstants.OP_ICONST_2),
- new ConstantInstruction(InstructionConstants.OP_ANEWARRAY, 1),
- new SimpleInstruction(InstructionConstants.OP_DUP),
- new SimpleInstruction(InstructionConstants.OP_ICONST_0),
- new ConstantInstruction(InstructionConstants.OP_LDC, PARAMETER0_CLASS_INDEX),
- new SimpleInstruction(InstructionConstants.OP_AASTORE),
- new SimpleInstruction(InstructionConstants.OP_DUP),
- new SimpleInstruction(InstructionConstants.OP_ICONST_1),
- new ConstantInstruction(InstructionConstants.OP_LDC, PARAMETER1_CLASS_INDEX),
- new SimpleInstruction(InstructionConstants.OP_AASTORE),
+ new ConstantInstruction(InstructionConstants.OP_LDC, Y),
new ConstantInstruction(InstructionConstants.OP_INVOKEVIRTUAL, 0),
};
// get[Declared]Method("someMethod", new Class[] {}).
private final Instruction[] GET_METHOD_INSTRUCTIONS0 = new Instruction[]
{
- new ConstantInstruction(InstructionConstants.OP_LDC, MEMBER_NAME_INDEX),
+ new ConstantInstruction(InstructionConstants.OP_LDC, Y),
new SimpleInstruction(InstructionConstants.OP_ICONST_0),
new ConstantInstruction(InstructionConstants.OP_ANEWARRAY, 1),
new ConstantInstruction(InstructionConstants.OP_INVOKEVIRTUAL, 0),
@@ -323,12 +174,12 @@ implements InstructionVisitor,
// get[Declared]Method("someMethod", new Class[] { A.class }).
private final Instruction[] GET_METHOD_INSTRUCTIONS1 = new Instruction[]
{
- new ConstantInstruction(InstructionConstants.OP_LDC, MEMBER_NAME_INDEX),
+ new ConstantInstruction(InstructionConstants.OP_LDC, Y),
new SimpleInstruction(InstructionConstants.OP_ICONST_1),
new ConstantInstruction(InstructionConstants.OP_ANEWARRAY, 1),
new SimpleInstruction(InstructionConstants.OP_DUP),
new SimpleInstruction(InstructionConstants.OP_ICONST_0),
- new ConstantInstruction(InstructionConstants.OP_LDC, PARAMETER0_CLASS_INDEX),
+ new ConstantInstruction(InstructionConstants.OP_LDC, A),
new SimpleInstruction(InstructionConstants.OP_AASTORE),
new ConstantInstruction(InstructionConstants.OP_INVOKEVIRTUAL, 0),
};
@@ -336,29 +187,20 @@ implements InstructionVisitor,
// get[Declared]Method("someMethod", new Class[] { A.class, B.class }).
private final Instruction[] GET_METHOD_INSTRUCTIONS2 = new Instruction[]
{
- new ConstantInstruction(InstructionConstants.OP_LDC, MEMBER_NAME_INDEX),
+ new ConstantInstruction(InstructionConstants.OP_LDC, Y),
new SimpleInstruction(InstructionConstants.OP_ICONST_2),
new ConstantInstruction(InstructionConstants.OP_ANEWARRAY, 1),
new SimpleInstruction(InstructionConstants.OP_DUP),
new SimpleInstruction(InstructionConstants.OP_ICONST_0),
- new ConstantInstruction(InstructionConstants.OP_LDC, PARAMETER0_CLASS_INDEX),
+ new ConstantInstruction(InstructionConstants.OP_LDC, A),
new SimpleInstruction(InstructionConstants.OP_AASTORE),
new SimpleInstruction(InstructionConstants.OP_DUP),
new SimpleInstruction(InstructionConstants.OP_ICONST_1),
- new ConstantInstruction(InstructionConstants.OP_LDC, PARAMETER1_CLASS_INDEX),
+ new ConstantInstruction(InstructionConstants.OP_LDC, B),
new SimpleInstruction(InstructionConstants.OP_AASTORE),
new ConstantInstruction(InstructionConstants.OP_INVOKEVIRTUAL, 0),
};
- // AtomicIntegerFieldUpdater.newUpdater(..., "someField").
- // AtomicLongFieldUpdater.newUpdater(..., "someField").
- // AtomicReferenceFieldUpdater.newUpdater(..., "someField").
- private final Instruction[] NEW_UPDATER_INSTRUCTIONS = new Instruction[]
- {
- new ConstantInstruction(InstructionConstants.OP_LDC, MEMBER_NAME_INDEX),
- new ConstantInstruction(InstructionConstants.OP_INVOKESTATIC, 0),
- };
-
private final ClassPool programClassPool;
private final ClassPool libraryClassPool;
@@ -375,30 +217,6 @@ implements InstructionVisitor,
new InstructionSequenceMatcher(GET_DECLARED_FIELD_CONSTANTS,
CONSTANT_GET_FIELD_INSTRUCTIONS);
-// private final InstructionSequenceMatcher constantGetConstructorMatcher0 =
-// new InstructionSequenceMatcher(GET_CONSTRUCTOR_CONSTANTS,
-// CONSTANT_GET_CONSTRUCTOR_INSTRUCTIONS0);
-//
-// private final InstructionSequenceMatcher constantGetDeclaredConstructorMatcher0 =
-// new InstructionSequenceMatcher(GET_DECLARED_CONSTRUCTOR_CONSTANTS,
-// CONSTANT_GET_CONSTRUCTOR_INSTRUCTIONS0);
-//
-// private final InstructionSequenceMatcher constantGetConstructorMatcher1 =
-// new InstructionSequenceMatcher(GET_CONSTRUCTOR_CONSTANTS,
-// CONSTANT_GET_CONSTRUCTOR_INSTRUCTIONS1);
-//
-// private final InstructionSequenceMatcher constantGetDeclaredConstructorMatcher1 =
-// new InstructionSequenceMatcher(GET_DECLARED_CONSTRUCTOR_CONSTANTS,
-// CONSTANT_GET_CONSTRUCTOR_INSTRUCTIONS1);
-//
-// private final InstructionSequenceMatcher constantGetConstructorMatcher2 =
-// new InstructionSequenceMatcher(GET_CONSTRUCTOR_CONSTANTS,
-// CONSTANT_GET_CONSTRUCTOR_INSTRUCTIONS2);
-//
-// private final InstructionSequenceMatcher constantGetDeclaredConstructorMatcher2 =
-// new InstructionSequenceMatcher(GET_DECLARED_CONSTRUCTOR_CONSTANTS,
-// CONSTANT_GET_CONSTRUCTOR_INSTRUCTIONS2);
-
private final InstructionSequenceMatcher constantGetMethodMatcher0 =
new InstructionSequenceMatcher(GET_METHOD_CONSTANTS,
CONSTANT_GET_METHOD_INSTRUCTIONS0);
@@ -423,18 +241,6 @@ implements InstructionVisitor,
new InstructionSequenceMatcher(GET_DECLARED_METHOD_CONSTANTS,
CONSTANT_GET_METHOD_INSTRUCTIONS2);
- private final InstructionSequenceMatcher constantGetIntegerUpdaterMatcher =
- new InstructionSequenceMatcher(NEW_INTEGER_UPDATER_CONSTANTS,
- CONSTANT_NEW_PRIMITIVE_UPDATER_INSTRUCTIONS);
-
- private final InstructionSequenceMatcher constantGetLongUpdaterMatcher =
- new InstructionSequenceMatcher(NEW_LONG_UPDATER_CONSTANTS,
- CONSTANT_NEW_PRIMITIVE_UPDATER_INSTRUCTIONS);
-
- private final InstructionSequenceMatcher constantGetReferenceUpdaterMatcher =
- new InstructionSequenceMatcher(NEW_REFERENCE_UPDATER_CONSTANTS,
- CONSTANT_NEW_REFERENCE_UPDATER_INSTRUCTIONS);
-
private final InstructionSequenceMatcher getFieldMatcher =
new InstructionSequenceMatcher(GET_FIELD_CONSTANTS,
GET_FIELD_INSTRUCTIONS);
@@ -443,30 +249,6 @@ implements InstructionVisitor,
new InstructionSequenceMatcher(GET_DECLARED_FIELD_CONSTANTS,
GET_FIELD_INSTRUCTIONS);
-// private final InstructionSequenceMatcher getConstructorMatcher0 =
-// new InstructionSequenceMatcher(GET_CONSTRUCTOR_CONSTANTS,
-// GET_CONSTRUCTOR_INSTRUCTIONS0);
-//
-// private final InstructionSequenceMatcher getDeclaredConstructorMatcher0 =
-// new InstructionSequenceMatcher(GET_DECLARED_CONSTRUCTOR_CONSTANTS,
-// GET_CONSTRUCTOR_INSTRUCTIONS0);
-
- private final InstructionSequenceMatcher getConstructorMatcher1 =
- new InstructionSequenceMatcher(GET_CONSTRUCTOR_CONSTANTS,
- GET_CONSTRUCTOR_INSTRUCTIONS1);
-
- private final InstructionSequenceMatcher getDeclaredConstructorMatcher1 =
- new InstructionSequenceMatcher(GET_DECLARED_CONSTRUCTOR_CONSTANTS,
- GET_CONSTRUCTOR_INSTRUCTIONS1);
-
- private final InstructionSequenceMatcher getConstructorMatcher2 =
- new InstructionSequenceMatcher(GET_CONSTRUCTOR_CONSTANTS,
- GET_CONSTRUCTOR_INSTRUCTIONS2);
-
- private final InstructionSequenceMatcher getDeclaredConstructorMatcher2 =
- new InstructionSequenceMatcher(GET_DECLARED_CONSTRUCTOR_CONSTANTS,
- GET_CONSTRUCTOR_INSTRUCTIONS2);
-
private final InstructionSequenceMatcher getMethodMatcher0 =
new InstructionSequenceMatcher(GET_METHOD_CONSTANTS,
GET_METHOD_INSTRUCTIONS0);
@@ -491,24 +273,11 @@ implements InstructionVisitor,
new InstructionSequenceMatcher(GET_DECLARED_METHOD_CONSTANTS,
GET_METHOD_INSTRUCTIONS2);
- private final InstructionSequenceMatcher getIntegerUpdaterMatcher =
- new InstructionSequenceMatcher(NEW_INTEGER_UPDATER_CONSTANTS,
- NEW_UPDATER_INSTRUCTIONS);
-
- private final InstructionSequenceMatcher getLongUpdaterMatcher =
- new InstructionSequenceMatcher(NEW_LONG_UPDATER_CONSTANTS,
- NEW_UPDATER_INSTRUCTIONS);
-
- private final InstructionSequenceMatcher getReferenceUpdaterMatcher =
- new InstructionSequenceMatcher(NEW_REFERENCE_UPDATER_CONSTANTS,
- NEW_UPDATER_INSTRUCTIONS);
-
private final MemberFinder memberFinder = new MemberFinder();
// Fields acting as parameters for the visitors.
private Clazz referencedClass;
- private String descriptor;
private boolean isDeclared;
private boolean isField;
@@ -538,110 +307,48 @@ implements InstructionVisitor,
// Try to match the SomeClass.class.getField("someField") construct.
matchGetMember(clazz, method, codeAttribute, offset, instruction,
constantGetFieldMatcher,
- getFieldMatcher, true, false, null, null);
+ getFieldMatcher, true, false);
// Try to match the SomeClass.class.getDeclaredField("someField") construct.
matchGetMember(clazz, method, codeAttribute, offset, instruction,
constantGetDeclaredFieldMatcher,
- getDeclaredFieldMatcher, true, true, null, null);
-
-// // Try to match the SomeClass.class.getConstructor(new Class[]
-// // {}) construct.
-// matchGetMember(clazz, method, codeAttribute, offset, instruction,
-// cnull, //onstantGetConstructorMatcher0,
-// getConstructorMatcher0, false, false,
-// ClassConstants.INTERNAL_METHOD_NAME_INIT, null);
-//
-// // Try to match the SomeClass.class.getDeclaredConstructor(new Class[]
-// // {}) construct.
-// matchGetMember(clazz, method, codeAttribute, offset, instruction,
-// null, //constantGetDeclaredConstructorMatcher0,
-// getDeclaredConstructorMatcher0, false, true,
-// ClassConstants.INTERNAL_METHOD_NAME_INIT, null);
-
- // Try to match the SomeClass.class.getConstructor(new Class[]
- // { A.class }) construct.
- matchGetMember(clazz, method, codeAttribute, offset, instruction,
- null, //constantGetConstructorMatcher1,
- getConstructorMatcher1, false, false,
- ClassConstants.INTERNAL_METHOD_NAME_INIT, null);
-
- // Try to match the SomeClass.class.getDeclaredConstructor(new Class[]
- // { A.class }) construct.
- matchGetMember(clazz, method, codeAttribute, offset, instruction,
- null, //constantGetDeclaredConstructorMatcher1,
- getDeclaredConstructorMatcher1, false, true,
- ClassConstants.INTERNAL_METHOD_NAME_INIT, null);
-
- // Try to match the SomeClass.class.getConstructor(new Class[]
- // { A.class, B.class }) construct.
- matchGetMember(clazz, method, codeAttribute, offset, instruction,
- null, //constantGetConstructorMatcher2,
- getConstructorMatcher2, false, false,
- ClassConstants.INTERNAL_METHOD_NAME_INIT, null);
-
- // Try to match the SomeClass.class.getDeclaredConstructor(new Class[]
- // { A.class, B.class }) construct.
- matchGetMember(clazz, method, codeAttribute, offset, instruction,
- null, //constantGetDeclaredConstructorMatcher2,
- getDeclaredConstructorMatcher2, false, true,
- ClassConstants.INTERNAL_METHOD_NAME_INIT, null);
+ getDeclaredFieldMatcher, true, true);
// Try to match the SomeClass.class.getMethod("someMethod", new Class[]
// {}) construct.
matchGetMember(clazz, method, codeAttribute, offset, instruction,
constantGetMethodMatcher0,
- getMethodMatcher0, false, false, null, null);
+ getMethodMatcher0, false, false);
// Try to match the SomeClass.class.getDeclaredMethod("someMethod",
- // new Class[] {}) construct.
+ // new Class[] {}) construct.
matchGetMember(clazz, method, codeAttribute, offset, instruction,
constantGetDeclaredMethodMatcher0,
- getDeclaredMethodMatcher0, false, true, null, null);
+ getDeclaredMethodMatcher0, false, true);
// Try to match the SomeClass.class.getMethod("someMethod", new Class[]
// { A.class }) construct.
matchGetMember(clazz, method, codeAttribute, offset, instruction,
constantGetMethodMatcher1,
- getMethodMatcher1, false, false, null, null);
+ getMethodMatcher1, false, false);
// Try to match the SomeClass.class.getDeclaredMethod("someMethod",
// new Class[] { A.class }) construct.
matchGetMember(clazz, method, codeAttribute, offset, instruction,
constantGetDeclaredMethodMatcher1,
- getDeclaredMethodMatcher1, false, true, null, null);
+ getDeclaredMethodMatcher1, false, true);
// Try to match the SomeClass.class.getMethod("someMethod", new Class[]
// { A.class, B.class }) construct.
matchGetMember(clazz, method, codeAttribute, offset, instruction,
constantGetMethodMatcher2,
- getMethodMatcher2, false, false, null, null);
+ getMethodMatcher2, false, false);
// Try to match the SomeClass.class.getDeclaredMethod("someMethod",
- // new Class[] { A.class, B.class }) construct.
+ // new Class[] { A.class, B.class }) construct.
matchGetMember(clazz, method, codeAttribute, offset, instruction,
constantGetDeclaredMethodMatcher2,
- getDeclaredMethodMatcher2, false, true, null, null);
-
- // Try to match the AtomicIntegerFieldUpdater.newUpdater(
- // SomeClass.class, "someField") construct.
- matchGetMember(clazz, method, codeAttribute, offset, instruction,
- constantGetIntegerUpdaterMatcher,
- getIntegerUpdaterMatcher, true, false, null,
- "" + ClassConstants.INTERNAL_TYPE_INT);
-
- // Try to match the AtomicLongFieldUpdater.newUpdater(
- // SomeClass.class, "someField") construct.
- matchGetMember(clazz, method, codeAttribute, offset, instruction,
- constantGetLongUpdaterMatcher,
- getLongUpdaterMatcher, true, false, null,
- "" + ClassConstants.INTERNAL_TYPE_LONG);
-
- // Try to match the AtomicReferenceFieldUpdater.newUpdater(
- // SomeClass.class, SomeClass.class, "someField") construct.
- matchGetMember(clazz, method, codeAttribute, offset, instruction,
- constantGetReferenceUpdaterMatcher,
- getReferenceUpdaterMatcher, true, false, null, null);
+ getDeclaredMethodMatcher2, false, true);
}
@@ -657,28 +364,26 @@ implements InstructionVisitor,
InstructionSequenceMatcher constantSequenceMatcher,
InstructionSequenceMatcher variableSequenceMatcher,
boolean isField,
- boolean isDeclared,
- String defaultName,
- String defaultDescriptor)
+ boolean isDeclared)
{
- if (constantSequenceMatcher != null)
+ // Try to match the next instruction in the constant sequence.
+ instruction.accept(clazz, method, codeAttribute, offset,
+ constantSequenceMatcher);
+
+ // Did we find a match to fill out the string constant?
+ if (constantSequenceMatcher.isMatching())
{
- // Try to match the next instruction in the constant sequence.
- instruction.accept(clazz, method, codeAttribute, offset,
- constantSequenceMatcher);
+ this.isField = isField;
+ this.isDeclared = isDeclared;
- // Did we find a match to fill out the string constant?
- if (constantSequenceMatcher.isMatching())
- {
- initializeStringReference(clazz,
- constantSequenceMatcher,
- isField,
- isDeclared,
- defaultDescriptor);
-
- // Don't look for the dynamic construct.
- variableSequenceMatcher.reset();
- }
+ // Get the member's class.
+ clazz.constantPoolEntryAccept(constantSequenceMatcher.matchedConstantIndex(X), this);
+
+ // Fill out the matched string constant.
+ clazz.constantPoolEntryAccept(constantSequenceMatcher.matchedConstantIndex(Y), this);
+
+ // Don't look for the dynamic construct.
+ variableSequenceMatcher.reset();
}
// Try to match the next instruction in the variable sequence.
@@ -692,41 +397,11 @@ implements InstructionVisitor,
printDynamicInvocationNote(clazz,
variableSequenceMatcher,
isField,
- isDeclared,
- defaultName,
- defaultDescriptor);
+ isDeclared);
}
}
- /**
- * Initializes the reference of the matched string constant to the
- * referenced class member and its class.
- */
- private void initializeStringReference(Clazz clazz,
- InstructionSequenceMatcher constantSequenceMatcher,
- boolean isField,
- boolean isDeclared,
- String defaultDescriptor)
- {
- this.isField = isField;
- this.isDeclared = isDeclared;
-
- // Get the member's class.
- int classIndex = constantSequenceMatcher.matchedConstantIndex(CLASS_INDEX);
- clazz.constantPoolEntryAccept(classIndex, this);
-
- // Get the field's reference type, if applicable.
- int typeClassIndex = constantSequenceMatcher.matchedConstantIndex(TYPE_CLASS_INDEX);
- descriptor = typeClassIndex <= 0 ? defaultDescriptor :
- ClassUtil.internalTypeFromClassName(clazz.getClassName(typeClassIndex));
-
- // Fill out the matched string constant.
- int memberNameIndex = constantSequenceMatcher.matchedConstantIndex(MEMBER_NAME_INDEX);
- clazz.constantPoolEntryAccept(memberNameIndex, this);
- }
-
-
// Implementations for ConstantVisitor.
/**
@@ -734,11 +409,6 @@ implements InstructionVisitor,
*/
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
- if (DEBUG)
- {
- System.out.println("DynamicMemberReferenceInitializer: ["+clazz.getName()+"] matched class ["+classConstant.getName(clazz)+"]");
- }
-
// Remember the referenced class.
referencedClass = ClassUtil.isInternalArrayType(classConstant.getName(clazz)) ?
null :
@@ -755,20 +425,15 @@ implements InstructionVisitor,
{
String name = stringConstant.getString(clazz);
- if (DEBUG)
- {
- System.out.println("DynamicMemberReferenceInitializer: ["+clazz.getName()+"] matched string ["+name+"]");
- }
-
// See if we can find the referenced class member locally, or
// somewhere in the hierarchy.
Member referencedMember = isDeclared ? isField ?
- (Member)referencedClass.findField(name, descriptor) :
- (Member)referencedClass.findMethod(name, descriptor) :
+ (Member)referencedClass.findField(name, null) :
+ (Member)referencedClass.findMethod(name, null) :
(Member)memberFinder.findMember(clazz,
referencedClass,
name,
- descriptor,
+ null,
isField);
if (referencedMember != null)
{
@@ -789,9 +454,7 @@ implements InstructionVisitor,
private void printDynamicInvocationNote(Clazz clazz,
InstructionSequenceMatcher noteSequenceMatcher,
boolean isField,
- boolean isDeclared,
- String defaultName,
- String defaultDescriptor)
+ boolean isDeclared)
{
// Print out a note about the dynamic invocation.
if (notePrinter != null &&
@@ -802,9 +465,8 @@ implements InstructionVisitor,
noteFieldExceptionMatcher :
noteMethodExceptionMatcher;
- int memberNameIndex = noteSequenceMatcher.matchedConstantIndex(MEMBER_NAME_INDEX);
- String memberName = memberNameIndex <= 0 ? defaultName :
- clazz.getStringString(memberNameIndex);
+ int memberNameIndex = noteSequenceMatcher.matchedConstantIndex(Y);
+ String memberName = clazz.getStringString(memberNameIndex);
if (noteExceptionMatcher == null ||
!noteExceptionMatcher.matches(memberName))
@@ -817,8 +479,7 @@ implements InstructionVisitor,
externalMemberDescription += '(';
for (int count = 0; count < 2; count++)
{
- int memberArgumentIndex = noteSequenceMatcher.matchedConstantIndex(
- PARAMETER0_CLASS_INDEX + count);
+ int memberArgumentIndex = noteSequenceMatcher.matchedConstantIndex(A + count);
if (memberArgumentIndex > 0)
{
if (count > 0)
@@ -840,9 +501,7 @@ implements InstructionVisitor,
ClassUtil.externalClassName(clazz.getName()) +
" accesses a " +
(isDeclared ? "declared " : "") +
- (isField ? "field" :
- memberName.equals(ClassConstants.INTERNAL_METHOD_NAME_INIT) ?
- "constructor" : "method") +
+ (isField ? "field" : "method") +
" '" +
externalMemberDescription +
"' dynamically");
@@ -852,12 +511,9 @@ implements InstructionVisitor,
if (isField)
{
- classVisitor = defaultDescriptor == null ?
- new AllFieldVisitor(
- new MemberNameFilter(memberName, this)) :
+ classVisitor =
new AllFieldVisitor(
- new MemberNameFilter(memberName,
- new MemberDescriptorFilter(defaultDescriptor, this)));
+ new MemberNameFilter(memberName, this));
}
else
{
@@ -865,16 +521,20 @@ implements InstructionVisitor,
String methodDescriptor = "(";
for (int count = 0; count < 2; count++)
{
- int memberArgumentIndex = noteSequenceMatcher.matchedConstantIndex(PARAMETER0_CLASS_INDEX + count);
+ int memberArgumentIndex = noteSequenceMatcher.matchedConstantIndex(A + count);
if (memberArgumentIndex > 0)
{
+ if (count > 0)
+ {
+ methodDescriptor += ',';
+ }
String className = clazz.getClassName(memberArgumentIndex);
methodDescriptor += ClassUtil.isInternalArrayType(className) ?
className :
ClassUtil.internalTypeFromClassName(className);
}
}
- methodDescriptor += ")L***;";
+ methodDescriptor += ")L///;";
classVisitor =
new AllMethodVisitor(
@@ -911,7 +571,7 @@ implements InstructionVisitor,
System.out.println(" Maybe this is program method '" +
ClassUtil.externalFullClassDescription(0, programClass.getName()) +
" { " +
- ClassUtil.externalFullMethodDescription(programClass.getName(), 0, programMethod.getName(programClass), programMethod.getDescriptor(programClass)) +
+ ClassUtil.externalFullMethodDescription(null, 0, programMethod.getName(programClass), programMethod.getDescriptor(programClass)) +
"; }'");
}
}
@@ -937,7 +597,7 @@ implements InstructionVisitor,
System.out.println(" Maybe this is library method '" +
ClassUtil.externalFullClassDescription(0, libraryClass.getName()) +
" { " +
- ClassUtil.externalFullMethodDescription(libraryClass.getName(), 0, libraryMethod.getName(libraryClass), libraryMethod.getDescriptor(libraryClass)) +
+ ClassUtil.externalFullMethodDescription(null, 0, libraryMethod.getName(libraryClass), libraryMethod.getDescriptor(libraryClass)) +
"; }'");
}
}