proj_name
stringclasses
91 values
relative_path
stringclasses
558 values
class_name
stringclasses
959 values
func_name
stringlengths
1
70
masked_class
stringlengths
69
162k
func_body
stringlengths
0
30.5k
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/LineNumberAttribute.java
LineNumberAttribute
tableLength
class LineNumberAttribute extends AttributeInfo { /** * The name of this attribute <code>"LineNumberTable"</code>. */ public static final String tag = "LineNumberTable"; LineNumberAttribute(ConstPool cp, int n, DataInputStream in) throws IOException { super(cp, n, in); } private LineNumberAttribute(ConstPool cp, byte[] i) { super(cp, tag, i); } /** * Returns <code>line_number_table_length</code>. * This represents the number of entries in the table. */ public int tableLength() {<FILL_FUNCTION_BODY>} /** * Returns <code>line_number_table[i].start_pc</code>. * This represents the index into the code array at which the code * for a new line in the original source file begins. * * @param i the i-th entry. */ public int startPc(int i) { return ByteArray.readU16bit(info, i * 4 + 2); } /** * Returns <code>line_number_table[i].line_number</code>. * This represents the corresponding line number in the original * source file. * * @param i the i-th entry. */ public int lineNumber(int i) { return ByteArray.readU16bit(info, i * 4 + 4); } /** * Returns the line number corresponding to the specified bytecode. * * @param pc the index into the code array. */ public int toLineNumber(int pc) { int n = tableLength(); int i = 0; for (; i < n; ++i) if (pc < startPc(i)) if (i == 0) return lineNumber(0); else break; return lineNumber(i - 1); } /** * Returns the index into the code array at which the code for * the specified line begins. * * @param line the line number. * @return -1 if the specified line is not found. */ public int toStartPc(int line) { int n = tableLength(); for (int i = 0; i < n; ++i) if (line == lineNumber(i)) return startPc(i); return -1; } /** * Used as a return type of <code>toNearPc()</code>. */ static public class Pc { /** * The index into the code array. */ public int index; /** * The line number. */ public int line; } /** * Returns the index into the code array at which the code for * the specified line (or the nearest line after the specified one) * begins. * * @param line the line number. * @return a pair of the index and the line number of the * bytecode at that index. */ public Pc toNearPc(int line) { int n = tableLength(); int nearPc = 0; int distance = 0; if (n > 0) { distance = lineNumber(0) - line; nearPc = startPc(0); } for (int i = 1; i < n; ++i) { int d = lineNumber(i) - line; if ((d < 0 && d > distance) || (d >= 0 && (d < distance || distance < 0))) { distance = d; nearPc = startPc(i); } } Pc res = new Pc(); res.index = nearPc; res.line = line + distance; return res; } /** * Makes a copy. * * @param newCp the constant pool table used by the new copy. * @param classnames should be null. */ @Override public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) { byte[] src = info; int num = src.length; byte[] dest = new byte[num]; for (int i = 0; i < num; ++i) dest[i] = src[i]; LineNumberAttribute attr = new LineNumberAttribute(newCp, dest); return attr; } /** * Adjusts start_pc if bytecode is inserted in a method body. */ void shiftPc(int where, int gapLength, boolean exclusive) { int n = tableLength(); for (int i = 0; i < n; ++i) { int pos = i * 4 + 2; int pc = ByteArray.readU16bit(info, pos); if (pc > where || (exclusive && pc == where)) ByteArray.write16bit(pc + gapLength, info, pos); } } }
return ByteArray.readU16bit(info, 0);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/LineNumberAttribute.java
LineNumberAttribute
startPc
class LineNumberAttribute extends AttributeInfo { /** * The name of this attribute <code>"LineNumberTable"</code>. */ public static final String tag = "LineNumberTable"; LineNumberAttribute(ConstPool cp, int n, DataInputStream in) throws IOException { super(cp, n, in); } private LineNumberAttribute(ConstPool cp, byte[] i) { super(cp, tag, i); } /** * Returns <code>line_number_table_length</code>. * This represents the number of entries in the table. */ public int tableLength() { return ByteArray.readU16bit(info, 0); } /** * Returns <code>line_number_table[i].start_pc</code>. * This represents the index into the code array at which the code * for a new line in the original source file begins. * * @param i the i-th entry. */ public int startPc(int i) {<FILL_FUNCTION_BODY>} /** * Returns <code>line_number_table[i].line_number</code>. * This represents the corresponding line number in the original * source file. * * @param i the i-th entry. */ public int lineNumber(int i) { return ByteArray.readU16bit(info, i * 4 + 4); } /** * Returns the line number corresponding to the specified bytecode. * * @param pc the index into the code array. */ public int toLineNumber(int pc) { int n = tableLength(); int i = 0; for (; i < n; ++i) if (pc < startPc(i)) if (i == 0) return lineNumber(0); else break; return lineNumber(i - 1); } /** * Returns the index into the code array at which the code for * the specified line begins. * * @param line the line number. * @return -1 if the specified line is not found. */ public int toStartPc(int line) { int n = tableLength(); for (int i = 0; i < n; ++i) if (line == lineNumber(i)) return startPc(i); return -1; } /** * Used as a return type of <code>toNearPc()</code>. */ static public class Pc { /** * The index into the code array. */ public int index; /** * The line number. */ public int line; } /** * Returns the index into the code array at which the code for * the specified line (or the nearest line after the specified one) * begins. * * @param line the line number. * @return a pair of the index and the line number of the * bytecode at that index. */ public Pc toNearPc(int line) { int n = tableLength(); int nearPc = 0; int distance = 0; if (n > 0) { distance = lineNumber(0) - line; nearPc = startPc(0); } for (int i = 1; i < n; ++i) { int d = lineNumber(i) - line; if ((d < 0 && d > distance) || (d >= 0 && (d < distance || distance < 0))) { distance = d; nearPc = startPc(i); } } Pc res = new Pc(); res.index = nearPc; res.line = line + distance; return res; } /** * Makes a copy. * * @param newCp the constant pool table used by the new copy. * @param classnames should be null. */ @Override public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) { byte[] src = info; int num = src.length; byte[] dest = new byte[num]; for (int i = 0; i < num; ++i) dest[i] = src[i]; LineNumberAttribute attr = new LineNumberAttribute(newCp, dest); return attr; } /** * Adjusts start_pc if bytecode is inserted in a method body. */ void shiftPc(int where, int gapLength, boolean exclusive) { int n = tableLength(); for (int i = 0; i < n; ++i) { int pos = i * 4 + 2; int pc = ByteArray.readU16bit(info, pos); if (pc > where || (exclusive && pc == where)) ByteArray.write16bit(pc + gapLength, info, pos); } } }
return ByteArray.readU16bit(info, i * 4 + 2);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/LineNumberAttribute.java
LineNumberAttribute
lineNumber
class LineNumberAttribute extends AttributeInfo { /** * The name of this attribute <code>"LineNumberTable"</code>. */ public static final String tag = "LineNumberTable"; LineNumberAttribute(ConstPool cp, int n, DataInputStream in) throws IOException { super(cp, n, in); } private LineNumberAttribute(ConstPool cp, byte[] i) { super(cp, tag, i); } /** * Returns <code>line_number_table_length</code>. * This represents the number of entries in the table. */ public int tableLength() { return ByteArray.readU16bit(info, 0); } /** * Returns <code>line_number_table[i].start_pc</code>. * This represents the index into the code array at which the code * for a new line in the original source file begins. * * @param i the i-th entry. */ public int startPc(int i) { return ByteArray.readU16bit(info, i * 4 + 2); } /** * Returns <code>line_number_table[i].line_number</code>. * This represents the corresponding line number in the original * source file. * * @param i the i-th entry. */ public int lineNumber(int i) {<FILL_FUNCTION_BODY>} /** * Returns the line number corresponding to the specified bytecode. * * @param pc the index into the code array. */ public int toLineNumber(int pc) { int n = tableLength(); int i = 0; for (; i < n; ++i) if (pc < startPc(i)) if (i == 0) return lineNumber(0); else break; return lineNumber(i - 1); } /** * Returns the index into the code array at which the code for * the specified line begins. * * @param line the line number. * @return -1 if the specified line is not found. */ public int toStartPc(int line) { int n = tableLength(); for (int i = 0; i < n; ++i) if (line == lineNumber(i)) return startPc(i); return -1; } /** * Used as a return type of <code>toNearPc()</code>. */ static public class Pc { /** * The index into the code array. */ public int index; /** * The line number. */ public int line; } /** * Returns the index into the code array at which the code for * the specified line (or the nearest line after the specified one) * begins. * * @param line the line number. * @return a pair of the index and the line number of the * bytecode at that index. */ public Pc toNearPc(int line) { int n = tableLength(); int nearPc = 0; int distance = 0; if (n > 0) { distance = lineNumber(0) - line; nearPc = startPc(0); } for (int i = 1; i < n; ++i) { int d = lineNumber(i) - line; if ((d < 0 && d > distance) || (d >= 0 && (d < distance || distance < 0))) { distance = d; nearPc = startPc(i); } } Pc res = new Pc(); res.index = nearPc; res.line = line + distance; return res; } /** * Makes a copy. * * @param newCp the constant pool table used by the new copy. * @param classnames should be null. */ @Override public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) { byte[] src = info; int num = src.length; byte[] dest = new byte[num]; for (int i = 0; i < num; ++i) dest[i] = src[i]; LineNumberAttribute attr = new LineNumberAttribute(newCp, dest); return attr; } /** * Adjusts start_pc if bytecode is inserted in a method body. */ void shiftPc(int where, int gapLength, boolean exclusive) { int n = tableLength(); for (int i = 0; i < n; ++i) { int pos = i * 4 + 2; int pc = ByteArray.readU16bit(info, pos); if (pc > where || (exclusive && pc == where)) ByteArray.write16bit(pc + gapLength, info, pos); } } }
return ByteArray.readU16bit(info, i * 4 + 4);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/LineNumberAttribute.java
LineNumberAttribute
toLineNumber
class LineNumberAttribute extends AttributeInfo { /** * The name of this attribute <code>"LineNumberTable"</code>. */ public static final String tag = "LineNumberTable"; LineNumberAttribute(ConstPool cp, int n, DataInputStream in) throws IOException { super(cp, n, in); } private LineNumberAttribute(ConstPool cp, byte[] i) { super(cp, tag, i); } /** * Returns <code>line_number_table_length</code>. * This represents the number of entries in the table. */ public int tableLength() { return ByteArray.readU16bit(info, 0); } /** * Returns <code>line_number_table[i].start_pc</code>. * This represents the index into the code array at which the code * for a new line in the original source file begins. * * @param i the i-th entry. */ public int startPc(int i) { return ByteArray.readU16bit(info, i * 4 + 2); } /** * Returns <code>line_number_table[i].line_number</code>. * This represents the corresponding line number in the original * source file. * * @param i the i-th entry. */ public int lineNumber(int i) { return ByteArray.readU16bit(info, i * 4 + 4); } /** * Returns the line number corresponding to the specified bytecode. * * @param pc the index into the code array. */ public int toLineNumber(int pc) {<FILL_FUNCTION_BODY>} /** * Returns the index into the code array at which the code for * the specified line begins. * * @param line the line number. * @return -1 if the specified line is not found. */ public int toStartPc(int line) { int n = tableLength(); for (int i = 0; i < n; ++i) if (line == lineNumber(i)) return startPc(i); return -1; } /** * Used as a return type of <code>toNearPc()</code>. */ static public class Pc { /** * The index into the code array. */ public int index; /** * The line number. */ public int line; } /** * Returns the index into the code array at which the code for * the specified line (or the nearest line after the specified one) * begins. * * @param line the line number. * @return a pair of the index and the line number of the * bytecode at that index. */ public Pc toNearPc(int line) { int n = tableLength(); int nearPc = 0; int distance = 0; if (n > 0) { distance = lineNumber(0) - line; nearPc = startPc(0); } for (int i = 1; i < n; ++i) { int d = lineNumber(i) - line; if ((d < 0 && d > distance) || (d >= 0 && (d < distance || distance < 0))) { distance = d; nearPc = startPc(i); } } Pc res = new Pc(); res.index = nearPc; res.line = line + distance; return res; } /** * Makes a copy. * * @param newCp the constant pool table used by the new copy. * @param classnames should be null. */ @Override public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) { byte[] src = info; int num = src.length; byte[] dest = new byte[num]; for (int i = 0; i < num; ++i) dest[i] = src[i]; LineNumberAttribute attr = new LineNumberAttribute(newCp, dest); return attr; } /** * Adjusts start_pc if bytecode is inserted in a method body. */ void shiftPc(int where, int gapLength, boolean exclusive) { int n = tableLength(); for (int i = 0; i < n; ++i) { int pos = i * 4 + 2; int pc = ByteArray.readU16bit(info, pos); if (pc > where || (exclusive && pc == where)) ByteArray.write16bit(pc + gapLength, info, pos); } } }
int n = tableLength(); int i = 0; for (; i < n; ++i) if (pc < startPc(i)) if (i == 0) return lineNumber(0); else break; return lineNumber(i - 1);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/LineNumberAttribute.java
LineNumberAttribute
toStartPc
class LineNumberAttribute extends AttributeInfo { /** * The name of this attribute <code>"LineNumberTable"</code>. */ public static final String tag = "LineNumberTable"; LineNumberAttribute(ConstPool cp, int n, DataInputStream in) throws IOException { super(cp, n, in); } private LineNumberAttribute(ConstPool cp, byte[] i) { super(cp, tag, i); } /** * Returns <code>line_number_table_length</code>. * This represents the number of entries in the table. */ public int tableLength() { return ByteArray.readU16bit(info, 0); } /** * Returns <code>line_number_table[i].start_pc</code>. * This represents the index into the code array at which the code * for a new line in the original source file begins. * * @param i the i-th entry. */ public int startPc(int i) { return ByteArray.readU16bit(info, i * 4 + 2); } /** * Returns <code>line_number_table[i].line_number</code>. * This represents the corresponding line number in the original * source file. * * @param i the i-th entry. */ public int lineNumber(int i) { return ByteArray.readU16bit(info, i * 4 + 4); } /** * Returns the line number corresponding to the specified bytecode. * * @param pc the index into the code array. */ public int toLineNumber(int pc) { int n = tableLength(); int i = 0; for (; i < n; ++i) if (pc < startPc(i)) if (i == 0) return lineNumber(0); else break; return lineNumber(i - 1); } /** * Returns the index into the code array at which the code for * the specified line begins. * * @param line the line number. * @return -1 if the specified line is not found. */ public int toStartPc(int line) {<FILL_FUNCTION_BODY>} /** * Used as a return type of <code>toNearPc()</code>. */ static public class Pc { /** * The index into the code array. */ public int index; /** * The line number. */ public int line; } /** * Returns the index into the code array at which the code for * the specified line (or the nearest line after the specified one) * begins. * * @param line the line number. * @return a pair of the index and the line number of the * bytecode at that index. */ public Pc toNearPc(int line) { int n = tableLength(); int nearPc = 0; int distance = 0; if (n > 0) { distance = lineNumber(0) - line; nearPc = startPc(0); } for (int i = 1; i < n; ++i) { int d = lineNumber(i) - line; if ((d < 0 && d > distance) || (d >= 0 && (d < distance || distance < 0))) { distance = d; nearPc = startPc(i); } } Pc res = new Pc(); res.index = nearPc; res.line = line + distance; return res; } /** * Makes a copy. * * @param newCp the constant pool table used by the new copy. * @param classnames should be null. */ @Override public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) { byte[] src = info; int num = src.length; byte[] dest = new byte[num]; for (int i = 0; i < num; ++i) dest[i] = src[i]; LineNumberAttribute attr = new LineNumberAttribute(newCp, dest); return attr; } /** * Adjusts start_pc if bytecode is inserted in a method body. */ void shiftPc(int where, int gapLength, boolean exclusive) { int n = tableLength(); for (int i = 0; i < n; ++i) { int pos = i * 4 + 2; int pc = ByteArray.readU16bit(info, pos); if (pc > where || (exclusive && pc == where)) ByteArray.write16bit(pc + gapLength, info, pos); } } }
int n = tableLength(); for (int i = 0; i < n; ++i) if (line == lineNumber(i)) return startPc(i); return -1;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/LineNumberAttribute.java
Pc
toNearPc
class Pc { /** * The index into the code array. */ public int index; /** * The line number. */ public int line; } /** * Returns the index into the code array at which the code for * the specified line (or the nearest line after the specified one) * begins. * * @param line the line number. * @return a pair of the index and the line number of the * bytecode at that index. */ public Pc toNearPc(int line) {<FILL_FUNCTION_BODY>
int n = tableLength(); int nearPc = 0; int distance = 0; if (n > 0) { distance = lineNumber(0) - line; nearPc = startPc(0); } for (int i = 1; i < n; ++i) { int d = lineNumber(i) - line; if ((d < 0 && d > distance) || (d >= 0 && (d < distance || distance < 0))) { distance = d; nearPc = startPc(i); } } Pc res = new Pc(); res.index = nearPc; res.line = line + distance; return res;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/LineNumberAttribute.java
Pc
copy
class Pc { /** * The index into the code array. */ public int index; /** * The line number. */ public int line; } /** * Returns the index into the code array at which the code for * the specified line (or the nearest line after the specified one) * begins. * * @param line the line number. * @return a pair of the index and the line number of the * bytecode at that index. */ public Pc toNearPc(int line) { int n = tableLength(); int nearPc = 0; int distance = 0; if (n > 0) { distance = lineNumber(0) - line; nearPc = startPc(0); } for (int i = 1; i < n; ++i) { int d = lineNumber(i) - line; if ((d < 0 && d > distance) || (d >= 0 && (d < distance || distance < 0))) { distance = d; nearPc = startPc(i); } } Pc res = new Pc(); res.index = nearPc; res.line = line + distance; return res; } /** * Makes a copy. * * @param newCp the constant pool table used by the new copy. * @param classnames should be null. */ @Override public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {<FILL_FUNCTION_BODY>
byte[] src = info; int num = src.length; byte[] dest = new byte[num]; for (int i = 0; i < num; ++i) dest[i] = src[i]; LineNumberAttribute attr = new LineNumberAttribute(newCp, dest); return attr;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/LineNumberAttribute.java
Pc
shiftPc
class Pc { /** * The index into the code array. */ public int index; /** * The line number. */ public int line; } /** * Returns the index into the code array at which the code for * the specified line (or the nearest line after the specified one) * begins. * * @param line the line number. * @return a pair of the index and the line number of the * bytecode at that index. */ public Pc toNearPc(int line) { int n = tableLength(); int nearPc = 0; int distance = 0; if (n > 0) { distance = lineNumber(0) - line; nearPc = startPc(0); } for (int i = 1; i < n; ++i) { int d = lineNumber(i) - line; if ((d < 0 && d > distance) || (d >= 0 && (d < distance || distance < 0))) { distance = d; nearPc = startPc(i); } } Pc res = new Pc(); res.index = nearPc; res.line = line + distance; return res; } /** * Makes a copy. * * @param newCp the constant pool table used by the new copy. * @param classnames should be null. */ @Override public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) { byte[] src = info; int num = src.length; byte[] dest = new byte[num]; for (int i = 0; i < num; ++i) dest[i] = src[i]; LineNumberAttribute attr = new LineNumberAttribute(newCp, dest); return attr; } /** * Adjusts start_pc if bytecode is inserted in a method body. */ void shiftPc(int where, int gapLength, boolean exclusive) {<FILL_FUNCTION_BODY>
int n = tableLength(); for (int i = 0; i < n; ++i) { int pos = i * 4 + 2; int pc = ByteArray.readU16bit(info, pos); if (pc > where || (exclusive && pc == where)) ByteArray.write16bit(pc + gapLength, info, pos); }
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/analysis/IntQueue.java
Entry
add
class Entry { private IntQueue.Entry next; private int value; private Entry(int value) { this.value = value; } } private IntQueue.Entry head; private IntQueue.Entry tail; void add(int value) {<FILL_FUNCTION_BODY>
IntQueue.Entry entry = new Entry(value); if (tail != null) tail.next = entry; tail = entry; if (head == null) head = entry;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/analysis/IntQueue.java
Entry
isEmpty
class Entry { private IntQueue.Entry next; private int value; private Entry(int value) { this.value = value; } } private IntQueue.Entry head; private IntQueue.Entry tail; void add(int value) { IntQueue.Entry entry = new Entry(value); if (tail != null) tail.next = entry; tail = entry; if (head == null) head = entry; } boolean isEmpty() {<FILL_FUNCTION_BODY>
return head == null;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/analysis/IntQueue.java
Entry
take
class Entry { private IntQueue.Entry next; private int value; private Entry(int value) { this.value = value; } } private IntQueue.Entry head; private IntQueue.Entry tail; void add(int value) { IntQueue.Entry entry = new Entry(value); if (tail != null) tail.next = entry; tail = entry; if (head == null) head = entry; } boolean isEmpty() { return head == null; } int take() {<FILL_FUNCTION_BODY>
if (head == null) throw new NoSuchElementException(); int value = head.value; head = head.next; if (head == null) tail = null; return value;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/annotation/Annotation.java
Pair
createMemberValue
class Pair { int name; MemberValue value; } ConstPool pool; int typeIndex; Map<String,Pair> members; // this sould be LinkedHashMap // but it is not supported by JDK 1.3. /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param type the index into the constant pool table. * the entry at that index must be the * <code>CONSTANT_Utf8_Info</code> structure * repreenting the name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(int type, ConstPool cp) { pool = cp; typeIndex = type; members = null; } /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param typeName the fully-qualified name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(String typeName, ConstPool cp) { this(cp.addUtf8Info(Descriptor.of(typeName)), cp); } /** * Constructs an annotation that can be accessed through the interface * represented by <code>clazz</code>. The values of the members are * not specified. * * @param cp the constant pool table. * @param clazz the interface. * @throws NotFoundException when the clazz is not found */ public Annotation(ConstPool cp, CtClass clazz) throws NotFoundException { // todo Enums are not supported right now. this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp); if (!clazz.isInterface()) throw new RuntimeException( "Only interfaces are allowed for Annotation creation."); CtMethod[] methods = clazz.getDeclaredMethods(); if (methods.length > 0) members = new LinkedHashMap<String,Pair>(); for (CtMethod m:methods) addMemberValue(m.getName(), createMemberValue(cp, m.getReturnType())); } /** * Makes an instance of <code>MemberValue</code>. * * @param cp the constant pool table. * @param type the type of the member. * @return the member value * @throws NotFoundException when the type is not found */ public static MemberValue createMemberValue(ConstPool cp, CtClass type) throws NotFoundException {<FILL_FUNCTION_BODY>
if (type == CtClass.booleanType) return new BooleanMemberValue(cp); else if (type == CtClass.byteType) return new ByteMemberValue(cp); else if (type == CtClass.charType) return new CharMemberValue(cp); else if (type == CtClass.shortType) return new ShortMemberValue(cp); else if (type == CtClass.intType) return new IntegerMemberValue(cp); else if (type == CtClass.longType) return new LongMemberValue(cp); else if (type == CtClass.floatType) return new FloatMemberValue(cp); else if (type == CtClass.doubleType) return new DoubleMemberValue(cp); else if (type.getName().equals("java.lang.Class")) return new ClassMemberValue(cp); else if (type.getName().equals("java.lang.String")) return new StringMemberValue(cp); else if (type.isArray()) { CtClass arrayType = type.getComponentType(); MemberValue member = createMemberValue(cp, arrayType); return new ArrayMemberValue(member, cp); } else if (type.isInterface()) { Annotation info = new Annotation(cp, type); return new AnnotationMemberValue(info, cp); } else { // treat as enum. I know this is not typed, // but JBoss has an Annotation Compiler for JDK 1.4 // and I want it to work with that. - Bill Burke EnumMemberValue emv = new EnumMemberValue(cp); emv.setType(type.getName()); return emv; }
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/annotation/Annotation.java
Pair
addMemberValue
class Pair { int name; MemberValue value; } ConstPool pool; int typeIndex; Map<String,Pair> members; // this sould be LinkedHashMap // but it is not supported by JDK 1.3. /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param type the index into the constant pool table. * the entry at that index must be the * <code>CONSTANT_Utf8_Info</code> structure * repreenting the name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(int type, ConstPool cp) { pool = cp; typeIndex = type; members = null; } /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param typeName the fully-qualified name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(String typeName, ConstPool cp) { this(cp.addUtf8Info(Descriptor.of(typeName)), cp); } /** * Constructs an annotation that can be accessed through the interface * represented by <code>clazz</code>. The values of the members are * not specified. * * @param cp the constant pool table. * @param clazz the interface. * @throws NotFoundException when the clazz is not found */ public Annotation(ConstPool cp, CtClass clazz) throws NotFoundException { // todo Enums are not supported right now. this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp); if (!clazz.isInterface()) throw new RuntimeException( "Only interfaces are allowed for Annotation creation."); CtMethod[] methods = clazz.getDeclaredMethods(); if (methods.length > 0) members = new LinkedHashMap<String,Pair>(); for (CtMethod m:methods) addMemberValue(m.getName(), createMemberValue(cp, m.getReturnType())); } /** * Makes an instance of <code>MemberValue</code>. * * @param cp the constant pool table. * @param type the type of the member. * @return the member value * @throws NotFoundException when the type is not found */ public static MemberValue createMemberValue(ConstPool cp, CtClass type) throws NotFoundException { if (type == CtClass.booleanType) return new BooleanMemberValue(cp); else if (type == CtClass.byteType) return new ByteMemberValue(cp); else if (type == CtClass.charType) return new CharMemberValue(cp); else if (type == CtClass.shortType) return new ShortMemberValue(cp); else if (type == CtClass.intType) return new IntegerMemberValue(cp); else if (type == CtClass.longType) return new LongMemberValue(cp); else if (type == CtClass.floatType) return new FloatMemberValue(cp); else if (type == CtClass.doubleType) return new DoubleMemberValue(cp); else if (type.getName().equals("java.lang.Class")) return new ClassMemberValue(cp); else if (type.getName().equals("java.lang.String")) return new StringMemberValue(cp); else if (type.isArray()) { CtClass arrayType = type.getComponentType(); MemberValue member = createMemberValue(cp, arrayType); return new ArrayMemberValue(member, cp); } else if (type.isInterface()) { Annotation info = new Annotation(cp, type); return new AnnotationMemberValue(info, cp); } else { // treat as enum. I know this is not typed, // but JBoss has an Annotation Compiler for JDK 1.4 // and I want it to work with that. - Bill Burke EnumMemberValue emv = new EnumMemberValue(cp); emv.setType(type.getName()); return emv; } } /** * Adds a new member. * * @param nameIndex the index into the constant pool table. * The entry at that index must be * a <code>CONSTANT_Utf8_info</code> structure. * structure representing the member name. * @param value the member value. */ public void addMemberValue(int nameIndex, MemberValue value) {<FILL_FUNCTION_BODY>
Pair p = new Pair(); p.name = nameIndex; p.value = value; addMemberValue(p);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/annotation/Annotation.java
Pair
addMemberValue
class Pair { int name; MemberValue value; } ConstPool pool; int typeIndex; Map<String,Pair> members; // this sould be LinkedHashMap // but it is not supported by JDK 1.3. /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param type the index into the constant pool table. * the entry at that index must be the * <code>CONSTANT_Utf8_Info</code> structure * repreenting the name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(int type, ConstPool cp) { pool = cp; typeIndex = type; members = null; } /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param typeName the fully-qualified name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(String typeName, ConstPool cp) { this(cp.addUtf8Info(Descriptor.of(typeName)), cp); } /** * Constructs an annotation that can be accessed through the interface * represented by <code>clazz</code>. The values of the members are * not specified. * * @param cp the constant pool table. * @param clazz the interface. * @throws NotFoundException when the clazz is not found */ public Annotation(ConstPool cp, CtClass clazz) throws NotFoundException { // todo Enums are not supported right now. this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp); if (!clazz.isInterface()) throw new RuntimeException( "Only interfaces are allowed for Annotation creation."); CtMethod[] methods = clazz.getDeclaredMethods(); if (methods.length > 0) members = new LinkedHashMap<String,Pair>(); for (CtMethod m:methods) addMemberValue(m.getName(), createMemberValue(cp, m.getReturnType())); } /** * Makes an instance of <code>MemberValue</code>. * * @param cp the constant pool table. * @param type the type of the member. * @return the member value * @throws NotFoundException when the type is not found */ public static MemberValue createMemberValue(ConstPool cp, CtClass type) throws NotFoundException { if (type == CtClass.booleanType) return new BooleanMemberValue(cp); else if (type == CtClass.byteType) return new ByteMemberValue(cp); else if (type == CtClass.charType) return new CharMemberValue(cp); else if (type == CtClass.shortType) return new ShortMemberValue(cp); else if (type == CtClass.intType) return new IntegerMemberValue(cp); else if (type == CtClass.longType) return new LongMemberValue(cp); else if (type == CtClass.floatType) return new FloatMemberValue(cp); else if (type == CtClass.doubleType) return new DoubleMemberValue(cp); else if (type.getName().equals("java.lang.Class")) return new ClassMemberValue(cp); else if (type.getName().equals("java.lang.String")) return new StringMemberValue(cp); else if (type.isArray()) { CtClass arrayType = type.getComponentType(); MemberValue member = createMemberValue(cp, arrayType); return new ArrayMemberValue(member, cp); } else if (type.isInterface()) { Annotation info = new Annotation(cp, type); return new AnnotationMemberValue(info, cp); } else { // treat as enum. I know this is not typed, // but JBoss has an Annotation Compiler for JDK 1.4 // and I want it to work with that. - Bill Burke EnumMemberValue emv = new EnumMemberValue(cp); emv.setType(type.getName()); return emv; } } /** * Adds a new member. * * @param nameIndex the index into the constant pool table. * The entry at that index must be * a <code>CONSTANT_Utf8_info</code> structure. * structure representing the member name. * @param value the member value. */ public void addMemberValue(int nameIndex, MemberValue value) { Pair p = new Pair(); p.name = nameIndex; p.value = value; addMemberValue(p); } /** * Adds a new member. * * @param name the member name. * @param value the member value. */ public void addMemberValue(String name, MemberValue value) {<FILL_FUNCTION_BODY>
Pair p = new Pair(); p.name = pool.addUtf8Info(name); p.value = value; if (members == null) members = new LinkedHashMap<String,Pair>(); members.put(name, p);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/annotation/Annotation.java
Pair
addMemberValue
class Pair { int name; MemberValue value; } ConstPool pool; int typeIndex; Map<String,Pair> members; // this sould be LinkedHashMap // but it is not supported by JDK 1.3. /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param type the index into the constant pool table. * the entry at that index must be the * <code>CONSTANT_Utf8_Info</code> structure * repreenting the name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(int type, ConstPool cp) { pool = cp; typeIndex = type; members = null; } /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param typeName the fully-qualified name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(String typeName, ConstPool cp) { this(cp.addUtf8Info(Descriptor.of(typeName)), cp); } /** * Constructs an annotation that can be accessed through the interface * represented by <code>clazz</code>. The values of the members are * not specified. * * @param cp the constant pool table. * @param clazz the interface. * @throws NotFoundException when the clazz is not found */ public Annotation(ConstPool cp, CtClass clazz) throws NotFoundException { // todo Enums are not supported right now. this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp); if (!clazz.isInterface()) throw new RuntimeException( "Only interfaces are allowed for Annotation creation."); CtMethod[] methods = clazz.getDeclaredMethods(); if (methods.length > 0) members = new LinkedHashMap<String,Pair>(); for (CtMethod m:methods) addMemberValue(m.getName(), createMemberValue(cp, m.getReturnType())); } /** * Makes an instance of <code>MemberValue</code>. * * @param cp the constant pool table. * @param type the type of the member. * @return the member value * @throws NotFoundException when the type is not found */ public static MemberValue createMemberValue(ConstPool cp, CtClass type) throws NotFoundException { if (type == CtClass.booleanType) return new BooleanMemberValue(cp); else if (type == CtClass.byteType) return new ByteMemberValue(cp); else if (type == CtClass.charType) return new CharMemberValue(cp); else if (type == CtClass.shortType) return new ShortMemberValue(cp); else if (type == CtClass.intType) return new IntegerMemberValue(cp); else if (type == CtClass.longType) return new LongMemberValue(cp); else if (type == CtClass.floatType) return new FloatMemberValue(cp); else if (type == CtClass.doubleType) return new DoubleMemberValue(cp); else if (type.getName().equals("java.lang.Class")) return new ClassMemberValue(cp); else if (type.getName().equals("java.lang.String")) return new StringMemberValue(cp); else if (type.isArray()) { CtClass arrayType = type.getComponentType(); MemberValue member = createMemberValue(cp, arrayType); return new ArrayMemberValue(member, cp); } else if (type.isInterface()) { Annotation info = new Annotation(cp, type); return new AnnotationMemberValue(info, cp); } else { // treat as enum. I know this is not typed, // but JBoss has an Annotation Compiler for JDK 1.4 // and I want it to work with that. - Bill Burke EnumMemberValue emv = new EnumMemberValue(cp); emv.setType(type.getName()); return emv; } } /** * Adds a new member. * * @param nameIndex the index into the constant pool table. * The entry at that index must be * a <code>CONSTANT_Utf8_info</code> structure. * structure representing the member name. * @param value the member value. */ public void addMemberValue(int nameIndex, MemberValue value) { Pair p = new Pair(); p.name = nameIndex; p.value = value; addMemberValue(p); } /** * Adds a new member. * * @param name the member name. * @param value the member value. */ public void addMemberValue(String name, MemberValue value) { Pair p = new Pair(); p.name = pool.addUtf8Info(name); p.value = value; if (members == null) members = new LinkedHashMap<String,Pair>(); members.put(name, p); } private void addMemberValue(Pair pair) {<FILL_FUNCTION_BODY>
String name = pool.getUtf8Info(pair.name); if (members == null) members = new LinkedHashMap<String,Pair>(); members.put(name, pair);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/annotation/Annotation.java
Pair
toString
class Pair { int name; MemberValue value; } ConstPool pool; int typeIndex; Map<String,Pair> members; // this sould be LinkedHashMap // but it is not supported by JDK 1.3. /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param type the index into the constant pool table. * the entry at that index must be the * <code>CONSTANT_Utf8_Info</code> structure * repreenting the name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(int type, ConstPool cp) { pool = cp; typeIndex = type; members = null; } /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param typeName the fully-qualified name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(String typeName, ConstPool cp) { this(cp.addUtf8Info(Descriptor.of(typeName)), cp); } /** * Constructs an annotation that can be accessed through the interface * represented by <code>clazz</code>. The values of the members are * not specified. * * @param cp the constant pool table. * @param clazz the interface. * @throws NotFoundException when the clazz is not found */ public Annotation(ConstPool cp, CtClass clazz) throws NotFoundException { // todo Enums are not supported right now. this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp); if (!clazz.isInterface()) throw new RuntimeException( "Only interfaces are allowed for Annotation creation."); CtMethod[] methods = clazz.getDeclaredMethods(); if (methods.length > 0) members = new LinkedHashMap<String,Pair>(); for (CtMethod m:methods) addMemberValue(m.getName(), createMemberValue(cp, m.getReturnType())); } /** * Makes an instance of <code>MemberValue</code>. * * @param cp the constant pool table. * @param type the type of the member. * @return the member value * @throws NotFoundException when the type is not found */ public static MemberValue createMemberValue(ConstPool cp, CtClass type) throws NotFoundException { if (type == CtClass.booleanType) return new BooleanMemberValue(cp); else if (type == CtClass.byteType) return new ByteMemberValue(cp); else if (type == CtClass.charType) return new CharMemberValue(cp); else if (type == CtClass.shortType) return new ShortMemberValue(cp); else if (type == CtClass.intType) return new IntegerMemberValue(cp); else if (type == CtClass.longType) return new LongMemberValue(cp); else if (type == CtClass.floatType) return new FloatMemberValue(cp); else if (type == CtClass.doubleType) return new DoubleMemberValue(cp); else if (type.getName().equals("java.lang.Class")) return new ClassMemberValue(cp); else if (type.getName().equals("java.lang.String")) return new StringMemberValue(cp); else if (type.isArray()) { CtClass arrayType = type.getComponentType(); MemberValue member = createMemberValue(cp, arrayType); return new ArrayMemberValue(member, cp); } else if (type.isInterface()) { Annotation info = new Annotation(cp, type); return new AnnotationMemberValue(info, cp); } else { // treat as enum. I know this is not typed, // but JBoss has an Annotation Compiler for JDK 1.4 // and I want it to work with that. - Bill Burke EnumMemberValue emv = new EnumMemberValue(cp); emv.setType(type.getName()); return emv; } } /** * Adds a new member. * * @param nameIndex the index into the constant pool table. * The entry at that index must be * a <code>CONSTANT_Utf8_info</code> structure. * structure representing the member name. * @param value the member value. */ public void addMemberValue(int nameIndex, MemberValue value) { Pair p = new Pair(); p.name = nameIndex; p.value = value; addMemberValue(p); } /** * Adds a new member. * * @param name the member name. * @param value the member value. */ public void addMemberValue(String name, MemberValue value) { Pair p = new Pair(); p.name = pool.addUtf8Info(name); p.value = value; if (members == null) members = new LinkedHashMap<String,Pair>(); members.put(name, p); } private void addMemberValue(Pair pair) { String name = pool.getUtf8Info(pair.name); if (members == null) members = new LinkedHashMap<String,Pair>(); members.put(name, pair); } /** * Returns a string representation of the annotation. */ @Override public String toString() {<FILL_FUNCTION_BODY>
StringBuffer buf = new StringBuffer("@"); buf.append(getTypeName()); if (members != null) { buf.append("("); for (String name:members.keySet()) { buf.append(name).append("=") .append(getMemberValue(name)) .append(", "); } buf.setLength(buf.length()-2); buf.append(")"); } return buf.toString();
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/annotation/Annotation.java
Pair
getTypeName
class Pair { int name; MemberValue value; } ConstPool pool; int typeIndex; Map<String,Pair> members; // this sould be LinkedHashMap // but it is not supported by JDK 1.3. /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param type the index into the constant pool table. * the entry at that index must be the * <code>CONSTANT_Utf8_Info</code> structure * repreenting the name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(int type, ConstPool cp) { pool = cp; typeIndex = type; members = null; } /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param typeName the fully-qualified name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(String typeName, ConstPool cp) { this(cp.addUtf8Info(Descriptor.of(typeName)), cp); } /** * Constructs an annotation that can be accessed through the interface * represented by <code>clazz</code>. The values of the members are * not specified. * * @param cp the constant pool table. * @param clazz the interface. * @throws NotFoundException when the clazz is not found */ public Annotation(ConstPool cp, CtClass clazz) throws NotFoundException { // todo Enums are not supported right now. this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp); if (!clazz.isInterface()) throw new RuntimeException( "Only interfaces are allowed for Annotation creation."); CtMethod[] methods = clazz.getDeclaredMethods(); if (methods.length > 0) members = new LinkedHashMap<String,Pair>(); for (CtMethod m:methods) addMemberValue(m.getName(), createMemberValue(cp, m.getReturnType())); } /** * Makes an instance of <code>MemberValue</code>. * * @param cp the constant pool table. * @param type the type of the member. * @return the member value * @throws NotFoundException when the type is not found */ public static MemberValue createMemberValue(ConstPool cp, CtClass type) throws NotFoundException { if (type == CtClass.booleanType) return new BooleanMemberValue(cp); else if (type == CtClass.byteType) return new ByteMemberValue(cp); else if (type == CtClass.charType) return new CharMemberValue(cp); else if (type == CtClass.shortType) return new ShortMemberValue(cp); else if (type == CtClass.intType) return new IntegerMemberValue(cp); else if (type == CtClass.longType) return new LongMemberValue(cp); else if (type == CtClass.floatType) return new FloatMemberValue(cp); else if (type == CtClass.doubleType) return new DoubleMemberValue(cp); else if (type.getName().equals("java.lang.Class")) return new ClassMemberValue(cp); else if (type.getName().equals("java.lang.String")) return new StringMemberValue(cp); else if (type.isArray()) { CtClass arrayType = type.getComponentType(); MemberValue member = createMemberValue(cp, arrayType); return new ArrayMemberValue(member, cp); } else if (type.isInterface()) { Annotation info = new Annotation(cp, type); return new AnnotationMemberValue(info, cp); } else { // treat as enum. I know this is not typed, // but JBoss has an Annotation Compiler for JDK 1.4 // and I want it to work with that. - Bill Burke EnumMemberValue emv = new EnumMemberValue(cp); emv.setType(type.getName()); return emv; } } /** * Adds a new member. * * @param nameIndex the index into the constant pool table. * The entry at that index must be * a <code>CONSTANT_Utf8_info</code> structure. * structure representing the member name. * @param value the member value. */ public void addMemberValue(int nameIndex, MemberValue value) { Pair p = new Pair(); p.name = nameIndex; p.value = value; addMemberValue(p); } /** * Adds a new member. * * @param name the member name. * @param value the member value. */ public void addMemberValue(String name, MemberValue value) { Pair p = new Pair(); p.name = pool.addUtf8Info(name); p.value = value; if (members == null) members = new LinkedHashMap<String,Pair>(); members.put(name, p); } private void addMemberValue(Pair pair) { String name = pool.getUtf8Info(pair.name); if (members == null) members = new LinkedHashMap<String,Pair>(); members.put(name, pair); } /** * Returns a string representation of the annotation. */ @Override public String toString() { StringBuffer buf = new StringBuffer("@"); buf.append(getTypeName()); if (members != null) { buf.append("("); for (String name:members.keySet()) { buf.append(name).append("=") .append(getMemberValue(name)) .append(", "); } buf.setLength(buf.length()-2); buf.append(")"); } return buf.toString(); } /** * Obtains the name of the annotation type. * * @return the type name */ public String getTypeName() {<FILL_FUNCTION_BODY>
return Descriptor.toClassName(pool.getUtf8Info(typeIndex));
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/annotation/Annotation.java
Pair
getMemberNames
class Pair { int name; MemberValue value; } ConstPool pool; int typeIndex; Map<String,Pair> members; // this sould be LinkedHashMap // but it is not supported by JDK 1.3. /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param type the index into the constant pool table. * the entry at that index must be the * <code>CONSTANT_Utf8_Info</code> structure * repreenting the name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(int type, ConstPool cp) { pool = cp; typeIndex = type; members = null; } /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param typeName the fully-qualified name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(String typeName, ConstPool cp) { this(cp.addUtf8Info(Descriptor.of(typeName)), cp); } /** * Constructs an annotation that can be accessed through the interface * represented by <code>clazz</code>. The values of the members are * not specified. * * @param cp the constant pool table. * @param clazz the interface. * @throws NotFoundException when the clazz is not found */ public Annotation(ConstPool cp, CtClass clazz) throws NotFoundException { // todo Enums are not supported right now. this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp); if (!clazz.isInterface()) throw new RuntimeException( "Only interfaces are allowed for Annotation creation."); CtMethod[] methods = clazz.getDeclaredMethods(); if (methods.length > 0) members = new LinkedHashMap<String,Pair>(); for (CtMethod m:methods) addMemberValue(m.getName(), createMemberValue(cp, m.getReturnType())); } /** * Makes an instance of <code>MemberValue</code>. * * @param cp the constant pool table. * @param type the type of the member. * @return the member value * @throws NotFoundException when the type is not found */ public static MemberValue createMemberValue(ConstPool cp, CtClass type) throws NotFoundException { if (type == CtClass.booleanType) return new BooleanMemberValue(cp); else if (type == CtClass.byteType) return new ByteMemberValue(cp); else if (type == CtClass.charType) return new CharMemberValue(cp); else if (type == CtClass.shortType) return new ShortMemberValue(cp); else if (type == CtClass.intType) return new IntegerMemberValue(cp); else if (type == CtClass.longType) return new LongMemberValue(cp); else if (type == CtClass.floatType) return new FloatMemberValue(cp); else if (type == CtClass.doubleType) return new DoubleMemberValue(cp); else if (type.getName().equals("java.lang.Class")) return new ClassMemberValue(cp); else if (type.getName().equals("java.lang.String")) return new StringMemberValue(cp); else if (type.isArray()) { CtClass arrayType = type.getComponentType(); MemberValue member = createMemberValue(cp, arrayType); return new ArrayMemberValue(member, cp); } else if (type.isInterface()) { Annotation info = new Annotation(cp, type); return new AnnotationMemberValue(info, cp); } else { // treat as enum. I know this is not typed, // but JBoss has an Annotation Compiler for JDK 1.4 // and I want it to work with that. - Bill Burke EnumMemberValue emv = new EnumMemberValue(cp); emv.setType(type.getName()); return emv; } } /** * Adds a new member. * * @param nameIndex the index into the constant pool table. * The entry at that index must be * a <code>CONSTANT_Utf8_info</code> structure. * structure representing the member name. * @param value the member value. */ public void addMemberValue(int nameIndex, MemberValue value) { Pair p = new Pair(); p.name = nameIndex; p.value = value; addMemberValue(p); } /** * Adds a new member. * * @param name the member name. * @param value the member value. */ public void addMemberValue(String name, MemberValue value) { Pair p = new Pair(); p.name = pool.addUtf8Info(name); p.value = value; if (members == null) members = new LinkedHashMap<String,Pair>(); members.put(name, p); } private void addMemberValue(Pair pair) { String name = pool.getUtf8Info(pair.name); if (members == null) members = new LinkedHashMap<String,Pair>(); members.put(name, pair); } /** * Returns a string representation of the annotation. */ @Override public String toString() { StringBuffer buf = new StringBuffer("@"); buf.append(getTypeName()); if (members != null) { buf.append("("); for (String name:members.keySet()) { buf.append(name).append("=") .append(getMemberValue(name)) .append(", "); } buf.setLength(buf.length()-2); buf.append(")"); } return buf.toString(); } /** * Obtains the name of the annotation type. * * @return the type name */ public String getTypeName() { return Descriptor.toClassName(pool.getUtf8Info(typeIndex)); } /** * Obtains all the member names. * * @return null if no members are defined. */ public Set<String> getMemberNames() {<FILL_FUNCTION_BODY>
if (members == null) return null; return members.keySet();
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/annotation/Annotation.java
Pair
getMemberValue
class Pair { int name; MemberValue value; } ConstPool pool; int typeIndex; Map<String,Pair> members; // this sould be LinkedHashMap // but it is not supported by JDK 1.3. /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param type the index into the constant pool table. * the entry at that index must be the * <code>CONSTANT_Utf8_Info</code> structure * repreenting the name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(int type, ConstPool cp) { pool = cp; typeIndex = type; members = null; } /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param typeName the fully-qualified name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(String typeName, ConstPool cp) { this(cp.addUtf8Info(Descriptor.of(typeName)), cp); } /** * Constructs an annotation that can be accessed through the interface * represented by <code>clazz</code>. The values of the members are * not specified. * * @param cp the constant pool table. * @param clazz the interface. * @throws NotFoundException when the clazz is not found */ public Annotation(ConstPool cp, CtClass clazz) throws NotFoundException { // todo Enums are not supported right now. this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp); if (!clazz.isInterface()) throw new RuntimeException( "Only interfaces are allowed for Annotation creation."); CtMethod[] methods = clazz.getDeclaredMethods(); if (methods.length > 0) members = new LinkedHashMap<String,Pair>(); for (CtMethod m:methods) addMemberValue(m.getName(), createMemberValue(cp, m.getReturnType())); } /** * Makes an instance of <code>MemberValue</code>. * * @param cp the constant pool table. * @param type the type of the member. * @return the member value * @throws NotFoundException when the type is not found */ public static MemberValue createMemberValue(ConstPool cp, CtClass type) throws NotFoundException { if (type == CtClass.booleanType) return new BooleanMemberValue(cp); else if (type == CtClass.byteType) return new ByteMemberValue(cp); else if (type == CtClass.charType) return new CharMemberValue(cp); else if (type == CtClass.shortType) return new ShortMemberValue(cp); else if (type == CtClass.intType) return new IntegerMemberValue(cp); else if (type == CtClass.longType) return new LongMemberValue(cp); else if (type == CtClass.floatType) return new FloatMemberValue(cp); else if (type == CtClass.doubleType) return new DoubleMemberValue(cp); else if (type.getName().equals("java.lang.Class")) return new ClassMemberValue(cp); else if (type.getName().equals("java.lang.String")) return new StringMemberValue(cp); else if (type.isArray()) { CtClass arrayType = type.getComponentType(); MemberValue member = createMemberValue(cp, arrayType); return new ArrayMemberValue(member, cp); } else if (type.isInterface()) { Annotation info = new Annotation(cp, type); return new AnnotationMemberValue(info, cp); } else { // treat as enum. I know this is not typed, // but JBoss has an Annotation Compiler for JDK 1.4 // and I want it to work with that. - Bill Burke EnumMemberValue emv = new EnumMemberValue(cp); emv.setType(type.getName()); return emv; } } /** * Adds a new member. * * @param nameIndex the index into the constant pool table. * The entry at that index must be * a <code>CONSTANT_Utf8_info</code> structure. * structure representing the member name. * @param value the member value. */ public void addMemberValue(int nameIndex, MemberValue value) { Pair p = new Pair(); p.name = nameIndex; p.value = value; addMemberValue(p); } /** * Adds a new member. * * @param name the member name. * @param value the member value. */ public void addMemberValue(String name, MemberValue value) { Pair p = new Pair(); p.name = pool.addUtf8Info(name); p.value = value; if (members == null) members = new LinkedHashMap<String,Pair>(); members.put(name, p); } private void addMemberValue(Pair pair) { String name = pool.getUtf8Info(pair.name); if (members == null) members = new LinkedHashMap<String,Pair>(); members.put(name, pair); } /** * Returns a string representation of the annotation. */ @Override public String toString() { StringBuffer buf = new StringBuffer("@"); buf.append(getTypeName()); if (members != null) { buf.append("("); for (String name:members.keySet()) { buf.append(name).append("=") .append(getMemberValue(name)) .append(", "); } buf.setLength(buf.length()-2); buf.append(")"); } return buf.toString(); } /** * Obtains the name of the annotation type. * * @return the type name */ public String getTypeName() { return Descriptor.toClassName(pool.getUtf8Info(typeIndex)); } /** * Obtains all the member names. * * @return null if no members are defined. */ public Set<String> getMemberNames() { if (members == null) return null; return members.keySet(); } /** * Obtains the member value with the given name. * * <p>If this annotation does not have a value for the * specified member, * this method returns null. It does not return a * <code>MemberValue</code> with the default value. * The default value can be obtained from the annotation type. * * @param name the member name * @return null if the member cannot be found or if the value is * the default value. * * @see javassist.bytecode.AnnotationDefaultAttribute */ public MemberValue getMemberValue(String name) {<FILL_FUNCTION_BODY>
if (members == null||members.get(name) == null) return null; return members.get(name).value;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/annotation/Annotation.java
Pair
toAnnotationType
class Pair { int name; MemberValue value; } ConstPool pool; int typeIndex; Map<String,Pair> members; // this sould be LinkedHashMap // but it is not supported by JDK 1.3. /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param type the index into the constant pool table. * the entry at that index must be the * <code>CONSTANT_Utf8_Info</code> structure * repreenting the name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(int type, ConstPool cp) { pool = cp; typeIndex = type; members = null; } /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param typeName the fully-qualified name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(String typeName, ConstPool cp) { this(cp.addUtf8Info(Descriptor.of(typeName)), cp); } /** * Constructs an annotation that can be accessed through the interface * represented by <code>clazz</code>. The values of the members are * not specified. * * @param cp the constant pool table. * @param clazz the interface. * @throws NotFoundException when the clazz is not found */ public Annotation(ConstPool cp, CtClass clazz) throws NotFoundException { // todo Enums are not supported right now. this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp); if (!clazz.isInterface()) throw new RuntimeException( "Only interfaces are allowed for Annotation creation."); CtMethod[] methods = clazz.getDeclaredMethods(); if (methods.length > 0) members = new LinkedHashMap<String,Pair>(); for (CtMethod m:methods) addMemberValue(m.getName(), createMemberValue(cp, m.getReturnType())); } /** * Makes an instance of <code>MemberValue</code>. * * @param cp the constant pool table. * @param type the type of the member. * @return the member value * @throws NotFoundException when the type is not found */ public static MemberValue createMemberValue(ConstPool cp, CtClass type) throws NotFoundException { if (type == CtClass.booleanType) return new BooleanMemberValue(cp); else if (type == CtClass.byteType) return new ByteMemberValue(cp); else if (type == CtClass.charType) return new CharMemberValue(cp); else if (type == CtClass.shortType) return new ShortMemberValue(cp); else if (type == CtClass.intType) return new IntegerMemberValue(cp); else if (type == CtClass.longType) return new LongMemberValue(cp); else if (type == CtClass.floatType) return new FloatMemberValue(cp); else if (type == CtClass.doubleType) return new DoubleMemberValue(cp); else if (type.getName().equals("java.lang.Class")) return new ClassMemberValue(cp); else if (type.getName().equals("java.lang.String")) return new StringMemberValue(cp); else if (type.isArray()) { CtClass arrayType = type.getComponentType(); MemberValue member = createMemberValue(cp, arrayType); return new ArrayMemberValue(member, cp); } else if (type.isInterface()) { Annotation info = new Annotation(cp, type); return new AnnotationMemberValue(info, cp); } else { // treat as enum. I know this is not typed, // but JBoss has an Annotation Compiler for JDK 1.4 // and I want it to work with that. - Bill Burke EnumMemberValue emv = new EnumMemberValue(cp); emv.setType(type.getName()); return emv; } } /** * Adds a new member. * * @param nameIndex the index into the constant pool table. * The entry at that index must be * a <code>CONSTANT_Utf8_info</code> structure. * structure representing the member name. * @param value the member value. */ public void addMemberValue(int nameIndex, MemberValue value) { Pair p = new Pair(); p.name = nameIndex; p.value = value; addMemberValue(p); } /** * Adds a new member. * * @param name the member name. * @param value the member value. */ public void addMemberValue(String name, MemberValue value) { Pair p = new Pair(); p.name = pool.addUtf8Info(name); p.value = value; if (members == null) members = new LinkedHashMap<String,Pair>(); members.put(name, p); } private void addMemberValue(Pair pair) { String name = pool.getUtf8Info(pair.name); if (members == null) members = new LinkedHashMap<String,Pair>(); members.put(name, pair); } /** * Returns a string representation of the annotation. */ @Override public String toString() { StringBuffer buf = new StringBuffer("@"); buf.append(getTypeName()); if (members != null) { buf.append("("); for (String name:members.keySet()) { buf.append(name).append("=") .append(getMemberValue(name)) .append(", "); } buf.setLength(buf.length()-2); buf.append(")"); } return buf.toString(); } /** * Obtains the name of the annotation type. * * @return the type name */ public String getTypeName() { return Descriptor.toClassName(pool.getUtf8Info(typeIndex)); } /** * Obtains all the member names. * * @return null if no members are defined. */ public Set<String> getMemberNames() { if (members == null) return null; return members.keySet(); } /** * Obtains the member value with the given name. * * <p>If this annotation does not have a value for the * specified member, * this method returns null. It does not return a * <code>MemberValue</code> with the default value. * The default value can be obtained from the annotation type. * * @param name the member name * @return null if the member cannot be found or if the value is * the default value. * * @see javassist.bytecode.AnnotationDefaultAttribute */ public MemberValue getMemberValue(String name) { if (members == null||members.get(name) == null) return null; return members.get(name).value; } /** * Constructs an annotation-type object representing this annotation. * For example, if this annotation represents <code>@Author</code>, * this method returns an <code>Author</code> object. * * @param cl class loader for loading an annotation type. * @param cp class pool for obtaining class files. * @return the annotation * @throws ClassNotFoundException if the class cannot found. * @throws NoSuchClassError if the class linkage fails. */ public Object toAnnotationType(ClassLoader cl, ClassPool cp) throws ClassNotFoundException, NoSuchClassError {<FILL_FUNCTION_BODY>
Class<?> clazz = MemberValue.loadClass(cl, getTypeName()); try { return AnnotationImpl.make(cl, clazz, cp, this); } catch (IllegalArgumentException e) { /* AnnotationImpl.make() may throw this exception * when it fails to make a proxy object for some * reason. */ throw new ClassNotFoundException(clazz.getName(), e); } catch (IllegalAccessError e2) { // also IllegalAccessError throw new ClassNotFoundException(clazz.getName(), e2); }
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/annotation/Annotation.java
Pair
write
class Pair { int name; MemberValue value; } ConstPool pool; int typeIndex; Map<String,Pair> members; // this sould be LinkedHashMap // but it is not supported by JDK 1.3. /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param type the index into the constant pool table. * the entry at that index must be the * <code>CONSTANT_Utf8_Info</code> structure * repreenting the name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(int type, ConstPool cp) { pool = cp; typeIndex = type; members = null; } /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param typeName the fully-qualified name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(String typeName, ConstPool cp) { this(cp.addUtf8Info(Descriptor.of(typeName)), cp); } /** * Constructs an annotation that can be accessed through the interface * represented by <code>clazz</code>. The values of the members are * not specified. * * @param cp the constant pool table. * @param clazz the interface. * @throws NotFoundException when the clazz is not found */ public Annotation(ConstPool cp, CtClass clazz) throws NotFoundException { // todo Enums are not supported right now. this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp); if (!clazz.isInterface()) throw new RuntimeException( "Only interfaces are allowed for Annotation creation."); CtMethod[] methods = clazz.getDeclaredMethods(); if (methods.length > 0) members = new LinkedHashMap<String,Pair>(); for (CtMethod m:methods) addMemberValue(m.getName(), createMemberValue(cp, m.getReturnType())); } /** * Makes an instance of <code>MemberValue</code>. * * @param cp the constant pool table. * @param type the type of the member. * @return the member value * @throws NotFoundException when the type is not found */ public static MemberValue createMemberValue(ConstPool cp, CtClass type) throws NotFoundException { if (type == CtClass.booleanType) return new BooleanMemberValue(cp); else if (type == CtClass.byteType) return new ByteMemberValue(cp); else if (type == CtClass.charType) return new CharMemberValue(cp); else if (type == CtClass.shortType) return new ShortMemberValue(cp); else if (type == CtClass.intType) return new IntegerMemberValue(cp); else if (type == CtClass.longType) return new LongMemberValue(cp); else if (type == CtClass.floatType) return new FloatMemberValue(cp); else if (type == CtClass.doubleType) return new DoubleMemberValue(cp); else if (type.getName().equals("java.lang.Class")) return new ClassMemberValue(cp); else if (type.getName().equals("java.lang.String")) return new StringMemberValue(cp); else if (type.isArray()) { CtClass arrayType = type.getComponentType(); MemberValue member = createMemberValue(cp, arrayType); return new ArrayMemberValue(member, cp); } else if (type.isInterface()) { Annotation info = new Annotation(cp, type); return new AnnotationMemberValue(info, cp); } else { // treat as enum. I know this is not typed, // but JBoss has an Annotation Compiler for JDK 1.4 // and I want it to work with that. - Bill Burke EnumMemberValue emv = new EnumMemberValue(cp); emv.setType(type.getName()); return emv; } } /** * Adds a new member. * * @param nameIndex the index into the constant pool table. * The entry at that index must be * a <code>CONSTANT_Utf8_info</code> structure. * structure representing the member name. * @param value the member value. */ public void addMemberValue(int nameIndex, MemberValue value) { Pair p = new Pair(); p.name = nameIndex; p.value = value; addMemberValue(p); } /** * Adds a new member. * * @param name the member name. * @param value the member value. */ public void addMemberValue(String name, MemberValue value) { Pair p = new Pair(); p.name = pool.addUtf8Info(name); p.value = value; if (members == null) members = new LinkedHashMap<String,Pair>(); members.put(name, p); } private void addMemberValue(Pair pair) { String name = pool.getUtf8Info(pair.name); if (members == null) members = new LinkedHashMap<String,Pair>(); members.put(name, pair); } /** * Returns a string representation of the annotation. */ @Override public String toString() { StringBuffer buf = new StringBuffer("@"); buf.append(getTypeName()); if (members != null) { buf.append("("); for (String name:members.keySet()) { buf.append(name).append("=") .append(getMemberValue(name)) .append(", "); } buf.setLength(buf.length()-2); buf.append(")"); } return buf.toString(); } /** * Obtains the name of the annotation type. * * @return the type name */ public String getTypeName() { return Descriptor.toClassName(pool.getUtf8Info(typeIndex)); } /** * Obtains all the member names. * * @return null if no members are defined. */ public Set<String> getMemberNames() { if (members == null) return null; return members.keySet(); } /** * Obtains the member value with the given name. * * <p>If this annotation does not have a value for the * specified member, * this method returns null. It does not return a * <code>MemberValue</code> with the default value. * The default value can be obtained from the annotation type. * * @param name the member name * @return null if the member cannot be found or if the value is * the default value. * * @see javassist.bytecode.AnnotationDefaultAttribute */ public MemberValue getMemberValue(String name) { if (members == null||members.get(name) == null) return null; return members.get(name).value; } /** * Constructs an annotation-type object representing this annotation. * For example, if this annotation represents <code>@Author</code>, * this method returns an <code>Author</code> object. * * @param cl class loader for loading an annotation type. * @param cp class pool for obtaining class files. * @return the annotation * @throws ClassNotFoundException if the class cannot found. * @throws NoSuchClassError if the class linkage fails. */ public Object toAnnotationType(ClassLoader cl, ClassPool cp) throws ClassNotFoundException, NoSuchClassError { Class<?> clazz = MemberValue.loadClass(cl, getTypeName()); try { return AnnotationImpl.make(cl, clazz, cp, this); } catch (IllegalArgumentException e) { /* AnnotationImpl.make() may throw this exception * when it fails to make a proxy object for some * reason. */ throw new ClassNotFoundException(clazz.getName(), e); } catch (IllegalAccessError e2) { // also IllegalAccessError throw new ClassNotFoundException(clazz.getName(), e2); } } /** * Writes this annotation. * * @param writer the output. * @throws IOException for an error during the write */ public void write(AnnotationsWriter writer) throws IOException {<FILL_FUNCTION_BODY>
String typeName = pool.getUtf8Info(typeIndex); if (members == null) { writer.annotation(typeName, 0); return; } writer.annotation(typeName, members.size()); for (Pair pair:members.values()) { writer.memberValuePair(pair.name); pair.value.write(writer); }
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/annotation/Annotation.java
Pair
hashCode
class Pair { int name; MemberValue value; } ConstPool pool; int typeIndex; Map<String,Pair> members; // this sould be LinkedHashMap // but it is not supported by JDK 1.3. /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param type the index into the constant pool table. * the entry at that index must be the * <code>CONSTANT_Utf8_Info</code> structure * repreenting the name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(int type, ConstPool cp) { pool = cp; typeIndex = type; members = null; } /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param typeName the fully-qualified name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(String typeName, ConstPool cp) { this(cp.addUtf8Info(Descriptor.of(typeName)), cp); } /** * Constructs an annotation that can be accessed through the interface * represented by <code>clazz</code>. The values of the members are * not specified. * * @param cp the constant pool table. * @param clazz the interface. * @throws NotFoundException when the clazz is not found */ public Annotation(ConstPool cp, CtClass clazz) throws NotFoundException { // todo Enums are not supported right now. this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp); if (!clazz.isInterface()) throw new RuntimeException( "Only interfaces are allowed for Annotation creation."); CtMethod[] methods = clazz.getDeclaredMethods(); if (methods.length > 0) members = new LinkedHashMap<String,Pair>(); for (CtMethod m:methods) addMemberValue(m.getName(), createMemberValue(cp, m.getReturnType())); } /** * Makes an instance of <code>MemberValue</code>. * * @param cp the constant pool table. * @param type the type of the member. * @return the member value * @throws NotFoundException when the type is not found */ public static MemberValue createMemberValue(ConstPool cp, CtClass type) throws NotFoundException { if (type == CtClass.booleanType) return new BooleanMemberValue(cp); else if (type == CtClass.byteType) return new ByteMemberValue(cp); else if (type == CtClass.charType) return new CharMemberValue(cp); else if (type == CtClass.shortType) return new ShortMemberValue(cp); else if (type == CtClass.intType) return new IntegerMemberValue(cp); else if (type == CtClass.longType) return new LongMemberValue(cp); else if (type == CtClass.floatType) return new FloatMemberValue(cp); else if (type == CtClass.doubleType) return new DoubleMemberValue(cp); else if (type.getName().equals("java.lang.Class")) return new ClassMemberValue(cp); else if (type.getName().equals("java.lang.String")) return new StringMemberValue(cp); else if (type.isArray()) { CtClass arrayType = type.getComponentType(); MemberValue member = createMemberValue(cp, arrayType); return new ArrayMemberValue(member, cp); } else if (type.isInterface()) { Annotation info = new Annotation(cp, type); return new AnnotationMemberValue(info, cp); } else { // treat as enum. I know this is not typed, // but JBoss has an Annotation Compiler for JDK 1.4 // and I want it to work with that. - Bill Burke EnumMemberValue emv = new EnumMemberValue(cp); emv.setType(type.getName()); return emv; } } /** * Adds a new member. * * @param nameIndex the index into the constant pool table. * The entry at that index must be * a <code>CONSTANT_Utf8_info</code> structure. * structure representing the member name. * @param value the member value. */ public void addMemberValue(int nameIndex, MemberValue value) { Pair p = new Pair(); p.name = nameIndex; p.value = value; addMemberValue(p); } /** * Adds a new member. * * @param name the member name. * @param value the member value. */ public void addMemberValue(String name, MemberValue value) { Pair p = new Pair(); p.name = pool.addUtf8Info(name); p.value = value; if (members == null) members = new LinkedHashMap<String,Pair>(); members.put(name, p); } private void addMemberValue(Pair pair) { String name = pool.getUtf8Info(pair.name); if (members == null) members = new LinkedHashMap<String,Pair>(); members.put(name, pair); } /** * Returns a string representation of the annotation. */ @Override public String toString() { StringBuffer buf = new StringBuffer("@"); buf.append(getTypeName()); if (members != null) { buf.append("("); for (String name:members.keySet()) { buf.append(name).append("=") .append(getMemberValue(name)) .append(", "); } buf.setLength(buf.length()-2); buf.append(")"); } return buf.toString(); } /** * Obtains the name of the annotation type. * * @return the type name */ public String getTypeName() { return Descriptor.toClassName(pool.getUtf8Info(typeIndex)); } /** * Obtains all the member names. * * @return null if no members are defined. */ public Set<String> getMemberNames() { if (members == null) return null; return members.keySet(); } /** * Obtains the member value with the given name. * * <p>If this annotation does not have a value for the * specified member, * this method returns null. It does not return a * <code>MemberValue</code> with the default value. * The default value can be obtained from the annotation type. * * @param name the member name * @return null if the member cannot be found or if the value is * the default value. * * @see javassist.bytecode.AnnotationDefaultAttribute */ public MemberValue getMemberValue(String name) { if (members == null||members.get(name) == null) return null; return members.get(name).value; } /** * Constructs an annotation-type object representing this annotation. * For example, if this annotation represents <code>@Author</code>, * this method returns an <code>Author</code> object. * * @param cl class loader for loading an annotation type. * @param cp class pool for obtaining class files. * @return the annotation * @throws ClassNotFoundException if the class cannot found. * @throws NoSuchClassError if the class linkage fails. */ public Object toAnnotationType(ClassLoader cl, ClassPool cp) throws ClassNotFoundException, NoSuchClassError { Class<?> clazz = MemberValue.loadClass(cl, getTypeName()); try { return AnnotationImpl.make(cl, clazz, cp, this); } catch (IllegalArgumentException e) { /* AnnotationImpl.make() may throw this exception * when it fails to make a proxy object for some * reason. */ throw new ClassNotFoundException(clazz.getName(), e); } catch (IllegalAccessError e2) { // also IllegalAccessError throw new ClassNotFoundException(clazz.getName(), e2); } } /** * Writes this annotation. * * @param writer the output. * @throws IOException for an error during the write */ public void write(AnnotationsWriter writer) throws IOException { String typeName = pool.getUtf8Info(typeIndex); if (members == null) { writer.annotation(typeName, 0); return; } writer.annotation(typeName, members.size()); for (Pair pair:members.values()) { writer.memberValuePair(pair.name); pair.value.write(writer); } } @Override public int hashCode() {<FILL_FUNCTION_BODY>
return getTypeName().hashCode() + (members == null ? 0 : members.hashCode());
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/annotation/Annotation.java
Pair
equals
class Pair { int name; MemberValue value; } ConstPool pool; int typeIndex; Map<String,Pair> members; // this sould be LinkedHashMap // but it is not supported by JDK 1.3. /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param type the index into the constant pool table. * the entry at that index must be the * <code>CONSTANT_Utf8_Info</code> structure * repreenting the name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(int type, ConstPool cp) { pool = cp; typeIndex = type; members = null; } /** * Constructs an annotation including no members. A member can be * later added to the created annotation by <code>addMemberValue()</code>. * * @param typeName the fully-qualified name of the annotation interface type. * @param cp the constant pool table. * * @see #addMemberValue(String, MemberValue) */ public Annotation(String typeName, ConstPool cp) { this(cp.addUtf8Info(Descriptor.of(typeName)), cp); } /** * Constructs an annotation that can be accessed through the interface * represented by <code>clazz</code>. The values of the members are * not specified. * * @param cp the constant pool table. * @param clazz the interface. * @throws NotFoundException when the clazz is not found */ public Annotation(ConstPool cp, CtClass clazz) throws NotFoundException { // todo Enums are not supported right now. this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp); if (!clazz.isInterface()) throw new RuntimeException( "Only interfaces are allowed for Annotation creation."); CtMethod[] methods = clazz.getDeclaredMethods(); if (methods.length > 0) members = new LinkedHashMap<String,Pair>(); for (CtMethod m:methods) addMemberValue(m.getName(), createMemberValue(cp, m.getReturnType())); } /** * Makes an instance of <code>MemberValue</code>. * * @param cp the constant pool table. * @param type the type of the member. * @return the member value * @throws NotFoundException when the type is not found */ public static MemberValue createMemberValue(ConstPool cp, CtClass type) throws NotFoundException { if (type == CtClass.booleanType) return new BooleanMemberValue(cp); else if (type == CtClass.byteType) return new ByteMemberValue(cp); else if (type == CtClass.charType) return new CharMemberValue(cp); else if (type == CtClass.shortType) return new ShortMemberValue(cp); else if (type == CtClass.intType) return new IntegerMemberValue(cp); else if (type == CtClass.longType) return new LongMemberValue(cp); else if (type == CtClass.floatType) return new FloatMemberValue(cp); else if (type == CtClass.doubleType) return new DoubleMemberValue(cp); else if (type.getName().equals("java.lang.Class")) return new ClassMemberValue(cp); else if (type.getName().equals("java.lang.String")) return new StringMemberValue(cp); else if (type.isArray()) { CtClass arrayType = type.getComponentType(); MemberValue member = createMemberValue(cp, arrayType); return new ArrayMemberValue(member, cp); } else if (type.isInterface()) { Annotation info = new Annotation(cp, type); return new AnnotationMemberValue(info, cp); } else { // treat as enum. I know this is not typed, // but JBoss has an Annotation Compiler for JDK 1.4 // and I want it to work with that. - Bill Burke EnumMemberValue emv = new EnumMemberValue(cp); emv.setType(type.getName()); return emv; } } /** * Adds a new member. * * @param nameIndex the index into the constant pool table. * The entry at that index must be * a <code>CONSTANT_Utf8_info</code> structure. * structure representing the member name. * @param value the member value. */ public void addMemberValue(int nameIndex, MemberValue value) { Pair p = new Pair(); p.name = nameIndex; p.value = value; addMemberValue(p); } /** * Adds a new member. * * @param name the member name. * @param value the member value. */ public void addMemberValue(String name, MemberValue value) { Pair p = new Pair(); p.name = pool.addUtf8Info(name); p.value = value; if (members == null) members = new LinkedHashMap<String,Pair>(); members.put(name, p); } private void addMemberValue(Pair pair) { String name = pool.getUtf8Info(pair.name); if (members == null) members = new LinkedHashMap<String,Pair>(); members.put(name, pair); } /** * Returns a string representation of the annotation. */ @Override public String toString() { StringBuffer buf = new StringBuffer("@"); buf.append(getTypeName()); if (members != null) { buf.append("("); for (String name:members.keySet()) { buf.append(name).append("=") .append(getMemberValue(name)) .append(", "); } buf.setLength(buf.length()-2); buf.append(")"); } return buf.toString(); } /** * Obtains the name of the annotation type. * * @return the type name */ public String getTypeName() { return Descriptor.toClassName(pool.getUtf8Info(typeIndex)); } /** * Obtains all the member names. * * @return null if no members are defined. */ public Set<String> getMemberNames() { if (members == null) return null; return members.keySet(); } /** * Obtains the member value with the given name. * * <p>If this annotation does not have a value for the * specified member, * this method returns null. It does not return a * <code>MemberValue</code> with the default value. * The default value can be obtained from the annotation type. * * @param name the member name * @return null if the member cannot be found or if the value is * the default value. * * @see javassist.bytecode.AnnotationDefaultAttribute */ public MemberValue getMemberValue(String name) { if (members == null||members.get(name) == null) return null; return members.get(name).value; } /** * Constructs an annotation-type object representing this annotation. * For example, if this annotation represents <code>@Author</code>, * this method returns an <code>Author</code> object. * * @param cl class loader for loading an annotation type. * @param cp class pool for obtaining class files. * @return the annotation * @throws ClassNotFoundException if the class cannot found. * @throws NoSuchClassError if the class linkage fails. */ public Object toAnnotationType(ClassLoader cl, ClassPool cp) throws ClassNotFoundException, NoSuchClassError { Class<?> clazz = MemberValue.loadClass(cl, getTypeName()); try { return AnnotationImpl.make(cl, clazz, cp, this); } catch (IllegalArgumentException e) { /* AnnotationImpl.make() may throw this exception * when it fails to make a proxy object for some * reason. */ throw new ClassNotFoundException(clazz.getName(), e); } catch (IllegalAccessError e2) { // also IllegalAccessError throw new ClassNotFoundException(clazz.getName(), e2); } } /** * Writes this annotation. * * @param writer the output. * @throws IOException for an error during the write */ public void write(AnnotationsWriter writer) throws IOException { String typeName = pool.getUtf8Info(typeIndex); if (members == null) { writer.annotation(typeName, 0); return; } writer.annotation(typeName, members.size()); for (Pair pair:members.values()) { writer.memberValuePair(pair.name); pair.value.write(writer); } } @Override public int hashCode() { return getTypeName().hashCode() + (members == null ? 0 : members.hashCode()); } /** * Returns true if the given object represents the same annotation * as this object. The equality test checks the member values. */ @Override public boolean equals(Object obj) {<FILL_FUNCTION_BODY>
if (obj == this) return true; if (obj == null || obj instanceof Annotation == false) return false; Annotation other = (Annotation) obj; if (getTypeName().equals(other.getTypeName()) == false) return false; Map<String,Pair> otherMembers = other.members; if (members == otherMembers) return true; else if (members == null) return otherMembers == null; else if (otherMembers == null) return false; else return members.equals(otherMembers);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/stackmap/TypedBlock.java
TypedBlock
makeBlocks
class TypedBlock extends BasicBlock { public int stackTop, numLocals; // localsTypes is set to non-null when this block is first visited by a MapMaker. // see alreadySet(). public TypeData[] localsTypes; public TypeData[] stackTypes; /** * Divides the method body into basic blocks. * The type information of the first block is initialized. * * @param optimize if it is true and the method does not include * branches, this method returns null. */ public static TypedBlock[] makeBlocks(MethodInfo minfo, CodeAttribute ca, boolean optimize) throws BadBytecode {<FILL_FUNCTION_BODY>} protected TypedBlock(int pos) { super(pos); localsTypes = null; } @Override protected void toString2(StringBuffer sbuf) { super.toString2(sbuf); sbuf.append(",\n stack={"); printTypes(sbuf, stackTop, stackTypes); sbuf.append("}, locals={"); printTypes(sbuf, numLocals, localsTypes); sbuf.append('}'); } private void printTypes(StringBuffer sbuf, int size, TypeData[] types) { if (types == null) return; for (int i = 0; i < size; i++) { if (i > 0) sbuf.append(", "); TypeData td = types[i]; sbuf.append(td == null ? "<>" : td.toString()); } } public boolean alreadySet() { return localsTypes != null; } public void setStackMap(int st, TypeData[] stack, int nl, TypeData[] locals) throws BadBytecode { stackTop = st; stackTypes = stack; numLocals = nl; localsTypes = locals; } /* * Computes the correct value of numLocals. */ public void resetNumLocals() { if (localsTypes != null) { int nl = localsTypes.length; while (nl > 0 && localsTypes[nl - 1].isBasicType() == TypeTag.TOP) { if (nl > 1) { if (localsTypes[nl - 2].is2WordType()) break; } --nl; } numLocals = nl; } } public static class Maker extends BasicBlock.Maker { @Override protected BasicBlock makeBlock(int pos) { return new TypedBlock(pos); } @Override protected BasicBlock[] makeArray(int size) { return new TypedBlock[size]; } } /** * Initializes the first block by the given method descriptor. * * @param block the first basic block that this method initializes. * @param className a dot-separated fully qualified class name. * For example, <code>javassist.bytecode.stackmap.BasicBlock</code>. * @param methodDesc method descriptor. * @param isStatic true if the method is a static method. * @param isConstructor true if the method is a constructor. */ void initFirstBlock(int maxStack, int maxLocals, String className, String methodDesc, boolean isStatic, boolean isConstructor) throws BadBytecode { if (methodDesc.charAt(0) != '(') throw new BadBytecode("no method descriptor: " + methodDesc); stackTop = 0; stackTypes = TypeData.make(maxStack); TypeData[] locals = TypeData.make(maxLocals); if (isConstructor) locals[0] = new TypeData.UninitThis(className); else if (!isStatic) locals[0] = new TypeData.ClassName(className); int n = isStatic ? -1 : 0; int i = 1; try { while ((i = descToTag(methodDesc, i, ++n, locals)) > 0) if (locals[n].is2WordType()) locals[++n] = TypeTag.TOP; } catch (StringIndexOutOfBoundsException e) { throw new BadBytecode("bad method descriptor: " + methodDesc); } numLocals = n; localsTypes = locals; } private static int descToTag(String desc, int i, int n, TypeData[] types) throws BadBytecode { int i0 = i; int arrayDim = 0; char c = desc.charAt(i); if (c == ')') return 0; while (c == '[') { ++arrayDim; c = desc.charAt(++i); } if (c == 'L') { int i2 = desc.indexOf(';', ++i); if (arrayDim > 0) types[n] = new TypeData.ClassName(desc.substring(i0, ++i2)); else types[n] = new TypeData.ClassName(desc.substring(i0 + 1, ++i2 - 1) .replace('/', '.')); return i2; } else if (arrayDim > 0) { types[n] = new TypeData.ClassName(desc.substring(i0, ++i)); return i; } else { TypeData t = toPrimitiveTag(c); if (t == null) throw new BadBytecode("bad method descriptor: " + desc); types[n] = t; return i + 1; } } private static TypeData toPrimitiveTag(char c) { switch (c) { case 'Z' : case 'C' : case 'B' : case 'S' : case 'I' : return TypeTag.INTEGER; case 'J' : return TypeTag.LONG; case 'F' : return TypeTag.FLOAT; case 'D' : return TypeTag.DOUBLE; case 'V' : default : return null; } } public static String getRetType(String desc) { int i = desc.indexOf(')'); if (i < 0) return "java.lang.Object"; char c = desc.charAt(i + 1); if (c == '[') return desc.substring(i + 1); else if (c == 'L') return desc.substring(i + 2, desc.length() - 1).replace('/', '.'); else return "java.lang.Object"; } }
TypedBlock[] blocks = (TypedBlock[])new Maker().make(minfo); if (optimize && blocks.length < 2) if (blocks.length == 0 || blocks[0].incoming == 0) return null; ConstPool pool = minfo.getConstPool(); boolean isStatic = (minfo.getAccessFlags() & AccessFlag.STATIC) != 0; blocks[0].initFirstBlock(ca.getMaxStack(), ca.getMaxLocals(), pool.getClassName(), minfo.getDescriptor(), isStatic, minfo.isConstructor()); return blocks;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/stackmap/TypedBlock.java
TypedBlock
toString2
class TypedBlock extends BasicBlock { public int stackTop, numLocals; // localsTypes is set to non-null when this block is first visited by a MapMaker. // see alreadySet(). public TypeData[] localsTypes; public TypeData[] stackTypes; /** * Divides the method body into basic blocks. * The type information of the first block is initialized. * * @param optimize if it is true and the method does not include * branches, this method returns null. */ public static TypedBlock[] makeBlocks(MethodInfo minfo, CodeAttribute ca, boolean optimize) throws BadBytecode { TypedBlock[] blocks = (TypedBlock[])new Maker().make(minfo); if (optimize && blocks.length < 2) if (blocks.length == 0 || blocks[0].incoming == 0) return null; ConstPool pool = minfo.getConstPool(); boolean isStatic = (minfo.getAccessFlags() & AccessFlag.STATIC) != 0; blocks[0].initFirstBlock(ca.getMaxStack(), ca.getMaxLocals(), pool.getClassName(), minfo.getDescriptor(), isStatic, minfo.isConstructor()); return blocks; } protected TypedBlock(int pos) { super(pos); localsTypes = null; } @Override protected void toString2(StringBuffer sbuf) {<FILL_FUNCTION_BODY>} private void printTypes(StringBuffer sbuf, int size, TypeData[] types) { if (types == null) return; for (int i = 0; i < size; i++) { if (i > 0) sbuf.append(", "); TypeData td = types[i]; sbuf.append(td == null ? "<>" : td.toString()); } } public boolean alreadySet() { return localsTypes != null; } public void setStackMap(int st, TypeData[] stack, int nl, TypeData[] locals) throws BadBytecode { stackTop = st; stackTypes = stack; numLocals = nl; localsTypes = locals; } /* * Computes the correct value of numLocals. */ public void resetNumLocals() { if (localsTypes != null) { int nl = localsTypes.length; while (nl > 0 && localsTypes[nl - 1].isBasicType() == TypeTag.TOP) { if (nl > 1) { if (localsTypes[nl - 2].is2WordType()) break; } --nl; } numLocals = nl; } } public static class Maker extends BasicBlock.Maker { @Override protected BasicBlock makeBlock(int pos) { return new TypedBlock(pos); } @Override protected BasicBlock[] makeArray(int size) { return new TypedBlock[size]; } } /** * Initializes the first block by the given method descriptor. * * @param block the first basic block that this method initializes. * @param className a dot-separated fully qualified class name. * For example, <code>javassist.bytecode.stackmap.BasicBlock</code>. * @param methodDesc method descriptor. * @param isStatic true if the method is a static method. * @param isConstructor true if the method is a constructor. */ void initFirstBlock(int maxStack, int maxLocals, String className, String methodDesc, boolean isStatic, boolean isConstructor) throws BadBytecode { if (methodDesc.charAt(0) != '(') throw new BadBytecode("no method descriptor: " + methodDesc); stackTop = 0; stackTypes = TypeData.make(maxStack); TypeData[] locals = TypeData.make(maxLocals); if (isConstructor) locals[0] = new TypeData.UninitThis(className); else if (!isStatic) locals[0] = new TypeData.ClassName(className); int n = isStatic ? -1 : 0; int i = 1; try { while ((i = descToTag(methodDesc, i, ++n, locals)) > 0) if (locals[n].is2WordType()) locals[++n] = TypeTag.TOP; } catch (StringIndexOutOfBoundsException e) { throw new BadBytecode("bad method descriptor: " + methodDesc); } numLocals = n; localsTypes = locals; } private static int descToTag(String desc, int i, int n, TypeData[] types) throws BadBytecode { int i0 = i; int arrayDim = 0; char c = desc.charAt(i); if (c == ')') return 0; while (c == '[') { ++arrayDim; c = desc.charAt(++i); } if (c == 'L') { int i2 = desc.indexOf(';', ++i); if (arrayDim > 0) types[n] = new TypeData.ClassName(desc.substring(i0, ++i2)); else types[n] = new TypeData.ClassName(desc.substring(i0 + 1, ++i2 - 1) .replace('/', '.')); return i2; } else if (arrayDim > 0) { types[n] = new TypeData.ClassName(desc.substring(i0, ++i)); return i; } else { TypeData t = toPrimitiveTag(c); if (t == null) throw new BadBytecode("bad method descriptor: " + desc); types[n] = t; return i + 1; } } private static TypeData toPrimitiveTag(char c) { switch (c) { case 'Z' : case 'C' : case 'B' : case 'S' : case 'I' : return TypeTag.INTEGER; case 'J' : return TypeTag.LONG; case 'F' : return TypeTag.FLOAT; case 'D' : return TypeTag.DOUBLE; case 'V' : default : return null; } } public static String getRetType(String desc) { int i = desc.indexOf(')'); if (i < 0) return "java.lang.Object"; char c = desc.charAt(i + 1); if (c == '[') return desc.substring(i + 1); else if (c == 'L') return desc.substring(i + 2, desc.length() - 1).replace('/', '.'); else return "java.lang.Object"; } }
super.toString2(sbuf); sbuf.append(",\n stack={"); printTypes(sbuf, stackTop, stackTypes); sbuf.append("}, locals={"); printTypes(sbuf, numLocals, localsTypes); sbuf.append('}');
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/stackmap/TypedBlock.java
TypedBlock
printTypes
class TypedBlock extends BasicBlock { public int stackTop, numLocals; // localsTypes is set to non-null when this block is first visited by a MapMaker. // see alreadySet(). public TypeData[] localsTypes; public TypeData[] stackTypes; /** * Divides the method body into basic blocks. * The type information of the first block is initialized. * * @param optimize if it is true and the method does not include * branches, this method returns null. */ public static TypedBlock[] makeBlocks(MethodInfo minfo, CodeAttribute ca, boolean optimize) throws BadBytecode { TypedBlock[] blocks = (TypedBlock[])new Maker().make(minfo); if (optimize && blocks.length < 2) if (blocks.length == 0 || blocks[0].incoming == 0) return null; ConstPool pool = minfo.getConstPool(); boolean isStatic = (minfo.getAccessFlags() & AccessFlag.STATIC) != 0; blocks[0].initFirstBlock(ca.getMaxStack(), ca.getMaxLocals(), pool.getClassName(), minfo.getDescriptor(), isStatic, minfo.isConstructor()); return blocks; } protected TypedBlock(int pos) { super(pos); localsTypes = null; } @Override protected void toString2(StringBuffer sbuf) { super.toString2(sbuf); sbuf.append(",\n stack={"); printTypes(sbuf, stackTop, stackTypes); sbuf.append("}, locals={"); printTypes(sbuf, numLocals, localsTypes); sbuf.append('}'); } private void printTypes(StringBuffer sbuf, int size, TypeData[] types) {<FILL_FUNCTION_BODY>} public boolean alreadySet() { return localsTypes != null; } public void setStackMap(int st, TypeData[] stack, int nl, TypeData[] locals) throws BadBytecode { stackTop = st; stackTypes = stack; numLocals = nl; localsTypes = locals; } /* * Computes the correct value of numLocals. */ public void resetNumLocals() { if (localsTypes != null) { int nl = localsTypes.length; while (nl > 0 && localsTypes[nl - 1].isBasicType() == TypeTag.TOP) { if (nl > 1) { if (localsTypes[nl - 2].is2WordType()) break; } --nl; } numLocals = nl; } } public static class Maker extends BasicBlock.Maker { @Override protected BasicBlock makeBlock(int pos) { return new TypedBlock(pos); } @Override protected BasicBlock[] makeArray(int size) { return new TypedBlock[size]; } } /** * Initializes the first block by the given method descriptor. * * @param block the first basic block that this method initializes. * @param className a dot-separated fully qualified class name. * For example, <code>javassist.bytecode.stackmap.BasicBlock</code>. * @param methodDesc method descriptor. * @param isStatic true if the method is a static method. * @param isConstructor true if the method is a constructor. */ void initFirstBlock(int maxStack, int maxLocals, String className, String methodDesc, boolean isStatic, boolean isConstructor) throws BadBytecode { if (methodDesc.charAt(0) != '(') throw new BadBytecode("no method descriptor: " + methodDesc); stackTop = 0; stackTypes = TypeData.make(maxStack); TypeData[] locals = TypeData.make(maxLocals); if (isConstructor) locals[0] = new TypeData.UninitThis(className); else if (!isStatic) locals[0] = new TypeData.ClassName(className); int n = isStatic ? -1 : 0; int i = 1; try { while ((i = descToTag(methodDesc, i, ++n, locals)) > 0) if (locals[n].is2WordType()) locals[++n] = TypeTag.TOP; } catch (StringIndexOutOfBoundsException e) { throw new BadBytecode("bad method descriptor: " + methodDesc); } numLocals = n; localsTypes = locals; } private static int descToTag(String desc, int i, int n, TypeData[] types) throws BadBytecode { int i0 = i; int arrayDim = 0; char c = desc.charAt(i); if (c == ')') return 0; while (c == '[') { ++arrayDim; c = desc.charAt(++i); } if (c == 'L') { int i2 = desc.indexOf(';', ++i); if (arrayDim > 0) types[n] = new TypeData.ClassName(desc.substring(i0, ++i2)); else types[n] = new TypeData.ClassName(desc.substring(i0 + 1, ++i2 - 1) .replace('/', '.')); return i2; } else if (arrayDim > 0) { types[n] = new TypeData.ClassName(desc.substring(i0, ++i)); return i; } else { TypeData t = toPrimitiveTag(c); if (t == null) throw new BadBytecode("bad method descriptor: " + desc); types[n] = t; return i + 1; } } private static TypeData toPrimitiveTag(char c) { switch (c) { case 'Z' : case 'C' : case 'B' : case 'S' : case 'I' : return TypeTag.INTEGER; case 'J' : return TypeTag.LONG; case 'F' : return TypeTag.FLOAT; case 'D' : return TypeTag.DOUBLE; case 'V' : default : return null; } } public static String getRetType(String desc) { int i = desc.indexOf(')'); if (i < 0) return "java.lang.Object"; char c = desc.charAt(i + 1); if (c == '[') return desc.substring(i + 1); else if (c == 'L') return desc.substring(i + 2, desc.length() - 1).replace('/', '.'); else return "java.lang.Object"; } }
if (types == null) return; for (int i = 0; i < size; i++) { if (i > 0) sbuf.append(", "); TypeData td = types[i]; sbuf.append(td == null ? "<>" : td.toString()); }
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/stackmap/TypedBlock.java
TypedBlock
alreadySet
class TypedBlock extends BasicBlock { public int stackTop, numLocals; // localsTypes is set to non-null when this block is first visited by a MapMaker. // see alreadySet(). public TypeData[] localsTypes; public TypeData[] stackTypes; /** * Divides the method body into basic blocks. * The type information of the first block is initialized. * * @param optimize if it is true and the method does not include * branches, this method returns null. */ public static TypedBlock[] makeBlocks(MethodInfo minfo, CodeAttribute ca, boolean optimize) throws BadBytecode { TypedBlock[] blocks = (TypedBlock[])new Maker().make(minfo); if (optimize && blocks.length < 2) if (blocks.length == 0 || blocks[0].incoming == 0) return null; ConstPool pool = minfo.getConstPool(); boolean isStatic = (minfo.getAccessFlags() & AccessFlag.STATIC) != 0; blocks[0].initFirstBlock(ca.getMaxStack(), ca.getMaxLocals(), pool.getClassName(), minfo.getDescriptor(), isStatic, minfo.isConstructor()); return blocks; } protected TypedBlock(int pos) { super(pos); localsTypes = null; } @Override protected void toString2(StringBuffer sbuf) { super.toString2(sbuf); sbuf.append(",\n stack={"); printTypes(sbuf, stackTop, stackTypes); sbuf.append("}, locals={"); printTypes(sbuf, numLocals, localsTypes); sbuf.append('}'); } private void printTypes(StringBuffer sbuf, int size, TypeData[] types) { if (types == null) return; for (int i = 0; i < size; i++) { if (i > 0) sbuf.append(", "); TypeData td = types[i]; sbuf.append(td == null ? "<>" : td.toString()); } } public boolean alreadySet() {<FILL_FUNCTION_BODY>} public void setStackMap(int st, TypeData[] stack, int nl, TypeData[] locals) throws BadBytecode { stackTop = st; stackTypes = stack; numLocals = nl; localsTypes = locals; } /* * Computes the correct value of numLocals. */ public void resetNumLocals() { if (localsTypes != null) { int nl = localsTypes.length; while (nl > 0 && localsTypes[nl - 1].isBasicType() == TypeTag.TOP) { if (nl > 1) { if (localsTypes[nl - 2].is2WordType()) break; } --nl; } numLocals = nl; } } public static class Maker extends BasicBlock.Maker { @Override protected BasicBlock makeBlock(int pos) { return new TypedBlock(pos); } @Override protected BasicBlock[] makeArray(int size) { return new TypedBlock[size]; } } /** * Initializes the first block by the given method descriptor. * * @param block the first basic block that this method initializes. * @param className a dot-separated fully qualified class name. * For example, <code>javassist.bytecode.stackmap.BasicBlock</code>. * @param methodDesc method descriptor. * @param isStatic true if the method is a static method. * @param isConstructor true if the method is a constructor. */ void initFirstBlock(int maxStack, int maxLocals, String className, String methodDesc, boolean isStatic, boolean isConstructor) throws BadBytecode { if (methodDesc.charAt(0) != '(') throw new BadBytecode("no method descriptor: " + methodDesc); stackTop = 0; stackTypes = TypeData.make(maxStack); TypeData[] locals = TypeData.make(maxLocals); if (isConstructor) locals[0] = new TypeData.UninitThis(className); else if (!isStatic) locals[0] = new TypeData.ClassName(className); int n = isStatic ? -1 : 0; int i = 1; try { while ((i = descToTag(methodDesc, i, ++n, locals)) > 0) if (locals[n].is2WordType()) locals[++n] = TypeTag.TOP; } catch (StringIndexOutOfBoundsException e) { throw new BadBytecode("bad method descriptor: " + methodDesc); } numLocals = n; localsTypes = locals; } private static int descToTag(String desc, int i, int n, TypeData[] types) throws BadBytecode { int i0 = i; int arrayDim = 0; char c = desc.charAt(i); if (c == ')') return 0; while (c == '[') { ++arrayDim; c = desc.charAt(++i); } if (c == 'L') { int i2 = desc.indexOf(';', ++i); if (arrayDim > 0) types[n] = new TypeData.ClassName(desc.substring(i0, ++i2)); else types[n] = new TypeData.ClassName(desc.substring(i0 + 1, ++i2 - 1) .replace('/', '.')); return i2; } else if (arrayDim > 0) { types[n] = new TypeData.ClassName(desc.substring(i0, ++i)); return i; } else { TypeData t = toPrimitiveTag(c); if (t == null) throw new BadBytecode("bad method descriptor: " + desc); types[n] = t; return i + 1; } } private static TypeData toPrimitiveTag(char c) { switch (c) { case 'Z' : case 'C' : case 'B' : case 'S' : case 'I' : return TypeTag.INTEGER; case 'J' : return TypeTag.LONG; case 'F' : return TypeTag.FLOAT; case 'D' : return TypeTag.DOUBLE; case 'V' : default : return null; } } public static String getRetType(String desc) { int i = desc.indexOf(')'); if (i < 0) return "java.lang.Object"; char c = desc.charAt(i + 1); if (c == '[') return desc.substring(i + 1); else if (c == 'L') return desc.substring(i + 2, desc.length() - 1).replace('/', '.'); else return "java.lang.Object"; } }
return localsTypes != null;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/stackmap/TypedBlock.java
TypedBlock
setStackMap
class TypedBlock extends BasicBlock { public int stackTop, numLocals; // localsTypes is set to non-null when this block is first visited by a MapMaker. // see alreadySet(). public TypeData[] localsTypes; public TypeData[] stackTypes; /** * Divides the method body into basic blocks. * The type information of the first block is initialized. * * @param optimize if it is true and the method does not include * branches, this method returns null. */ public static TypedBlock[] makeBlocks(MethodInfo minfo, CodeAttribute ca, boolean optimize) throws BadBytecode { TypedBlock[] blocks = (TypedBlock[])new Maker().make(minfo); if (optimize && blocks.length < 2) if (blocks.length == 0 || blocks[0].incoming == 0) return null; ConstPool pool = minfo.getConstPool(); boolean isStatic = (minfo.getAccessFlags() & AccessFlag.STATIC) != 0; blocks[0].initFirstBlock(ca.getMaxStack(), ca.getMaxLocals(), pool.getClassName(), minfo.getDescriptor(), isStatic, minfo.isConstructor()); return blocks; } protected TypedBlock(int pos) { super(pos); localsTypes = null; } @Override protected void toString2(StringBuffer sbuf) { super.toString2(sbuf); sbuf.append(",\n stack={"); printTypes(sbuf, stackTop, stackTypes); sbuf.append("}, locals={"); printTypes(sbuf, numLocals, localsTypes); sbuf.append('}'); } private void printTypes(StringBuffer sbuf, int size, TypeData[] types) { if (types == null) return; for (int i = 0; i < size; i++) { if (i > 0) sbuf.append(", "); TypeData td = types[i]; sbuf.append(td == null ? "<>" : td.toString()); } } public boolean alreadySet() { return localsTypes != null; } public void setStackMap(int st, TypeData[] stack, int nl, TypeData[] locals) throws BadBytecode {<FILL_FUNCTION_BODY>} /* * Computes the correct value of numLocals. */ public void resetNumLocals() { if (localsTypes != null) { int nl = localsTypes.length; while (nl > 0 && localsTypes[nl - 1].isBasicType() == TypeTag.TOP) { if (nl > 1) { if (localsTypes[nl - 2].is2WordType()) break; } --nl; } numLocals = nl; } } public static class Maker extends BasicBlock.Maker { @Override protected BasicBlock makeBlock(int pos) { return new TypedBlock(pos); } @Override protected BasicBlock[] makeArray(int size) { return new TypedBlock[size]; } } /** * Initializes the first block by the given method descriptor. * * @param block the first basic block that this method initializes. * @param className a dot-separated fully qualified class name. * For example, <code>javassist.bytecode.stackmap.BasicBlock</code>. * @param methodDesc method descriptor. * @param isStatic true if the method is a static method. * @param isConstructor true if the method is a constructor. */ void initFirstBlock(int maxStack, int maxLocals, String className, String methodDesc, boolean isStatic, boolean isConstructor) throws BadBytecode { if (methodDesc.charAt(0) != '(') throw new BadBytecode("no method descriptor: " + methodDesc); stackTop = 0; stackTypes = TypeData.make(maxStack); TypeData[] locals = TypeData.make(maxLocals); if (isConstructor) locals[0] = new TypeData.UninitThis(className); else if (!isStatic) locals[0] = new TypeData.ClassName(className); int n = isStatic ? -1 : 0; int i = 1; try { while ((i = descToTag(methodDesc, i, ++n, locals)) > 0) if (locals[n].is2WordType()) locals[++n] = TypeTag.TOP; } catch (StringIndexOutOfBoundsException e) { throw new BadBytecode("bad method descriptor: " + methodDesc); } numLocals = n; localsTypes = locals; } private static int descToTag(String desc, int i, int n, TypeData[] types) throws BadBytecode { int i0 = i; int arrayDim = 0; char c = desc.charAt(i); if (c == ')') return 0; while (c == '[') { ++arrayDim; c = desc.charAt(++i); } if (c == 'L') { int i2 = desc.indexOf(';', ++i); if (arrayDim > 0) types[n] = new TypeData.ClassName(desc.substring(i0, ++i2)); else types[n] = new TypeData.ClassName(desc.substring(i0 + 1, ++i2 - 1) .replace('/', '.')); return i2; } else if (arrayDim > 0) { types[n] = new TypeData.ClassName(desc.substring(i0, ++i)); return i; } else { TypeData t = toPrimitiveTag(c); if (t == null) throw new BadBytecode("bad method descriptor: " + desc); types[n] = t; return i + 1; } } private static TypeData toPrimitiveTag(char c) { switch (c) { case 'Z' : case 'C' : case 'B' : case 'S' : case 'I' : return TypeTag.INTEGER; case 'J' : return TypeTag.LONG; case 'F' : return TypeTag.FLOAT; case 'D' : return TypeTag.DOUBLE; case 'V' : default : return null; } } public static String getRetType(String desc) { int i = desc.indexOf(')'); if (i < 0) return "java.lang.Object"; char c = desc.charAt(i + 1); if (c == '[') return desc.substring(i + 1); else if (c == 'L') return desc.substring(i + 2, desc.length() - 1).replace('/', '.'); else return "java.lang.Object"; } }
stackTop = st; stackTypes = stack; numLocals = nl; localsTypes = locals;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/stackmap/TypedBlock.java
TypedBlock
resetNumLocals
class TypedBlock extends BasicBlock { public int stackTop, numLocals; // localsTypes is set to non-null when this block is first visited by a MapMaker. // see alreadySet(). public TypeData[] localsTypes; public TypeData[] stackTypes; /** * Divides the method body into basic blocks. * The type information of the first block is initialized. * * @param optimize if it is true and the method does not include * branches, this method returns null. */ public static TypedBlock[] makeBlocks(MethodInfo minfo, CodeAttribute ca, boolean optimize) throws BadBytecode { TypedBlock[] blocks = (TypedBlock[])new Maker().make(minfo); if (optimize && blocks.length < 2) if (blocks.length == 0 || blocks[0].incoming == 0) return null; ConstPool pool = minfo.getConstPool(); boolean isStatic = (minfo.getAccessFlags() & AccessFlag.STATIC) != 0; blocks[0].initFirstBlock(ca.getMaxStack(), ca.getMaxLocals(), pool.getClassName(), minfo.getDescriptor(), isStatic, minfo.isConstructor()); return blocks; } protected TypedBlock(int pos) { super(pos); localsTypes = null; } @Override protected void toString2(StringBuffer sbuf) { super.toString2(sbuf); sbuf.append(",\n stack={"); printTypes(sbuf, stackTop, stackTypes); sbuf.append("}, locals={"); printTypes(sbuf, numLocals, localsTypes); sbuf.append('}'); } private void printTypes(StringBuffer sbuf, int size, TypeData[] types) { if (types == null) return; for (int i = 0; i < size; i++) { if (i > 0) sbuf.append(", "); TypeData td = types[i]; sbuf.append(td == null ? "<>" : td.toString()); } } public boolean alreadySet() { return localsTypes != null; } public void setStackMap(int st, TypeData[] stack, int nl, TypeData[] locals) throws BadBytecode { stackTop = st; stackTypes = stack; numLocals = nl; localsTypes = locals; } /* * Computes the correct value of numLocals. */ public void resetNumLocals() {<FILL_FUNCTION_BODY>} public static class Maker extends BasicBlock.Maker { @Override protected BasicBlock makeBlock(int pos) { return new TypedBlock(pos); } @Override protected BasicBlock[] makeArray(int size) { return new TypedBlock[size]; } } /** * Initializes the first block by the given method descriptor. * * @param block the first basic block that this method initializes. * @param className a dot-separated fully qualified class name. * For example, <code>javassist.bytecode.stackmap.BasicBlock</code>. * @param methodDesc method descriptor. * @param isStatic true if the method is a static method. * @param isConstructor true if the method is a constructor. */ void initFirstBlock(int maxStack, int maxLocals, String className, String methodDesc, boolean isStatic, boolean isConstructor) throws BadBytecode { if (methodDesc.charAt(0) != '(') throw new BadBytecode("no method descriptor: " + methodDesc); stackTop = 0; stackTypes = TypeData.make(maxStack); TypeData[] locals = TypeData.make(maxLocals); if (isConstructor) locals[0] = new TypeData.UninitThis(className); else if (!isStatic) locals[0] = new TypeData.ClassName(className); int n = isStatic ? -1 : 0; int i = 1; try { while ((i = descToTag(methodDesc, i, ++n, locals)) > 0) if (locals[n].is2WordType()) locals[++n] = TypeTag.TOP; } catch (StringIndexOutOfBoundsException e) { throw new BadBytecode("bad method descriptor: " + methodDesc); } numLocals = n; localsTypes = locals; } private static int descToTag(String desc, int i, int n, TypeData[] types) throws BadBytecode { int i0 = i; int arrayDim = 0; char c = desc.charAt(i); if (c == ')') return 0; while (c == '[') { ++arrayDim; c = desc.charAt(++i); } if (c == 'L') { int i2 = desc.indexOf(';', ++i); if (arrayDim > 0) types[n] = new TypeData.ClassName(desc.substring(i0, ++i2)); else types[n] = new TypeData.ClassName(desc.substring(i0 + 1, ++i2 - 1) .replace('/', '.')); return i2; } else if (arrayDim > 0) { types[n] = new TypeData.ClassName(desc.substring(i0, ++i)); return i; } else { TypeData t = toPrimitiveTag(c); if (t == null) throw new BadBytecode("bad method descriptor: " + desc); types[n] = t; return i + 1; } } private static TypeData toPrimitiveTag(char c) { switch (c) { case 'Z' : case 'C' : case 'B' : case 'S' : case 'I' : return TypeTag.INTEGER; case 'J' : return TypeTag.LONG; case 'F' : return TypeTag.FLOAT; case 'D' : return TypeTag.DOUBLE; case 'V' : default : return null; } } public static String getRetType(String desc) { int i = desc.indexOf(')'); if (i < 0) return "java.lang.Object"; char c = desc.charAt(i + 1); if (c == '[') return desc.substring(i + 1); else if (c == 'L') return desc.substring(i + 2, desc.length() - 1).replace('/', '.'); else return "java.lang.Object"; } }
if (localsTypes != null) { int nl = localsTypes.length; while (nl > 0 && localsTypes[nl - 1].isBasicType() == TypeTag.TOP) { if (nl > 1) { if (localsTypes[nl - 2].is2WordType()) break; } --nl; } numLocals = nl; }
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/stackmap/TypedBlock.java
Maker
makeBlock
class Maker extends BasicBlock.Maker { @Override protected BasicBlock makeBlock(int pos) {<FILL_FUNCTION_BODY>} @Override protected BasicBlock[] makeArray(int size) { return new TypedBlock[size]; } }
return new TypedBlock(pos);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/stackmap/TypedBlock.java
Maker
makeArray
class Maker extends BasicBlock.Maker { @Override protected BasicBlock makeBlock(int pos) { return new TypedBlock(pos); } @Override protected BasicBlock[] makeArray(int size) {<FILL_FUNCTION_BODY>} }
return new TypedBlock[size];
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/stackmap/TypedBlock.java
Maker
initFirstBlock
class Maker extends BasicBlock.Maker { @Override protected BasicBlock makeBlock(int pos) { return new TypedBlock(pos); } @Override protected BasicBlock[] makeArray(int size) { return new TypedBlock[size]; } } /** * Initializes the first block by the given method descriptor. * * @param block the first basic block that this method initializes. * @param className a dot-separated fully qualified class name. * For example, <code>javassist.bytecode.stackmap.BasicBlock</code>. * @param methodDesc method descriptor. * @param isStatic true if the method is a static method. * @param isConstructor true if the method is a constructor. */ void initFirstBlock(int maxStack, int maxLocals, String className, String methodDesc, boolean isStatic, boolean isConstructor) throws BadBytecode {<FILL_FUNCTION_BODY>
if (methodDesc.charAt(0) != '(') throw new BadBytecode("no method descriptor: " + methodDesc); stackTop = 0; stackTypes = TypeData.make(maxStack); TypeData[] locals = TypeData.make(maxLocals); if (isConstructor) locals[0] = new TypeData.UninitThis(className); else if (!isStatic) locals[0] = new TypeData.ClassName(className); int n = isStatic ? -1 : 0; int i = 1; try { while ((i = descToTag(methodDesc, i, ++n, locals)) > 0) if (locals[n].is2WordType()) locals[++n] = TypeTag.TOP; } catch (StringIndexOutOfBoundsException e) { throw new BadBytecode("bad method descriptor: " + methodDesc); } numLocals = n; localsTypes = locals;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/stackmap/TypedBlock.java
Maker
descToTag
class Maker extends BasicBlock.Maker { @Override protected BasicBlock makeBlock(int pos) { return new TypedBlock(pos); } @Override protected BasicBlock[] makeArray(int size) { return new TypedBlock[size]; } } /** * Initializes the first block by the given method descriptor. * * @param block the first basic block that this method initializes. * @param className a dot-separated fully qualified class name. * For example, <code>javassist.bytecode.stackmap.BasicBlock</code>. * @param methodDesc method descriptor. * @param isStatic true if the method is a static method. * @param isConstructor true if the method is a constructor. */ void initFirstBlock(int maxStack, int maxLocals, String className, String methodDesc, boolean isStatic, boolean isConstructor) throws BadBytecode { if (methodDesc.charAt(0) != '(') throw new BadBytecode("no method descriptor: " + methodDesc); stackTop = 0; stackTypes = TypeData.make(maxStack); TypeData[] locals = TypeData.make(maxLocals); if (isConstructor) locals[0] = new TypeData.UninitThis(className); else if (!isStatic) locals[0] = new TypeData.ClassName(className); int n = isStatic ? -1 : 0; int i = 1; try { while ((i = descToTag(methodDesc, i, ++n, locals)) > 0) if (locals[n].is2WordType()) locals[++n] = TypeTag.TOP; } catch (StringIndexOutOfBoundsException e) { throw new BadBytecode("bad method descriptor: " + methodDesc); } numLocals = n; localsTypes = locals; } private static int descToTag(String desc, int i, int n, TypeData[] types) throws BadBytecode {<FILL_FUNCTION_BODY>
int i0 = i; int arrayDim = 0; char c = desc.charAt(i); if (c == ')') return 0; while (c == '[') { ++arrayDim; c = desc.charAt(++i); } if (c == 'L') { int i2 = desc.indexOf(';', ++i); if (arrayDim > 0) types[n] = new TypeData.ClassName(desc.substring(i0, ++i2)); else types[n] = new TypeData.ClassName(desc.substring(i0 + 1, ++i2 - 1) .replace('/', '.')); return i2; } else if (arrayDim > 0) { types[n] = new TypeData.ClassName(desc.substring(i0, ++i)); return i; } else { TypeData t = toPrimitiveTag(c); if (t == null) throw new BadBytecode("bad method descriptor: " + desc); types[n] = t; return i + 1; }
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/stackmap/TypedBlock.java
Maker
toPrimitiveTag
class Maker extends BasicBlock.Maker { @Override protected BasicBlock makeBlock(int pos) { return new TypedBlock(pos); } @Override protected BasicBlock[] makeArray(int size) { return new TypedBlock[size]; } } /** * Initializes the first block by the given method descriptor. * * @param block the first basic block that this method initializes. * @param className a dot-separated fully qualified class name. * For example, <code>javassist.bytecode.stackmap.BasicBlock</code>. * @param methodDesc method descriptor. * @param isStatic true if the method is a static method. * @param isConstructor true if the method is a constructor. */ void initFirstBlock(int maxStack, int maxLocals, String className, String methodDesc, boolean isStatic, boolean isConstructor) throws BadBytecode { if (methodDesc.charAt(0) != '(') throw new BadBytecode("no method descriptor: " + methodDesc); stackTop = 0; stackTypes = TypeData.make(maxStack); TypeData[] locals = TypeData.make(maxLocals); if (isConstructor) locals[0] = new TypeData.UninitThis(className); else if (!isStatic) locals[0] = new TypeData.ClassName(className); int n = isStatic ? -1 : 0; int i = 1; try { while ((i = descToTag(methodDesc, i, ++n, locals)) > 0) if (locals[n].is2WordType()) locals[++n] = TypeTag.TOP; } catch (StringIndexOutOfBoundsException e) { throw new BadBytecode("bad method descriptor: " + methodDesc); } numLocals = n; localsTypes = locals; } private static int descToTag(String desc, int i, int n, TypeData[] types) throws BadBytecode { int i0 = i; int arrayDim = 0; char c = desc.charAt(i); if (c == ')') return 0; while (c == '[') { ++arrayDim; c = desc.charAt(++i); } if (c == 'L') { int i2 = desc.indexOf(';', ++i); if (arrayDim > 0) types[n] = new TypeData.ClassName(desc.substring(i0, ++i2)); else types[n] = new TypeData.ClassName(desc.substring(i0 + 1, ++i2 - 1) .replace('/', '.')); return i2; } else if (arrayDim > 0) { types[n] = new TypeData.ClassName(desc.substring(i0, ++i)); return i; } else { TypeData t = toPrimitiveTag(c); if (t == null) throw new BadBytecode("bad method descriptor: " + desc); types[n] = t; return i + 1; } } private static TypeData toPrimitiveTag(char c) {<FILL_FUNCTION_BODY>
switch (c) { case 'Z' : case 'C' : case 'B' : case 'S' : case 'I' : return TypeTag.INTEGER; case 'J' : return TypeTag.LONG; case 'F' : return TypeTag.FLOAT; case 'D' : return TypeTag.DOUBLE; case 'V' : default : return null; }
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/stackmap/TypedBlock.java
Maker
getRetType
class Maker extends BasicBlock.Maker { @Override protected BasicBlock makeBlock(int pos) { return new TypedBlock(pos); } @Override protected BasicBlock[] makeArray(int size) { return new TypedBlock[size]; } } /** * Initializes the first block by the given method descriptor. * * @param block the first basic block that this method initializes. * @param className a dot-separated fully qualified class name. * For example, <code>javassist.bytecode.stackmap.BasicBlock</code>. * @param methodDesc method descriptor. * @param isStatic true if the method is a static method. * @param isConstructor true if the method is a constructor. */ void initFirstBlock(int maxStack, int maxLocals, String className, String methodDesc, boolean isStatic, boolean isConstructor) throws BadBytecode { if (methodDesc.charAt(0) != '(') throw new BadBytecode("no method descriptor: " + methodDesc); stackTop = 0; stackTypes = TypeData.make(maxStack); TypeData[] locals = TypeData.make(maxLocals); if (isConstructor) locals[0] = new TypeData.UninitThis(className); else if (!isStatic) locals[0] = new TypeData.ClassName(className); int n = isStatic ? -1 : 0; int i = 1; try { while ((i = descToTag(methodDesc, i, ++n, locals)) > 0) if (locals[n].is2WordType()) locals[++n] = TypeTag.TOP; } catch (StringIndexOutOfBoundsException e) { throw new BadBytecode("bad method descriptor: " + methodDesc); } numLocals = n; localsTypes = locals; } private static int descToTag(String desc, int i, int n, TypeData[] types) throws BadBytecode { int i0 = i; int arrayDim = 0; char c = desc.charAt(i); if (c == ')') return 0; while (c == '[') { ++arrayDim; c = desc.charAt(++i); } if (c == 'L') { int i2 = desc.indexOf(';', ++i); if (arrayDim > 0) types[n] = new TypeData.ClassName(desc.substring(i0, ++i2)); else types[n] = new TypeData.ClassName(desc.substring(i0 + 1, ++i2 - 1) .replace('/', '.')); return i2; } else if (arrayDim > 0) { types[n] = new TypeData.ClassName(desc.substring(i0, ++i)); return i; } else { TypeData t = toPrimitiveTag(c); if (t == null) throw new BadBytecode("bad method descriptor: " + desc); types[n] = t; return i + 1; } } private static TypeData toPrimitiveTag(char c) { switch (c) { case 'Z' : case 'C' : case 'B' : case 'S' : case 'I' : return TypeTag.INTEGER; case 'J' : return TypeTag.LONG; case 'F' : return TypeTag.FLOAT; case 'D' : return TypeTag.DOUBLE; case 'V' : default : return null; } } public static String getRetType(String desc) {<FILL_FUNCTION_BODY>
int i = desc.indexOf(')'); if (i < 0) return "java.lang.Object"; char c = desc.charAt(i + 1); if (c == '[') return desc.substring(i + 1); else if (c == 'L') return desc.substring(i + 2, desc.length() - 1).replace('/', '.'); else return "java.lang.Object";
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
MemberResolver
getClassPool
class MemberResolver implements TokenId { private ClassPool classPool; public MemberResolver(ClassPool cp) { classPool = cp; } public ClassPool getClassPool() {<FILL_FUNCTION_BODY>} private static void fatal() throws CompileError { throw new CompileError("fatal"); } public static class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError { return lookupClass(Declarator.astToClassName(name, '.'), false); } public CtClass lookupClassByJvmName(String jvmName) throws CompileError { return lookupClass(jvmToJavaName(jvmName), false); } public CtClass lookupClass(Declarator decl) throws CompileError { return lookupClass(decl.getType(), decl.getArrayDim(), decl.getClassName()); } /** * @param classname jvm class name. */ public CtClass lookupClass(int type, int dim, String classname) throws CompileError { String cname = ""; CtClass clazz; if (type == CLASS) { clazz = lookupClassByJvmName(classname); if (dim > 0) cname = clazz.getName(); else return clazz; } else cname = getTypeName(type); while (dim-- > 0) cname += "[]"; return lookupClass(cname, false); } /* * type cannot be CLASS */ static String getTypeName(int type) throws CompileError { String cname = ""; switch (type) { case BOOLEAN : cname = "boolean"; break; case CHAR : cname = "char"; break; case BYTE : cname = "byte"; break; case SHORT : cname = "short"; break; case INT : cname = "int"; break; case LONG : cname = "long"; break; case FLOAT : cname = "float"; break; case DOUBLE : cname = "double"; break; case VOID : cname = "void"; break; default : fatal(); } return cname; } /** * @param name a qualified class name. e.g. java.lang.String */ public CtClass lookupClass(String name, boolean notCheckInner) throws CompileError { Map<String,String> cache = getInvalidNames(); String found = cache.get(name); if (found == INVALID) throw new CompileError("no such class: " + name); else if (found != null) try { return classPool.get(found); } catch (NotFoundException e) {} CtClass cc = null; try { cc = lookupClass0(name, notCheckInner); } catch (NotFoundException e) { cc = searchImports(name); } cache.put(name, cc.getName()); return cc; } private static final String INVALID = "<invalid>"; private static Map<ClassPool, Reference<Map<String,String>>> invalidNamesMap = new WeakHashMap<ClassPool, Reference<Map<String,String>>>(); private Map<String,String> invalidNames = null; // for unit tests public static int getInvalidMapSize() { return invalidNamesMap.size(); } private Map<String,String> getInvalidNames() { Map<String,String> ht = invalidNames; if (ht == null) { synchronized (MemberResolver.class) { Reference<Map<String,String>> ref = invalidNamesMap.get(classPool); if (ref != null) ht = ref.get(); if (ht == null) { ht = new Hashtable<String,String>(); invalidNamesMap.put(classPool, new WeakReference<Map<String,String>>(ht)); } } invalidNames = ht; } return ht; } private CtClass searchImports(String orgName) throws CompileError { if (orgName.indexOf('.') < 0) { Iterator<String> it = classPool.getImportedPackages(); while (it.hasNext()) { String pac = it.next(); String fqName = pac.replaceAll("\\.$","") + "." + orgName; try { return classPool.get(fqName); } catch (NotFoundException e) { try { if (pac.endsWith("." + orgName)) return classPool.get(pac); } catch (NotFoundException e2) {} } } } getInvalidNames().put(orgName, INVALID); throw new CompileError("no such class: " + orgName); } private CtClass lookupClass0(String classname, boolean notCheckInner) throws NotFoundException { CtClass cc = null; do { try { cc = classPool.get(classname); } catch (NotFoundException e) { int i = classname.lastIndexOf('.'); if (notCheckInner || i < 0) throw e; StringBuffer sbuf = new StringBuffer(classname); sbuf.setCharAt(i, '$'); classname = sbuf.toString(); } } while (cc == null); return cc; } /* Converts a class name into a JVM-internal representation. * * It may also expand a simple class name to java.lang.*. * For example, this converts Object into java/lang/Object. */ public String resolveClassName(ASTList name) throws CompileError { if (name == null) return null; return javaToJvmName(lookupClassByName(name).getName()); } /* Expands a simple class name to java.lang.*. * For example, this converts Object into java/lang/Object. */ public String resolveJvmClassName(String jvmName) throws CompileError { if (jvmName == null) return null; return javaToJvmName(lookupClassByJvmName(jvmName).getName()); } public static CtClass getSuperclass(CtClass c) throws CompileError { try { CtClass sc = c.getSuperclass(); if (sc != null) return sc; } catch (NotFoundException e) {} throw new CompileError("cannot find the super class of " + c.getName()); } public static CtClass getSuperInterface(CtClass c, String interfaceName) throws CompileError { try { CtClass[] intfs = c.getInterfaces(); for (int i = 0; i < intfs.length; i++) if (intfs[i].getName().equals(interfaceName)) return intfs[i]; } catch (NotFoundException e) {} throw new CompileError("cannot find the super inetrface " + interfaceName + " of " + c.getName()); } public static String javaToJvmName(String classname) { return classname.replace('.', '/'); } public static String jvmToJavaName(String classname) { return classname.replace('/', '.'); } public static int descToType(char c) throws CompileError { switch (c) { case 'Z' : return BOOLEAN; case 'C' : return CHAR; case 'B' : return BYTE; case 'S' : return SHORT; case 'I' : return INT; case 'J' : return LONG; case 'F' : return FLOAT; case 'D' : return DOUBLE; case 'V' : return VOID; case 'L' : case '[' : return CLASS; default : fatal(); return VOID; // never reach here } } public static int getModifiers(ASTList mods) { int m = 0; while (mods != null) { Keyword k = (Keyword)mods.head(); mods = mods.tail(); switch (k.get()) { case STATIC : m |= Modifier.STATIC; break; case FINAL : m |= Modifier.FINAL; break; case SYNCHRONIZED : m |= Modifier.SYNCHRONIZED; break; case ABSTRACT : m |= Modifier.ABSTRACT; break; case PUBLIC : m |= Modifier.PUBLIC; break; case PROTECTED : m |= Modifier.PROTECTED; break; case PRIVATE : m |= Modifier.PRIVATE; break; case VOLATILE : m |= Modifier.VOLATILE; break; case TRANSIENT : m |= Modifier.TRANSIENT; break; case STRICT : m |= Modifier.STRICT; break; } } return m; } }
return classPool;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
MemberResolver
fatal
class MemberResolver implements TokenId { private ClassPool classPool; public MemberResolver(ClassPool cp) { classPool = cp; } public ClassPool getClassPool() { return classPool; } private static void fatal() throws CompileError {<FILL_FUNCTION_BODY>} public static class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError { return lookupClass(Declarator.astToClassName(name, '.'), false); } public CtClass lookupClassByJvmName(String jvmName) throws CompileError { return lookupClass(jvmToJavaName(jvmName), false); } public CtClass lookupClass(Declarator decl) throws CompileError { return lookupClass(decl.getType(), decl.getArrayDim(), decl.getClassName()); } /** * @param classname jvm class name. */ public CtClass lookupClass(int type, int dim, String classname) throws CompileError { String cname = ""; CtClass clazz; if (type == CLASS) { clazz = lookupClassByJvmName(classname); if (dim > 0) cname = clazz.getName(); else return clazz; } else cname = getTypeName(type); while (dim-- > 0) cname += "[]"; return lookupClass(cname, false); } /* * type cannot be CLASS */ static String getTypeName(int type) throws CompileError { String cname = ""; switch (type) { case BOOLEAN : cname = "boolean"; break; case CHAR : cname = "char"; break; case BYTE : cname = "byte"; break; case SHORT : cname = "short"; break; case INT : cname = "int"; break; case LONG : cname = "long"; break; case FLOAT : cname = "float"; break; case DOUBLE : cname = "double"; break; case VOID : cname = "void"; break; default : fatal(); } return cname; } /** * @param name a qualified class name. e.g. java.lang.String */ public CtClass lookupClass(String name, boolean notCheckInner) throws CompileError { Map<String,String> cache = getInvalidNames(); String found = cache.get(name); if (found == INVALID) throw new CompileError("no such class: " + name); else if (found != null) try { return classPool.get(found); } catch (NotFoundException e) {} CtClass cc = null; try { cc = lookupClass0(name, notCheckInner); } catch (NotFoundException e) { cc = searchImports(name); } cache.put(name, cc.getName()); return cc; } private static final String INVALID = "<invalid>"; private static Map<ClassPool, Reference<Map<String,String>>> invalidNamesMap = new WeakHashMap<ClassPool, Reference<Map<String,String>>>(); private Map<String,String> invalidNames = null; // for unit tests public static int getInvalidMapSize() { return invalidNamesMap.size(); } private Map<String,String> getInvalidNames() { Map<String,String> ht = invalidNames; if (ht == null) { synchronized (MemberResolver.class) { Reference<Map<String,String>> ref = invalidNamesMap.get(classPool); if (ref != null) ht = ref.get(); if (ht == null) { ht = new Hashtable<String,String>(); invalidNamesMap.put(classPool, new WeakReference<Map<String,String>>(ht)); } } invalidNames = ht; } return ht; } private CtClass searchImports(String orgName) throws CompileError { if (orgName.indexOf('.') < 0) { Iterator<String> it = classPool.getImportedPackages(); while (it.hasNext()) { String pac = it.next(); String fqName = pac.replaceAll("\\.$","") + "." + orgName; try { return classPool.get(fqName); } catch (NotFoundException e) { try { if (pac.endsWith("." + orgName)) return classPool.get(pac); } catch (NotFoundException e2) {} } } } getInvalidNames().put(orgName, INVALID); throw new CompileError("no such class: " + orgName); } private CtClass lookupClass0(String classname, boolean notCheckInner) throws NotFoundException { CtClass cc = null; do { try { cc = classPool.get(classname); } catch (NotFoundException e) { int i = classname.lastIndexOf('.'); if (notCheckInner || i < 0) throw e; StringBuffer sbuf = new StringBuffer(classname); sbuf.setCharAt(i, '$'); classname = sbuf.toString(); } } while (cc == null); return cc; } /* Converts a class name into a JVM-internal representation. * * It may also expand a simple class name to java.lang.*. * For example, this converts Object into java/lang/Object. */ public String resolveClassName(ASTList name) throws CompileError { if (name == null) return null; return javaToJvmName(lookupClassByName(name).getName()); } /* Expands a simple class name to java.lang.*. * For example, this converts Object into java/lang/Object. */ public String resolveJvmClassName(String jvmName) throws CompileError { if (jvmName == null) return null; return javaToJvmName(lookupClassByJvmName(jvmName).getName()); } public static CtClass getSuperclass(CtClass c) throws CompileError { try { CtClass sc = c.getSuperclass(); if (sc != null) return sc; } catch (NotFoundException e) {} throw new CompileError("cannot find the super class of " + c.getName()); } public static CtClass getSuperInterface(CtClass c, String interfaceName) throws CompileError { try { CtClass[] intfs = c.getInterfaces(); for (int i = 0; i < intfs.length; i++) if (intfs[i].getName().equals(interfaceName)) return intfs[i]; } catch (NotFoundException e) {} throw new CompileError("cannot find the super inetrface " + interfaceName + " of " + c.getName()); } public static String javaToJvmName(String classname) { return classname.replace('.', '/'); } public static String jvmToJavaName(String classname) { return classname.replace('/', '.'); } public static int descToType(char c) throws CompileError { switch (c) { case 'Z' : return BOOLEAN; case 'C' : return CHAR; case 'B' : return BYTE; case 'S' : return SHORT; case 'I' : return INT; case 'J' : return LONG; case 'F' : return FLOAT; case 'D' : return DOUBLE; case 'V' : return VOID; case 'L' : case '[' : return CLASS; default : fatal(); return VOID; // never reach here } } public static int getModifiers(ASTList mods) { int m = 0; while (mods != null) { Keyword k = (Keyword)mods.head(); mods = mods.tail(); switch (k.get()) { case STATIC : m |= Modifier.STATIC; break; case FINAL : m |= Modifier.FINAL; break; case SYNCHRONIZED : m |= Modifier.SYNCHRONIZED; break; case ABSTRACT : m |= Modifier.ABSTRACT; break; case PUBLIC : m |= Modifier.PUBLIC; break; case PROTECTED : m |= Modifier.PROTECTED; break; case PRIVATE : m |= Modifier.PRIVATE; break; case VOLATILE : m |= Modifier.VOLATILE; break; case TRANSIENT : m |= Modifier.TRANSIENT; break; case STRICT : m |= Modifier.STRICT; break; } } return m; } }
throw new CompileError("fatal");
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
isStatic
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() {<FILL_FUNCTION_BODY>} }
int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
lookupMethod
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError {<FILL_FUNCTION_BODY>
Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
lookupMethod
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError {<FILL_FUNCTION_BODY>
Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
compareSignature
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError {<FILL_FUNCTION_BODY>
int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
lookupFieldByJvmName2
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException {<FILL_FUNCTION_BODY>
String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); }
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
lookupFieldByJvmName
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError {<FILL_FUNCTION_BODY>
return lookupField(jvmToJavaName(jvmClassName), fieldName);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
lookupField
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError {<FILL_FUNCTION_BODY>
CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get());
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
lookupClassByName
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError {<FILL_FUNCTION_BODY>
return lookupClass(Declarator.astToClassName(name, '.'), false);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
lookupClassByJvmName
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError { return lookupClass(Declarator.astToClassName(name, '.'), false); } public CtClass lookupClassByJvmName(String jvmName) throws CompileError {<FILL_FUNCTION_BODY>
return lookupClass(jvmToJavaName(jvmName), false);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
lookupClass
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError { return lookupClass(Declarator.astToClassName(name, '.'), false); } public CtClass lookupClassByJvmName(String jvmName) throws CompileError { return lookupClass(jvmToJavaName(jvmName), false); } public CtClass lookupClass(Declarator decl) throws CompileError {<FILL_FUNCTION_BODY>
return lookupClass(decl.getType(), decl.getArrayDim(), decl.getClassName());
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
lookupClass
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError { return lookupClass(Declarator.astToClassName(name, '.'), false); } public CtClass lookupClassByJvmName(String jvmName) throws CompileError { return lookupClass(jvmToJavaName(jvmName), false); } public CtClass lookupClass(Declarator decl) throws CompileError { return lookupClass(decl.getType(), decl.getArrayDim(), decl.getClassName()); } /** * @param classname jvm class name. */ public CtClass lookupClass(int type, int dim, String classname) throws CompileError {<FILL_FUNCTION_BODY>
String cname = ""; CtClass clazz; if (type == CLASS) { clazz = lookupClassByJvmName(classname); if (dim > 0) cname = clazz.getName(); else return clazz; } else cname = getTypeName(type); while (dim-- > 0) cname += "[]"; return lookupClass(cname, false);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
getTypeName
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError { return lookupClass(Declarator.astToClassName(name, '.'), false); } public CtClass lookupClassByJvmName(String jvmName) throws CompileError { return lookupClass(jvmToJavaName(jvmName), false); } public CtClass lookupClass(Declarator decl) throws CompileError { return lookupClass(decl.getType(), decl.getArrayDim(), decl.getClassName()); } /** * @param classname jvm class name. */ public CtClass lookupClass(int type, int dim, String classname) throws CompileError { String cname = ""; CtClass clazz; if (type == CLASS) { clazz = lookupClassByJvmName(classname); if (dim > 0) cname = clazz.getName(); else return clazz; } else cname = getTypeName(type); while (dim-- > 0) cname += "[]"; return lookupClass(cname, false); } /* * type cannot be CLASS */ static String getTypeName(int type) throws CompileError {<FILL_FUNCTION_BODY>
String cname = ""; switch (type) { case BOOLEAN : cname = "boolean"; break; case CHAR : cname = "char"; break; case BYTE : cname = "byte"; break; case SHORT : cname = "short"; break; case INT : cname = "int"; break; case LONG : cname = "long"; break; case FLOAT : cname = "float"; break; case DOUBLE : cname = "double"; break; case VOID : cname = "void"; break; default : fatal(); } return cname;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
lookupClass
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError { return lookupClass(Declarator.astToClassName(name, '.'), false); } public CtClass lookupClassByJvmName(String jvmName) throws CompileError { return lookupClass(jvmToJavaName(jvmName), false); } public CtClass lookupClass(Declarator decl) throws CompileError { return lookupClass(decl.getType(), decl.getArrayDim(), decl.getClassName()); } /** * @param classname jvm class name. */ public CtClass lookupClass(int type, int dim, String classname) throws CompileError { String cname = ""; CtClass clazz; if (type == CLASS) { clazz = lookupClassByJvmName(classname); if (dim > 0) cname = clazz.getName(); else return clazz; } else cname = getTypeName(type); while (dim-- > 0) cname += "[]"; return lookupClass(cname, false); } /* * type cannot be CLASS */ static String getTypeName(int type) throws CompileError { String cname = ""; switch (type) { case BOOLEAN : cname = "boolean"; break; case CHAR : cname = "char"; break; case BYTE : cname = "byte"; break; case SHORT : cname = "short"; break; case INT : cname = "int"; break; case LONG : cname = "long"; break; case FLOAT : cname = "float"; break; case DOUBLE : cname = "double"; break; case VOID : cname = "void"; break; default : fatal(); } return cname; } /** * @param name a qualified class name. e.g. java.lang.String */ public CtClass lookupClass(String name, boolean notCheckInner) throws CompileError {<FILL_FUNCTION_BODY>
Map<String,String> cache = getInvalidNames(); String found = cache.get(name); if (found == INVALID) throw new CompileError("no such class: " + name); else if (found != null) try { return classPool.get(found); } catch (NotFoundException e) {} CtClass cc = null; try { cc = lookupClass0(name, notCheckInner); } catch (NotFoundException e) { cc = searchImports(name); } cache.put(name, cc.getName()); return cc;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
getInvalidMapSize
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError { return lookupClass(Declarator.astToClassName(name, '.'), false); } public CtClass lookupClassByJvmName(String jvmName) throws CompileError { return lookupClass(jvmToJavaName(jvmName), false); } public CtClass lookupClass(Declarator decl) throws CompileError { return lookupClass(decl.getType(), decl.getArrayDim(), decl.getClassName()); } /** * @param classname jvm class name. */ public CtClass lookupClass(int type, int dim, String classname) throws CompileError { String cname = ""; CtClass clazz; if (type == CLASS) { clazz = lookupClassByJvmName(classname); if (dim > 0) cname = clazz.getName(); else return clazz; } else cname = getTypeName(type); while (dim-- > 0) cname += "[]"; return lookupClass(cname, false); } /* * type cannot be CLASS */ static String getTypeName(int type) throws CompileError { String cname = ""; switch (type) { case BOOLEAN : cname = "boolean"; break; case CHAR : cname = "char"; break; case BYTE : cname = "byte"; break; case SHORT : cname = "short"; break; case INT : cname = "int"; break; case LONG : cname = "long"; break; case FLOAT : cname = "float"; break; case DOUBLE : cname = "double"; break; case VOID : cname = "void"; break; default : fatal(); } return cname; } /** * @param name a qualified class name. e.g. java.lang.String */ public CtClass lookupClass(String name, boolean notCheckInner) throws CompileError { Map<String,String> cache = getInvalidNames(); String found = cache.get(name); if (found == INVALID) throw new CompileError("no such class: " + name); else if (found != null) try { return classPool.get(found); } catch (NotFoundException e) {} CtClass cc = null; try { cc = lookupClass0(name, notCheckInner); } catch (NotFoundException e) { cc = searchImports(name); } cache.put(name, cc.getName()); return cc; } private static final String INVALID = "<invalid>"; private static Map<ClassPool, Reference<Map<String,String>>> invalidNamesMap = new WeakHashMap<ClassPool, Reference<Map<String,String>>>(); private Map<String,String> invalidNames = null; // for unit tests public static int getInvalidMapSize() {<FILL_FUNCTION_BODY>
return invalidNamesMap.size();
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
getInvalidNames
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError { return lookupClass(Declarator.astToClassName(name, '.'), false); } public CtClass lookupClassByJvmName(String jvmName) throws CompileError { return lookupClass(jvmToJavaName(jvmName), false); } public CtClass lookupClass(Declarator decl) throws CompileError { return lookupClass(decl.getType(), decl.getArrayDim(), decl.getClassName()); } /** * @param classname jvm class name. */ public CtClass lookupClass(int type, int dim, String classname) throws CompileError { String cname = ""; CtClass clazz; if (type == CLASS) { clazz = lookupClassByJvmName(classname); if (dim > 0) cname = clazz.getName(); else return clazz; } else cname = getTypeName(type); while (dim-- > 0) cname += "[]"; return lookupClass(cname, false); } /* * type cannot be CLASS */ static String getTypeName(int type) throws CompileError { String cname = ""; switch (type) { case BOOLEAN : cname = "boolean"; break; case CHAR : cname = "char"; break; case BYTE : cname = "byte"; break; case SHORT : cname = "short"; break; case INT : cname = "int"; break; case LONG : cname = "long"; break; case FLOAT : cname = "float"; break; case DOUBLE : cname = "double"; break; case VOID : cname = "void"; break; default : fatal(); } return cname; } /** * @param name a qualified class name. e.g. java.lang.String */ public CtClass lookupClass(String name, boolean notCheckInner) throws CompileError { Map<String,String> cache = getInvalidNames(); String found = cache.get(name); if (found == INVALID) throw new CompileError("no such class: " + name); else if (found != null) try { return classPool.get(found); } catch (NotFoundException e) {} CtClass cc = null; try { cc = lookupClass0(name, notCheckInner); } catch (NotFoundException e) { cc = searchImports(name); } cache.put(name, cc.getName()); return cc; } private static final String INVALID = "<invalid>"; private static Map<ClassPool, Reference<Map<String,String>>> invalidNamesMap = new WeakHashMap<ClassPool, Reference<Map<String,String>>>(); private Map<String,String> invalidNames = null; // for unit tests public static int getInvalidMapSize() { return invalidNamesMap.size(); } private Map<String,String> getInvalidNames() {<FILL_FUNCTION_BODY>
Map<String,String> ht = invalidNames; if (ht == null) { synchronized (MemberResolver.class) { Reference<Map<String,String>> ref = invalidNamesMap.get(classPool); if (ref != null) ht = ref.get(); if (ht == null) { ht = new Hashtable<String,String>(); invalidNamesMap.put(classPool, new WeakReference<Map<String,String>>(ht)); } } invalidNames = ht; } return ht;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
searchImports
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError { return lookupClass(Declarator.astToClassName(name, '.'), false); } public CtClass lookupClassByJvmName(String jvmName) throws CompileError { return lookupClass(jvmToJavaName(jvmName), false); } public CtClass lookupClass(Declarator decl) throws CompileError { return lookupClass(decl.getType(), decl.getArrayDim(), decl.getClassName()); } /** * @param classname jvm class name. */ public CtClass lookupClass(int type, int dim, String classname) throws CompileError { String cname = ""; CtClass clazz; if (type == CLASS) { clazz = lookupClassByJvmName(classname); if (dim > 0) cname = clazz.getName(); else return clazz; } else cname = getTypeName(type); while (dim-- > 0) cname += "[]"; return lookupClass(cname, false); } /* * type cannot be CLASS */ static String getTypeName(int type) throws CompileError { String cname = ""; switch (type) { case BOOLEAN : cname = "boolean"; break; case CHAR : cname = "char"; break; case BYTE : cname = "byte"; break; case SHORT : cname = "short"; break; case INT : cname = "int"; break; case LONG : cname = "long"; break; case FLOAT : cname = "float"; break; case DOUBLE : cname = "double"; break; case VOID : cname = "void"; break; default : fatal(); } return cname; } /** * @param name a qualified class name. e.g. java.lang.String */ public CtClass lookupClass(String name, boolean notCheckInner) throws CompileError { Map<String,String> cache = getInvalidNames(); String found = cache.get(name); if (found == INVALID) throw new CompileError("no such class: " + name); else if (found != null) try { return classPool.get(found); } catch (NotFoundException e) {} CtClass cc = null; try { cc = lookupClass0(name, notCheckInner); } catch (NotFoundException e) { cc = searchImports(name); } cache.put(name, cc.getName()); return cc; } private static final String INVALID = "<invalid>"; private static Map<ClassPool, Reference<Map<String,String>>> invalidNamesMap = new WeakHashMap<ClassPool, Reference<Map<String,String>>>(); private Map<String,String> invalidNames = null; // for unit tests public static int getInvalidMapSize() { return invalidNamesMap.size(); } private Map<String,String> getInvalidNames() { Map<String,String> ht = invalidNames; if (ht == null) { synchronized (MemberResolver.class) { Reference<Map<String,String>> ref = invalidNamesMap.get(classPool); if (ref != null) ht = ref.get(); if (ht == null) { ht = new Hashtable<String,String>(); invalidNamesMap.put(classPool, new WeakReference<Map<String,String>>(ht)); } } invalidNames = ht; } return ht; } private CtClass searchImports(String orgName) throws CompileError {<FILL_FUNCTION_BODY>
if (orgName.indexOf('.') < 0) { Iterator<String> it = classPool.getImportedPackages(); while (it.hasNext()) { String pac = it.next(); String fqName = pac.replaceAll("\\.$","") + "." + orgName; try { return classPool.get(fqName); } catch (NotFoundException e) { try { if (pac.endsWith("." + orgName)) return classPool.get(pac); } catch (NotFoundException e2) {} } } } getInvalidNames().put(orgName, INVALID); throw new CompileError("no such class: " + orgName);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
lookupClass0
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError { return lookupClass(Declarator.astToClassName(name, '.'), false); } public CtClass lookupClassByJvmName(String jvmName) throws CompileError { return lookupClass(jvmToJavaName(jvmName), false); } public CtClass lookupClass(Declarator decl) throws CompileError { return lookupClass(decl.getType(), decl.getArrayDim(), decl.getClassName()); } /** * @param classname jvm class name. */ public CtClass lookupClass(int type, int dim, String classname) throws CompileError { String cname = ""; CtClass clazz; if (type == CLASS) { clazz = lookupClassByJvmName(classname); if (dim > 0) cname = clazz.getName(); else return clazz; } else cname = getTypeName(type); while (dim-- > 0) cname += "[]"; return lookupClass(cname, false); } /* * type cannot be CLASS */ static String getTypeName(int type) throws CompileError { String cname = ""; switch (type) { case BOOLEAN : cname = "boolean"; break; case CHAR : cname = "char"; break; case BYTE : cname = "byte"; break; case SHORT : cname = "short"; break; case INT : cname = "int"; break; case LONG : cname = "long"; break; case FLOAT : cname = "float"; break; case DOUBLE : cname = "double"; break; case VOID : cname = "void"; break; default : fatal(); } return cname; } /** * @param name a qualified class name. e.g. java.lang.String */ public CtClass lookupClass(String name, boolean notCheckInner) throws CompileError { Map<String,String> cache = getInvalidNames(); String found = cache.get(name); if (found == INVALID) throw new CompileError("no such class: " + name); else if (found != null) try { return classPool.get(found); } catch (NotFoundException e) {} CtClass cc = null; try { cc = lookupClass0(name, notCheckInner); } catch (NotFoundException e) { cc = searchImports(name); } cache.put(name, cc.getName()); return cc; } private static final String INVALID = "<invalid>"; private static Map<ClassPool, Reference<Map<String,String>>> invalidNamesMap = new WeakHashMap<ClassPool, Reference<Map<String,String>>>(); private Map<String,String> invalidNames = null; // for unit tests public static int getInvalidMapSize() { return invalidNamesMap.size(); } private Map<String,String> getInvalidNames() { Map<String,String> ht = invalidNames; if (ht == null) { synchronized (MemberResolver.class) { Reference<Map<String,String>> ref = invalidNamesMap.get(classPool); if (ref != null) ht = ref.get(); if (ht == null) { ht = new Hashtable<String,String>(); invalidNamesMap.put(classPool, new WeakReference<Map<String,String>>(ht)); } } invalidNames = ht; } return ht; } private CtClass searchImports(String orgName) throws CompileError { if (orgName.indexOf('.') < 0) { Iterator<String> it = classPool.getImportedPackages(); while (it.hasNext()) { String pac = it.next(); String fqName = pac.replaceAll("\\.$","") + "." + orgName; try { return classPool.get(fqName); } catch (NotFoundException e) { try { if (pac.endsWith("." + orgName)) return classPool.get(pac); } catch (NotFoundException e2) {} } } } getInvalidNames().put(orgName, INVALID); throw new CompileError("no such class: " + orgName); } private CtClass lookupClass0(String classname, boolean notCheckInner) throws NotFoundException {<FILL_FUNCTION_BODY>
CtClass cc = null; do { try { cc = classPool.get(classname); } catch (NotFoundException e) { int i = classname.lastIndexOf('.'); if (notCheckInner || i < 0) throw e; StringBuffer sbuf = new StringBuffer(classname); sbuf.setCharAt(i, '$'); classname = sbuf.toString(); } } while (cc == null); return cc;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
resolveClassName
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError { return lookupClass(Declarator.astToClassName(name, '.'), false); } public CtClass lookupClassByJvmName(String jvmName) throws CompileError { return lookupClass(jvmToJavaName(jvmName), false); } public CtClass lookupClass(Declarator decl) throws CompileError { return lookupClass(decl.getType(), decl.getArrayDim(), decl.getClassName()); } /** * @param classname jvm class name. */ public CtClass lookupClass(int type, int dim, String classname) throws CompileError { String cname = ""; CtClass clazz; if (type == CLASS) { clazz = lookupClassByJvmName(classname); if (dim > 0) cname = clazz.getName(); else return clazz; } else cname = getTypeName(type); while (dim-- > 0) cname += "[]"; return lookupClass(cname, false); } /* * type cannot be CLASS */ static String getTypeName(int type) throws CompileError { String cname = ""; switch (type) { case BOOLEAN : cname = "boolean"; break; case CHAR : cname = "char"; break; case BYTE : cname = "byte"; break; case SHORT : cname = "short"; break; case INT : cname = "int"; break; case LONG : cname = "long"; break; case FLOAT : cname = "float"; break; case DOUBLE : cname = "double"; break; case VOID : cname = "void"; break; default : fatal(); } return cname; } /** * @param name a qualified class name. e.g. java.lang.String */ public CtClass lookupClass(String name, boolean notCheckInner) throws CompileError { Map<String,String> cache = getInvalidNames(); String found = cache.get(name); if (found == INVALID) throw new CompileError("no such class: " + name); else if (found != null) try { return classPool.get(found); } catch (NotFoundException e) {} CtClass cc = null; try { cc = lookupClass0(name, notCheckInner); } catch (NotFoundException e) { cc = searchImports(name); } cache.put(name, cc.getName()); return cc; } private static final String INVALID = "<invalid>"; private static Map<ClassPool, Reference<Map<String,String>>> invalidNamesMap = new WeakHashMap<ClassPool, Reference<Map<String,String>>>(); private Map<String,String> invalidNames = null; // for unit tests public static int getInvalidMapSize() { return invalidNamesMap.size(); } private Map<String,String> getInvalidNames() { Map<String,String> ht = invalidNames; if (ht == null) { synchronized (MemberResolver.class) { Reference<Map<String,String>> ref = invalidNamesMap.get(classPool); if (ref != null) ht = ref.get(); if (ht == null) { ht = new Hashtable<String,String>(); invalidNamesMap.put(classPool, new WeakReference<Map<String,String>>(ht)); } } invalidNames = ht; } return ht; } private CtClass searchImports(String orgName) throws CompileError { if (orgName.indexOf('.') < 0) { Iterator<String> it = classPool.getImportedPackages(); while (it.hasNext()) { String pac = it.next(); String fqName = pac.replaceAll("\\.$","") + "." + orgName; try { return classPool.get(fqName); } catch (NotFoundException e) { try { if (pac.endsWith("." + orgName)) return classPool.get(pac); } catch (NotFoundException e2) {} } } } getInvalidNames().put(orgName, INVALID); throw new CompileError("no such class: " + orgName); } private CtClass lookupClass0(String classname, boolean notCheckInner) throws NotFoundException { CtClass cc = null; do { try { cc = classPool.get(classname); } catch (NotFoundException e) { int i = classname.lastIndexOf('.'); if (notCheckInner || i < 0) throw e; StringBuffer sbuf = new StringBuffer(classname); sbuf.setCharAt(i, '$'); classname = sbuf.toString(); } } while (cc == null); return cc; } /* Converts a class name into a JVM-internal representation. * * It may also expand a simple class name to java.lang.*. * For example, this converts Object into java/lang/Object. */ public String resolveClassName(ASTList name) throws CompileError {<FILL_FUNCTION_BODY>
if (name == null) return null; return javaToJvmName(lookupClassByName(name).getName());
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
resolveJvmClassName
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError { return lookupClass(Declarator.astToClassName(name, '.'), false); } public CtClass lookupClassByJvmName(String jvmName) throws CompileError { return lookupClass(jvmToJavaName(jvmName), false); } public CtClass lookupClass(Declarator decl) throws CompileError { return lookupClass(decl.getType(), decl.getArrayDim(), decl.getClassName()); } /** * @param classname jvm class name. */ public CtClass lookupClass(int type, int dim, String classname) throws CompileError { String cname = ""; CtClass clazz; if (type == CLASS) { clazz = lookupClassByJvmName(classname); if (dim > 0) cname = clazz.getName(); else return clazz; } else cname = getTypeName(type); while (dim-- > 0) cname += "[]"; return lookupClass(cname, false); } /* * type cannot be CLASS */ static String getTypeName(int type) throws CompileError { String cname = ""; switch (type) { case BOOLEAN : cname = "boolean"; break; case CHAR : cname = "char"; break; case BYTE : cname = "byte"; break; case SHORT : cname = "short"; break; case INT : cname = "int"; break; case LONG : cname = "long"; break; case FLOAT : cname = "float"; break; case DOUBLE : cname = "double"; break; case VOID : cname = "void"; break; default : fatal(); } return cname; } /** * @param name a qualified class name. e.g. java.lang.String */ public CtClass lookupClass(String name, boolean notCheckInner) throws CompileError { Map<String,String> cache = getInvalidNames(); String found = cache.get(name); if (found == INVALID) throw new CompileError("no such class: " + name); else if (found != null) try { return classPool.get(found); } catch (NotFoundException e) {} CtClass cc = null; try { cc = lookupClass0(name, notCheckInner); } catch (NotFoundException e) { cc = searchImports(name); } cache.put(name, cc.getName()); return cc; } private static final String INVALID = "<invalid>"; private static Map<ClassPool, Reference<Map<String,String>>> invalidNamesMap = new WeakHashMap<ClassPool, Reference<Map<String,String>>>(); private Map<String,String> invalidNames = null; // for unit tests public static int getInvalidMapSize() { return invalidNamesMap.size(); } private Map<String,String> getInvalidNames() { Map<String,String> ht = invalidNames; if (ht == null) { synchronized (MemberResolver.class) { Reference<Map<String,String>> ref = invalidNamesMap.get(classPool); if (ref != null) ht = ref.get(); if (ht == null) { ht = new Hashtable<String,String>(); invalidNamesMap.put(classPool, new WeakReference<Map<String,String>>(ht)); } } invalidNames = ht; } return ht; } private CtClass searchImports(String orgName) throws CompileError { if (orgName.indexOf('.') < 0) { Iterator<String> it = classPool.getImportedPackages(); while (it.hasNext()) { String pac = it.next(); String fqName = pac.replaceAll("\\.$","") + "." + orgName; try { return classPool.get(fqName); } catch (NotFoundException e) { try { if (pac.endsWith("." + orgName)) return classPool.get(pac); } catch (NotFoundException e2) {} } } } getInvalidNames().put(orgName, INVALID); throw new CompileError("no such class: " + orgName); } private CtClass lookupClass0(String classname, boolean notCheckInner) throws NotFoundException { CtClass cc = null; do { try { cc = classPool.get(classname); } catch (NotFoundException e) { int i = classname.lastIndexOf('.'); if (notCheckInner || i < 0) throw e; StringBuffer sbuf = new StringBuffer(classname); sbuf.setCharAt(i, '$'); classname = sbuf.toString(); } } while (cc == null); return cc; } /* Converts a class name into a JVM-internal representation. * * It may also expand a simple class name to java.lang.*. * For example, this converts Object into java/lang/Object. */ public String resolveClassName(ASTList name) throws CompileError { if (name == null) return null; return javaToJvmName(lookupClassByName(name).getName()); } /* Expands a simple class name to java.lang.*. * For example, this converts Object into java/lang/Object. */ public String resolveJvmClassName(String jvmName) throws CompileError {<FILL_FUNCTION_BODY>
if (jvmName == null) return null; return javaToJvmName(lookupClassByJvmName(jvmName).getName());
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
getSuperclass
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError { return lookupClass(Declarator.astToClassName(name, '.'), false); } public CtClass lookupClassByJvmName(String jvmName) throws CompileError { return lookupClass(jvmToJavaName(jvmName), false); } public CtClass lookupClass(Declarator decl) throws CompileError { return lookupClass(decl.getType(), decl.getArrayDim(), decl.getClassName()); } /** * @param classname jvm class name. */ public CtClass lookupClass(int type, int dim, String classname) throws CompileError { String cname = ""; CtClass clazz; if (type == CLASS) { clazz = lookupClassByJvmName(classname); if (dim > 0) cname = clazz.getName(); else return clazz; } else cname = getTypeName(type); while (dim-- > 0) cname += "[]"; return lookupClass(cname, false); } /* * type cannot be CLASS */ static String getTypeName(int type) throws CompileError { String cname = ""; switch (type) { case BOOLEAN : cname = "boolean"; break; case CHAR : cname = "char"; break; case BYTE : cname = "byte"; break; case SHORT : cname = "short"; break; case INT : cname = "int"; break; case LONG : cname = "long"; break; case FLOAT : cname = "float"; break; case DOUBLE : cname = "double"; break; case VOID : cname = "void"; break; default : fatal(); } return cname; } /** * @param name a qualified class name. e.g. java.lang.String */ public CtClass lookupClass(String name, boolean notCheckInner) throws CompileError { Map<String,String> cache = getInvalidNames(); String found = cache.get(name); if (found == INVALID) throw new CompileError("no such class: " + name); else if (found != null) try { return classPool.get(found); } catch (NotFoundException e) {} CtClass cc = null; try { cc = lookupClass0(name, notCheckInner); } catch (NotFoundException e) { cc = searchImports(name); } cache.put(name, cc.getName()); return cc; } private static final String INVALID = "<invalid>"; private static Map<ClassPool, Reference<Map<String,String>>> invalidNamesMap = new WeakHashMap<ClassPool, Reference<Map<String,String>>>(); private Map<String,String> invalidNames = null; // for unit tests public static int getInvalidMapSize() { return invalidNamesMap.size(); } private Map<String,String> getInvalidNames() { Map<String,String> ht = invalidNames; if (ht == null) { synchronized (MemberResolver.class) { Reference<Map<String,String>> ref = invalidNamesMap.get(classPool); if (ref != null) ht = ref.get(); if (ht == null) { ht = new Hashtable<String,String>(); invalidNamesMap.put(classPool, new WeakReference<Map<String,String>>(ht)); } } invalidNames = ht; } return ht; } private CtClass searchImports(String orgName) throws CompileError { if (orgName.indexOf('.') < 0) { Iterator<String> it = classPool.getImportedPackages(); while (it.hasNext()) { String pac = it.next(); String fqName = pac.replaceAll("\\.$","") + "." + orgName; try { return classPool.get(fqName); } catch (NotFoundException e) { try { if (pac.endsWith("." + orgName)) return classPool.get(pac); } catch (NotFoundException e2) {} } } } getInvalidNames().put(orgName, INVALID); throw new CompileError("no such class: " + orgName); } private CtClass lookupClass0(String classname, boolean notCheckInner) throws NotFoundException { CtClass cc = null; do { try { cc = classPool.get(classname); } catch (NotFoundException e) { int i = classname.lastIndexOf('.'); if (notCheckInner || i < 0) throw e; StringBuffer sbuf = new StringBuffer(classname); sbuf.setCharAt(i, '$'); classname = sbuf.toString(); } } while (cc == null); return cc; } /* Converts a class name into a JVM-internal representation. * * It may also expand a simple class name to java.lang.*. * For example, this converts Object into java/lang/Object. */ public String resolveClassName(ASTList name) throws CompileError { if (name == null) return null; return javaToJvmName(lookupClassByName(name).getName()); } /* Expands a simple class name to java.lang.*. * For example, this converts Object into java/lang/Object. */ public String resolveJvmClassName(String jvmName) throws CompileError { if (jvmName == null) return null; return javaToJvmName(lookupClassByJvmName(jvmName).getName()); } public static CtClass getSuperclass(CtClass c) throws CompileError {<FILL_FUNCTION_BODY>
try { CtClass sc = c.getSuperclass(); if (sc != null) return sc; } catch (NotFoundException e) {} throw new CompileError("cannot find the super class of " + c.getName());
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
getSuperInterface
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError { return lookupClass(Declarator.astToClassName(name, '.'), false); } public CtClass lookupClassByJvmName(String jvmName) throws CompileError { return lookupClass(jvmToJavaName(jvmName), false); } public CtClass lookupClass(Declarator decl) throws CompileError { return lookupClass(decl.getType(), decl.getArrayDim(), decl.getClassName()); } /** * @param classname jvm class name. */ public CtClass lookupClass(int type, int dim, String classname) throws CompileError { String cname = ""; CtClass clazz; if (type == CLASS) { clazz = lookupClassByJvmName(classname); if (dim > 0) cname = clazz.getName(); else return clazz; } else cname = getTypeName(type); while (dim-- > 0) cname += "[]"; return lookupClass(cname, false); } /* * type cannot be CLASS */ static String getTypeName(int type) throws CompileError { String cname = ""; switch (type) { case BOOLEAN : cname = "boolean"; break; case CHAR : cname = "char"; break; case BYTE : cname = "byte"; break; case SHORT : cname = "short"; break; case INT : cname = "int"; break; case LONG : cname = "long"; break; case FLOAT : cname = "float"; break; case DOUBLE : cname = "double"; break; case VOID : cname = "void"; break; default : fatal(); } return cname; } /** * @param name a qualified class name. e.g. java.lang.String */ public CtClass lookupClass(String name, boolean notCheckInner) throws CompileError { Map<String,String> cache = getInvalidNames(); String found = cache.get(name); if (found == INVALID) throw new CompileError("no such class: " + name); else if (found != null) try { return classPool.get(found); } catch (NotFoundException e) {} CtClass cc = null; try { cc = lookupClass0(name, notCheckInner); } catch (NotFoundException e) { cc = searchImports(name); } cache.put(name, cc.getName()); return cc; } private static final String INVALID = "<invalid>"; private static Map<ClassPool, Reference<Map<String,String>>> invalidNamesMap = new WeakHashMap<ClassPool, Reference<Map<String,String>>>(); private Map<String,String> invalidNames = null; // for unit tests public static int getInvalidMapSize() { return invalidNamesMap.size(); } private Map<String,String> getInvalidNames() { Map<String,String> ht = invalidNames; if (ht == null) { synchronized (MemberResolver.class) { Reference<Map<String,String>> ref = invalidNamesMap.get(classPool); if (ref != null) ht = ref.get(); if (ht == null) { ht = new Hashtable<String,String>(); invalidNamesMap.put(classPool, new WeakReference<Map<String,String>>(ht)); } } invalidNames = ht; } return ht; } private CtClass searchImports(String orgName) throws CompileError { if (orgName.indexOf('.') < 0) { Iterator<String> it = classPool.getImportedPackages(); while (it.hasNext()) { String pac = it.next(); String fqName = pac.replaceAll("\\.$","") + "." + orgName; try { return classPool.get(fqName); } catch (NotFoundException e) { try { if (pac.endsWith("." + orgName)) return classPool.get(pac); } catch (NotFoundException e2) {} } } } getInvalidNames().put(orgName, INVALID); throw new CompileError("no such class: " + orgName); } private CtClass lookupClass0(String classname, boolean notCheckInner) throws NotFoundException { CtClass cc = null; do { try { cc = classPool.get(classname); } catch (NotFoundException e) { int i = classname.lastIndexOf('.'); if (notCheckInner || i < 0) throw e; StringBuffer sbuf = new StringBuffer(classname); sbuf.setCharAt(i, '$'); classname = sbuf.toString(); } } while (cc == null); return cc; } /* Converts a class name into a JVM-internal representation. * * It may also expand a simple class name to java.lang.*. * For example, this converts Object into java/lang/Object. */ public String resolveClassName(ASTList name) throws CompileError { if (name == null) return null; return javaToJvmName(lookupClassByName(name).getName()); } /* Expands a simple class name to java.lang.*. * For example, this converts Object into java/lang/Object. */ public String resolveJvmClassName(String jvmName) throws CompileError { if (jvmName == null) return null; return javaToJvmName(lookupClassByJvmName(jvmName).getName()); } public static CtClass getSuperclass(CtClass c) throws CompileError { try { CtClass sc = c.getSuperclass(); if (sc != null) return sc; } catch (NotFoundException e) {} throw new CompileError("cannot find the super class of " + c.getName()); } public static CtClass getSuperInterface(CtClass c, String interfaceName) throws CompileError {<FILL_FUNCTION_BODY>
try { CtClass[] intfs = c.getInterfaces(); for (int i = 0; i < intfs.length; i++) if (intfs[i].getName().equals(interfaceName)) return intfs[i]; } catch (NotFoundException e) {} throw new CompileError("cannot find the super inetrface " + interfaceName + " of " + c.getName());
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
javaToJvmName
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError { return lookupClass(Declarator.astToClassName(name, '.'), false); } public CtClass lookupClassByJvmName(String jvmName) throws CompileError { return lookupClass(jvmToJavaName(jvmName), false); } public CtClass lookupClass(Declarator decl) throws CompileError { return lookupClass(decl.getType(), decl.getArrayDim(), decl.getClassName()); } /** * @param classname jvm class name. */ public CtClass lookupClass(int type, int dim, String classname) throws CompileError { String cname = ""; CtClass clazz; if (type == CLASS) { clazz = lookupClassByJvmName(classname); if (dim > 0) cname = clazz.getName(); else return clazz; } else cname = getTypeName(type); while (dim-- > 0) cname += "[]"; return lookupClass(cname, false); } /* * type cannot be CLASS */ static String getTypeName(int type) throws CompileError { String cname = ""; switch (type) { case BOOLEAN : cname = "boolean"; break; case CHAR : cname = "char"; break; case BYTE : cname = "byte"; break; case SHORT : cname = "short"; break; case INT : cname = "int"; break; case LONG : cname = "long"; break; case FLOAT : cname = "float"; break; case DOUBLE : cname = "double"; break; case VOID : cname = "void"; break; default : fatal(); } return cname; } /** * @param name a qualified class name. e.g. java.lang.String */ public CtClass lookupClass(String name, boolean notCheckInner) throws CompileError { Map<String,String> cache = getInvalidNames(); String found = cache.get(name); if (found == INVALID) throw new CompileError("no such class: " + name); else if (found != null) try { return classPool.get(found); } catch (NotFoundException e) {} CtClass cc = null; try { cc = lookupClass0(name, notCheckInner); } catch (NotFoundException e) { cc = searchImports(name); } cache.put(name, cc.getName()); return cc; } private static final String INVALID = "<invalid>"; private static Map<ClassPool, Reference<Map<String,String>>> invalidNamesMap = new WeakHashMap<ClassPool, Reference<Map<String,String>>>(); private Map<String,String> invalidNames = null; // for unit tests public static int getInvalidMapSize() { return invalidNamesMap.size(); } private Map<String,String> getInvalidNames() { Map<String,String> ht = invalidNames; if (ht == null) { synchronized (MemberResolver.class) { Reference<Map<String,String>> ref = invalidNamesMap.get(classPool); if (ref != null) ht = ref.get(); if (ht == null) { ht = new Hashtable<String,String>(); invalidNamesMap.put(classPool, new WeakReference<Map<String,String>>(ht)); } } invalidNames = ht; } return ht; } private CtClass searchImports(String orgName) throws CompileError { if (orgName.indexOf('.') < 0) { Iterator<String> it = classPool.getImportedPackages(); while (it.hasNext()) { String pac = it.next(); String fqName = pac.replaceAll("\\.$","") + "." + orgName; try { return classPool.get(fqName); } catch (NotFoundException e) { try { if (pac.endsWith("." + orgName)) return classPool.get(pac); } catch (NotFoundException e2) {} } } } getInvalidNames().put(orgName, INVALID); throw new CompileError("no such class: " + orgName); } private CtClass lookupClass0(String classname, boolean notCheckInner) throws NotFoundException { CtClass cc = null; do { try { cc = classPool.get(classname); } catch (NotFoundException e) { int i = classname.lastIndexOf('.'); if (notCheckInner || i < 0) throw e; StringBuffer sbuf = new StringBuffer(classname); sbuf.setCharAt(i, '$'); classname = sbuf.toString(); } } while (cc == null); return cc; } /* Converts a class name into a JVM-internal representation. * * It may also expand a simple class name to java.lang.*. * For example, this converts Object into java/lang/Object. */ public String resolveClassName(ASTList name) throws CompileError { if (name == null) return null; return javaToJvmName(lookupClassByName(name).getName()); } /* Expands a simple class name to java.lang.*. * For example, this converts Object into java/lang/Object. */ public String resolveJvmClassName(String jvmName) throws CompileError { if (jvmName == null) return null; return javaToJvmName(lookupClassByJvmName(jvmName).getName()); } public static CtClass getSuperclass(CtClass c) throws CompileError { try { CtClass sc = c.getSuperclass(); if (sc != null) return sc; } catch (NotFoundException e) {} throw new CompileError("cannot find the super class of " + c.getName()); } public static CtClass getSuperInterface(CtClass c, String interfaceName) throws CompileError { try { CtClass[] intfs = c.getInterfaces(); for (int i = 0; i < intfs.length; i++) if (intfs[i].getName().equals(interfaceName)) return intfs[i]; } catch (NotFoundException e) {} throw new CompileError("cannot find the super inetrface " + interfaceName + " of " + c.getName()); } public static String javaToJvmName(String classname) {<FILL_FUNCTION_BODY>
return classname.replace('.', '/');
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
jvmToJavaName
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError { return lookupClass(Declarator.astToClassName(name, '.'), false); } public CtClass lookupClassByJvmName(String jvmName) throws CompileError { return lookupClass(jvmToJavaName(jvmName), false); } public CtClass lookupClass(Declarator decl) throws CompileError { return lookupClass(decl.getType(), decl.getArrayDim(), decl.getClassName()); } /** * @param classname jvm class name. */ public CtClass lookupClass(int type, int dim, String classname) throws CompileError { String cname = ""; CtClass clazz; if (type == CLASS) { clazz = lookupClassByJvmName(classname); if (dim > 0) cname = clazz.getName(); else return clazz; } else cname = getTypeName(type); while (dim-- > 0) cname += "[]"; return lookupClass(cname, false); } /* * type cannot be CLASS */ static String getTypeName(int type) throws CompileError { String cname = ""; switch (type) { case BOOLEAN : cname = "boolean"; break; case CHAR : cname = "char"; break; case BYTE : cname = "byte"; break; case SHORT : cname = "short"; break; case INT : cname = "int"; break; case LONG : cname = "long"; break; case FLOAT : cname = "float"; break; case DOUBLE : cname = "double"; break; case VOID : cname = "void"; break; default : fatal(); } return cname; } /** * @param name a qualified class name. e.g. java.lang.String */ public CtClass lookupClass(String name, boolean notCheckInner) throws CompileError { Map<String,String> cache = getInvalidNames(); String found = cache.get(name); if (found == INVALID) throw new CompileError("no such class: " + name); else if (found != null) try { return classPool.get(found); } catch (NotFoundException e) {} CtClass cc = null; try { cc = lookupClass0(name, notCheckInner); } catch (NotFoundException e) { cc = searchImports(name); } cache.put(name, cc.getName()); return cc; } private static final String INVALID = "<invalid>"; private static Map<ClassPool, Reference<Map<String,String>>> invalidNamesMap = new WeakHashMap<ClassPool, Reference<Map<String,String>>>(); private Map<String,String> invalidNames = null; // for unit tests public static int getInvalidMapSize() { return invalidNamesMap.size(); } private Map<String,String> getInvalidNames() { Map<String,String> ht = invalidNames; if (ht == null) { synchronized (MemberResolver.class) { Reference<Map<String,String>> ref = invalidNamesMap.get(classPool); if (ref != null) ht = ref.get(); if (ht == null) { ht = new Hashtable<String,String>(); invalidNamesMap.put(classPool, new WeakReference<Map<String,String>>(ht)); } } invalidNames = ht; } return ht; } private CtClass searchImports(String orgName) throws CompileError { if (orgName.indexOf('.') < 0) { Iterator<String> it = classPool.getImportedPackages(); while (it.hasNext()) { String pac = it.next(); String fqName = pac.replaceAll("\\.$","") + "." + orgName; try { return classPool.get(fqName); } catch (NotFoundException e) { try { if (pac.endsWith("." + orgName)) return classPool.get(pac); } catch (NotFoundException e2) {} } } } getInvalidNames().put(orgName, INVALID); throw new CompileError("no such class: " + orgName); } private CtClass lookupClass0(String classname, boolean notCheckInner) throws NotFoundException { CtClass cc = null; do { try { cc = classPool.get(classname); } catch (NotFoundException e) { int i = classname.lastIndexOf('.'); if (notCheckInner || i < 0) throw e; StringBuffer sbuf = new StringBuffer(classname); sbuf.setCharAt(i, '$'); classname = sbuf.toString(); } } while (cc == null); return cc; } /* Converts a class name into a JVM-internal representation. * * It may also expand a simple class name to java.lang.*. * For example, this converts Object into java/lang/Object. */ public String resolveClassName(ASTList name) throws CompileError { if (name == null) return null; return javaToJvmName(lookupClassByName(name).getName()); } /* Expands a simple class name to java.lang.*. * For example, this converts Object into java/lang/Object. */ public String resolveJvmClassName(String jvmName) throws CompileError { if (jvmName == null) return null; return javaToJvmName(lookupClassByJvmName(jvmName).getName()); } public static CtClass getSuperclass(CtClass c) throws CompileError { try { CtClass sc = c.getSuperclass(); if (sc != null) return sc; } catch (NotFoundException e) {} throw new CompileError("cannot find the super class of " + c.getName()); } public static CtClass getSuperInterface(CtClass c, String interfaceName) throws CompileError { try { CtClass[] intfs = c.getInterfaces(); for (int i = 0; i < intfs.length; i++) if (intfs[i].getName().equals(interfaceName)) return intfs[i]; } catch (NotFoundException e) {} throw new CompileError("cannot find the super inetrface " + interfaceName + " of " + c.getName()); } public static String javaToJvmName(String classname) { return classname.replace('.', '/'); } public static String jvmToJavaName(String classname) {<FILL_FUNCTION_BODY>
return classname.replace('/', '.');
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
descToType
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError { return lookupClass(Declarator.astToClassName(name, '.'), false); } public CtClass lookupClassByJvmName(String jvmName) throws CompileError { return lookupClass(jvmToJavaName(jvmName), false); } public CtClass lookupClass(Declarator decl) throws CompileError { return lookupClass(decl.getType(), decl.getArrayDim(), decl.getClassName()); } /** * @param classname jvm class name. */ public CtClass lookupClass(int type, int dim, String classname) throws CompileError { String cname = ""; CtClass clazz; if (type == CLASS) { clazz = lookupClassByJvmName(classname); if (dim > 0) cname = clazz.getName(); else return clazz; } else cname = getTypeName(type); while (dim-- > 0) cname += "[]"; return lookupClass(cname, false); } /* * type cannot be CLASS */ static String getTypeName(int type) throws CompileError { String cname = ""; switch (type) { case BOOLEAN : cname = "boolean"; break; case CHAR : cname = "char"; break; case BYTE : cname = "byte"; break; case SHORT : cname = "short"; break; case INT : cname = "int"; break; case LONG : cname = "long"; break; case FLOAT : cname = "float"; break; case DOUBLE : cname = "double"; break; case VOID : cname = "void"; break; default : fatal(); } return cname; } /** * @param name a qualified class name. e.g. java.lang.String */ public CtClass lookupClass(String name, boolean notCheckInner) throws CompileError { Map<String,String> cache = getInvalidNames(); String found = cache.get(name); if (found == INVALID) throw new CompileError("no such class: " + name); else if (found != null) try { return classPool.get(found); } catch (NotFoundException e) {} CtClass cc = null; try { cc = lookupClass0(name, notCheckInner); } catch (NotFoundException e) { cc = searchImports(name); } cache.put(name, cc.getName()); return cc; } private static final String INVALID = "<invalid>"; private static Map<ClassPool, Reference<Map<String,String>>> invalidNamesMap = new WeakHashMap<ClassPool, Reference<Map<String,String>>>(); private Map<String,String> invalidNames = null; // for unit tests public static int getInvalidMapSize() { return invalidNamesMap.size(); } private Map<String,String> getInvalidNames() { Map<String,String> ht = invalidNames; if (ht == null) { synchronized (MemberResolver.class) { Reference<Map<String,String>> ref = invalidNamesMap.get(classPool); if (ref != null) ht = ref.get(); if (ht == null) { ht = new Hashtable<String,String>(); invalidNamesMap.put(classPool, new WeakReference<Map<String,String>>(ht)); } } invalidNames = ht; } return ht; } private CtClass searchImports(String orgName) throws CompileError { if (orgName.indexOf('.') < 0) { Iterator<String> it = classPool.getImportedPackages(); while (it.hasNext()) { String pac = it.next(); String fqName = pac.replaceAll("\\.$","") + "." + orgName; try { return classPool.get(fqName); } catch (NotFoundException e) { try { if (pac.endsWith("." + orgName)) return classPool.get(pac); } catch (NotFoundException e2) {} } } } getInvalidNames().put(orgName, INVALID); throw new CompileError("no such class: " + orgName); } private CtClass lookupClass0(String classname, boolean notCheckInner) throws NotFoundException { CtClass cc = null; do { try { cc = classPool.get(classname); } catch (NotFoundException e) { int i = classname.lastIndexOf('.'); if (notCheckInner || i < 0) throw e; StringBuffer sbuf = new StringBuffer(classname); sbuf.setCharAt(i, '$'); classname = sbuf.toString(); } } while (cc == null); return cc; } /* Converts a class name into a JVM-internal representation. * * It may also expand a simple class name to java.lang.*. * For example, this converts Object into java/lang/Object. */ public String resolveClassName(ASTList name) throws CompileError { if (name == null) return null; return javaToJvmName(lookupClassByName(name).getName()); } /* Expands a simple class name to java.lang.*. * For example, this converts Object into java/lang/Object. */ public String resolveJvmClassName(String jvmName) throws CompileError { if (jvmName == null) return null; return javaToJvmName(lookupClassByJvmName(jvmName).getName()); } public static CtClass getSuperclass(CtClass c) throws CompileError { try { CtClass sc = c.getSuperclass(); if (sc != null) return sc; } catch (NotFoundException e) {} throw new CompileError("cannot find the super class of " + c.getName()); } public static CtClass getSuperInterface(CtClass c, String interfaceName) throws CompileError { try { CtClass[] intfs = c.getInterfaces(); for (int i = 0; i < intfs.length; i++) if (intfs[i].getName().equals(interfaceName)) return intfs[i]; } catch (NotFoundException e) {} throw new CompileError("cannot find the super inetrface " + interfaceName + " of " + c.getName()); } public static String javaToJvmName(String classname) { return classname.replace('.', '/'); } public static String jvmToJavaName(String classname) { return classname.replace('/', '.'); } public static int descToType(char c) throws CompileError {<FILL_FUNCTION_BODY>
switch (c) { case 'Z' : return BOOLEAN; case 'C' : return CHAR; case 'B' : return BYTE; case 'S' : return SHORT; case 'I' : return INT; case 'J' : return LONG; case 'F' : return FLOAT; case 'D' : return DOUBLE; case 'V' : return VOID; case 'L' : case '[' : return CLASS; default : fatal(); return VOID; // never reach here }
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/MemberResolver.java
Method
getModifiers
class Method { public CtClass declaring; public MethodInfo info; public int notmatch; public Method(CtClass c, MethodInfo i, int n) { declaring = c; info = i; notmatch = n; } /** * Returns true if the invoked method is static. */ public boolean isStatic() { int acc = info.getAccessFlags(); return (acc & AccessFlag.STATIC) != 0; } } public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current, String methodName, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { Method maybe = null; // to enable the creation of a recursively called method if (current != null && clazz == currentClass) if (current.getName().equals(methodName)) { int res = compareSignature(current.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, current, res); if (res == YES) return r; maybe = r; } } Method m = lookupMethod(clazz, methodName, argTypes, argDims, argClassNames, maybe != null); if (m != null) return m; return maybe; } private Method lookupMethod(CtClass clazz, String methodName, int[] argTypes, int[] argDims, String[] argClassNames, boolean onlyExact) throws CompileError { Method maybe = null; ClassFile cf = clazz.getClassFile2(); // If the class is an array type, the class file is null. // If so, search the super class java.lang.Object for clone() etc. if (cf != null) { List<MethodInfo> list = cf.getMethods(); for (MethodInfo minfo:list) { if (minfo.getName().equals(methodName) && (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) { int res = compareSignature(minfo.getDescriptor(), argTypes, argDims, argClassNames); if (res != NO) { Method r = new Method(clazz, minfo, res); if (res == YES) return r; else if (maybe == null || maybe.notmatch > res) maybe = r; } } } } if (onlyExact) maybe = null; else if (maybe != null) return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try { // skip searching java.lang.Object if clazz is an interface type. if (!isIntf) { CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} try { CtClass[] ifs = clazz.getInterfaces(); for (CtClass intf:ifs) { Method r = lookupMethod(intf, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } if (isIntf) { // finally search java.lang.Object. CtClass pclazz = clazz.getSuperclass(); if (pclazz != null) { Method r = lookupMethod(pclazz, methodName, argTypes, argDims, argClassNames, onlyExact); if (r != null) return r; } } } catch (NotFoundException e) {} return maybe; } private static final int YES = 0; private static final int NO = -1; /* * Returns YES if actual parameter types matches the given signature. * * argTypes, argDims, and argClassNames represent actual parameters. * * This method does not correctly implement the Java method dispatch * algorithm. * * If some of the parameter types exactly match but others are subtypes of * the corresponding type in the signature, this method returns the number * of parameter types that do not exactly match. */ private int compareSignature(String desc, int[] argTypes, int[] argDims, String[] argClassNames) throws CompileError { int result = YES; int i = 1; int nArgs = argTypes.length; if (nArgs != Descriptor.numOfParameters(desc)) return NO; int len = desc.length(); for (int n = 0; i < len; ++n) { char c = desc.charAt(i++); if (c == ')') return (n == nArgs ? result : NO); else if (n >= nArgs) return NO; int dim = 0; while (c == '[') { ++dim; c = desc.charAt(i++); } if (argTypes[n] == NULL) { if (dim == 0 && c != 'L') return NO; if (c == 'L') i = desc.indexOf(';', i) + 1; } else if (argDims[n] != dim) { if (!(dim == 0 && c == 'L' && desc.startsWith("java/lang/Object;", i))) return NO; // if the thread reaches here, c must be 'L'. i = desc.indexOf(';', i) + 1; result++; if (i <= 0) return NO; // invalid descriptor? } else if (c == 'L') { // not compare int j = desc.indexOf(';', i); if (j < 0 || argTypes[n] != CLASS) return NO; String cname = desc.substring(i, j); if (!cname.equals(argClassNames[n])) { CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else return NO; } catch (NotFoundException e) { result++; // should be NO? } } i = j + 1; } else { int t = descToType(c); int at = argTypes[n]; if (t != at) if (t == INT && (at == SHORT || at == BYTE || at == CHAR)) result++; else return NO; } } return NO; } /** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } } /** * @param jvmClassName a JVM class name. e.g. java/lang/String */ public CtField lookupFieldByJvmName(String jvmClassName, Symbol fieldName) throws CompileError { return lookupField(jvmToJavaName(jvmClassName), fieldName); } /** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); } public CtClass lookupClassByName(ASTList name) throws CompileError { return lookupClass(Declarator.astToClassName(name, '.'), false); } public CtClass lookupClassByJvmName(String jvmName) throws CompileError { return lookupClass(jvmToJavaName(jvmName), false); } public CtClass lookupClass(Declarator decl) throws CompileError { return lookupClass(decl.getType(), decl.getArrayDim(), decl.getClassName()); } /** * @param classname jvm class name. */ public CtClass lookupClass(int type, int dim, String classname) throws CompileError { String cname = ""; CtClass clazz; if (type == CLASS) { clazz = lookupClassByJvmName(classname); if (dim > 0) cname = clazz.getName(); else return clazz; } else cname = getTypeName(type); while (dim-- > 0) cname += "[]"; return lookupClass(cname, false); } /* * type cannot be CLASS */ static String getTypeName(int type) throws CompileError { String cname = ""; switch (type) { case BOOLEAN : cname = "boolean"; break; case CHAR : cname = "char"; break; case BYTE : cname = "byte"; break; case SHORT : cname = "short"; break; case INT : cname = "int"; break; case LONG : cname = "long"; break; case FLOAT : cname = "float"; break; case DOUBLE : cname = "double"; break; case VOID : cname = "void"; break; default : fatal(); } return cname; } /** * @param name a qualified class name. e.g. java.lang.String */ public CtClass lookupClass(String name, boolean notCheckInner) throws CompileError { Map<String,String> cache = getInvalidNames(); String found = cache.get(name); if (found == INVALID) throw new CompileError("no such class: " + name); else if (found != null) try { return classPool.get(found); } catch (NotFoundException e) {} CtClass cc = null; try { cc = lookupClass0(name, notCheckInner); } catch (NotFoundException e) { cc = searchImports(name); } cache.put(name, cc.getName()); return cc; } private static final String INVALID = "<invalid>"; private static Map<ClassPool, Reference<Map<String,String>>> invalidNamesMap = new WeakHashMap<ClassPool, Reference<Map<String,String>>>(); private Map<String,String> invalidNames = null; // for unit tests public static int getInvalidMapSize() { return invalidNamesMap.size(); } private Map<String,String> getInvalidNames() { Map<String,String> ht = invalidNames; if (ht == null) { synchronized (MemberResolver.class) { Reference<Map<String,String>> ref = invalidNamesMap.get(classPool); if (ref != null) ht = ref.get(); if (ht == null) { ht = new Hashtable<String,String>(); invalidNamesMap.put(classPool, new WeakReference<Map<String,String>>(ht)); } } invalidNames = ht; } return ht; } private CtClass searchImports(String orgName) throws CompileError { if (orgName.indexOf('.') < 0) { Iterator<String> it = classPool.getImportedPackages(); while (it.hasNext()) { String pac = it.next(); String fqName = pac.replaceAll("\\.$","") + "." + orgName; try { return classPool.get(fqName); } catch (NotFoundException e) { try { if (pac.endsWith("." + orgName)) return classPool.get(pac); } catch (NotFoundException e2) {} } } } getInvalidNames().put(orgName, INVALID); throw new CompileError("no such class: " + orgName); } private CtClass lookupClass0(String classname, boolean notCheckInner) throws NotFoundException { CtClass cc = null; do { try { cc = classPool.get(classname); } catch (NotFoundException e) { int i = classname.lastIndexOf('.'); if (notCheckInner || i < 0) throw e; StringBuffer sbuf = new StringBuffer(classname); sbuf.setCharAt(i, '$'); classname = sbuf.toString(); } } while (cc == null); return cc; } /* Converts a class name into a JVM-internal representation. * * It may also expand a simple class name to java.lang.*. * For example, this converts Object into java/lang/Object. */ public String resolveClassName(ASTList name) throws CompileError { if (name == null) return null; return javaToJvmName(lookupClassByName(name).getName()); } /* Expands a simple class name to java.lang.*. * For example, this converts Object into java/lang/Object. */ public String resolveJvmClassName(String jvmName) throws CompileError { if (jvmName == null) return null; return javaToJvmName(lookupClassByJvmName(jvmName).getName()); } public static CtClass getSuperclass(CtClass c) throws CompileError { try { CtClass sc = c.getSuperclass(); if (sc != null) return sc; } catch (NotFoundException e) {} throw new CompileError("cannot find the super class of " + c.getName()); } public static CtClass getSuperInterface(CtClass c, String interfaceName) throws CompileError { try { CtClass[] intfs = c.getInterfaces(); for (int i = 0; i < intfs.length; i++) if (intfs[i].getName().equals(interfaceName)) return intfs[i]; } catch (NotFoundException e) {} throw new CompileError("cannot find the super inetrface " + interfaceName + " of " + c.getName()); } public static String javaToJvmName(String classname) { return classname.replace('.', '/'); } public static String jvmToJavaName(String classname) { return classname.replace('/', '.'); } public static int descToType(char c) throws CompileError { switch (c) { case 'Z' : return BOOLEAN; case 'C' : return CHAR; case 'B' : return BYTE; case 'S' : return SHORT; case 'I' : return INT; case 'J' : return LONG; case 'F' : return FLOAT; case 'D' : return DOUBLE; case 'V' : return VOID; case 'L' : case '[' : return CLASS; default : fatal(); return VOID; // never reach here } } public static int getModifiers(ASTList mods) {<FILL_FUNCTION_BODY>
int m = 0; while (mods != null) { Keyword k = (Keyword)mods.head(); mods = mods.tail(); switch (k.get()) { case STATIC : m |= Modifier.STATIC; break; case FINAL : m |= Modifier.FINAL; break; case SYNCHRONIZED : m |= Modifier.SYNCHRONIZED; break; case ABSTRACT : m |= Modifier.ABSTRACT; break; case PUBLIC : m |= Modifier.PUBLIC; break; case PROTECTED : m |= Modifier.PROTECTED; break; case PRIVATE : m |= Modifier.PRIVATE; break; case VOLATILE : m |= Modifier.VOLATILE; break; case TRANSIENT : m |= Modifier.TRANSIENT; break; case STRICT : m |= Modifier.STRICT; break; } } return m;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/expr/ExprEditor.java
ExprEditor
doit
class ExprEditor { /** * Default constructor. It does nothing. */ public ExprEditor() {} /** * Undocumented method. Do not use; internal-use only. */ public boolean doit(CtClass clazz, MethodInfo minfo) throws CannotCompileException {<FILL_FUNCTION_BODY>} /** * Visits each bytecode in the given range. */ boolean doit(CtClass clazz, MethodInfo minfo, LoopContext context, CodeIterator iterator, int endPos) throws CannotCompileException { boolean edited = false; while (iterator.hasNext() && iterator.lookAhead() < endPos) { int size = iterator.getCodeLength(); if (loopBody(iterator, clazz, minfo, context)) { edited = true; int size2 = iterator.getCodeLength(); if (size != size2) // the body was modified. endPos += size2 - size; } } return edited; } final static class NewOp { NewOp next; int pos; String type; NewOp(NewOp n, int p, String t) { next = n; pos = p; type = t; } } final static class LoopContext { NewOp newList; int maxLocals; int maxStack; LoopContext(int locals) { maxLocals = locals; maxStack = 0; newList = null; } void updateMax(int locals, int stack) { if (maxLocals < locals) maxLocals = locals; if (maxStack < stack) maxStack = stack; } } final boolean loopBody(CodeIterator iterator, CtClass clazz, MethodInfo minfo, LoopContext context) throws CannotCompileException { try { Expr expr = null; int pos = iterator.next(); int c = iterator.byteAt(pos); if (c < Opcode.GETSTATIC) // c < 178 /* skip */; else if (c < Opcode.NEWARRAY) { // c < 188 if (c == Opcode.INVOKESTATIC || c == Opcode.INVOKEINTERFACE || c == Opcode.INVOKEVIRTUAL) { expr = new MethodCall(pos, iterator, clazz, minfo); edit((MethodCall)expr); } else if (c == Opcode.GETFIELD || c == Opcode.GETSTATIC || c == Opcode.PUTFIELD || c == Opcode.PUTSTATIC) { expr = new FieldAccess(pos, iterator, clazz, minfo, c); edit((FieldAccess)expr); } else if (c == Opcode.NEW) { int index = iterator.u16bitAt(pos + 1); context.newList = new NewOp(context.newList, pos, minfo.getConstPool().getClassInfo(index)); } else if (c == Opcode.INVOKESPECIAL) { NewOp newList = context.newList; if (newList != null && minfo.getConstPool().isConstructor(newList.type, iterator.u16bitAt(pos + 1)) > 0) { expr = new NewExpr(pos, iterator, clazz, minfo, newList.type, newList.pos); edit((NewExpr)expr); context.newList = newList.next; } else { MethodCall mcall = new MethodCall(pos, iterator, clazz, minfo); if (mcall.getMethodName().equals(MethodInfo.nameInit)) { ConstructorCall ccall = new ConstructorCall(pos, iterator, clazz, minfo); expr = ccall; edit(ccall); } else { expr = mcall; edit(mcall); } } } } else { // c >= 188 if (c == Opcode.NEWARRAY || c == Opcode.ANEWARRAY || c == Opcode.MULTIANEWARRAY) { expr = new NewArray(pos, iterator, clazz, minfo, c); edit((NewArray)expr); } else if (c == Opcode.INSTANCEOF) { expr = new Instanceof(pos, iterator, clazz, minfo); edit((Instanceof)expr); } else if (c == Opcode.CHECKCAST) { expr = new Cast(pos, iterator, clazz, minfo); edit((Cast)expr); } } if (expr != null && expr.edited()) { context.updateMax(expr.locals(), expr.stack()); return true; } return false; } catch (BadBytecode e) { throw new CannotCompileException(e); } } /** * Edits a <code>new</code> expression (overridable). * The default implementation performs nothing. * * @param e the <code>new</code> expression creating an object. */ public void edit(NewExpr e) throws CannotCompileException {} /** * Edits an expression for array creation (overridable). * The default implementation performs nothing. * * @param a the <code>new</code> expression for creating an array. * @throws CannotCompileException */ public void edit(NewArray a) throws CannotCompileException {} /** * Edits a method call (overridable). * * The default implementation performs nothing. */ public void edit(MethodCall m) throws CannotCompileException {} /** * Edits a constructor call (overridable). * The constructor call is either * <code>super()</code> or <code>this()</code> * included in a constructor body. * * The default implementation performs nothing. * * @see #edit(NewExpr) */ public void edit(ConstructorCall c) throws CannotCompileException {} /** * Edits a field-access expression (overridable). * Field access means both read and write. * The default implementation performs nothing. */ public void edit(FieldAccess f) throws CannotCompileException {} /** * Edits an instanceof expression (overridable). * The default implementation performs nothing. */ public void edit(Instanceof i) throws CannotCompileException {} /** * Edits an expression for explicit type casting (overridable). * The default implementation performs nothing. */ public void edit(Cast c) throws CannotCompileException {} /** * Edits a catch clause (overridable). * The default implementation performs nothing. */ public void edit(Handler h) throws CannotCompileException {} }
CodeAttribute codeAttr = minfo.getCodeAttribute(); if (codeAttr == null) return false; CodeIterator iterator = codeAttr.iterator(); boolean edited = false; LoopContext context = new LoopContext(codeAttr.getMaxLocals()); while (iterator.hasNext()) if (loopBody(iterator, clazz, minfo, context)) edited = true; ExceptionTable et = codeAttr.getExceptionTable(); int n = et.size(); for (int i = 0; i < n; ++i) { Handler h = new Handler(et, i, iterator, clazz, minfo); edit(h); if (h.edited()) { edited = true; context.updateMax(h.locals(), h.stack()); } } // codeAttr might be modified by other partiess // so I check the current value of max-locals. if (codeAttr.getMaxLocals() < context.maxLocals) codeAttr.setMaxLocals(context.maxLocals); codeAttr.setMaxStack(codeAttr.getMaxStack() + context.maxStack); try { if (edited) minfo.rebuildStackMapIf6(clazz.getClassPool(), clazz.getClassFile2()); } catch (BadBytecode b) { throw new CannotCompileException(b.getMessage(), b); } return edited;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/expr/ExprEditor.java
ExprEditor
doit
class ExprEditor { /** * Default constructor. It does nothing. */ public ExprEditor() {} /** * Undocumented method. Do not use; internal-use only. */ public boolean doit(CtClass clazz, MethodInfo minfo) throws CannotCompileException { CodeAttribute codeAttr = minfo.getCodeAttribute(); if (codeAttr == null) return false; CodeIterator iterator = codeAttr.iterator(); boolean edited = false; LoopContext context = new LoopContext(codeAttr.getMaxLocals()); while (iterator.hasNext()) if (loopBody(iterator, clazz, minfo, context)) edited = true; ExceptionTable et = codeAttr.getExceptionTable(); int n = et.size(); for (int i = 0; i < n; ++i) { Handler h = new Handler(et, i, iterator, clazz, minfo); edit(h); if (h.edited()) { edited = true; context.updateMax(h.locals(), h.stack()); } } // codeAttr might be modified by other partiess // so I check the current value of max-locals. if (codeAttr.getMaxLocals() < context.maxLocals) codeAttr.setMaxLocals(context.maxLocals); codeAttr.setMaxStack(codeAttr.getMaxStack() + context.maxStack); try { if (edited) minfo.rebuildStackMapIf6(clazz.getClassPool(), clazz.getClassFile2()); } catch (BadBytecode b) { throw new CannotCompileException(b.getMessage(), b); } return edited; } /** * Visits each bytecode in the given range. */ boolean doit(CtClass clazz, MethodInfo minfo, LoopContext context, CodeIterator iterator, int endPos) throws CannotCompileException {<FILL_FUNCTION_BODY>} final static class NewOp { NewOp next; int pos; String type; NewOp(NewOp n, int p, String t) { next = n; pos = p; type = t; } } final static class LoopContext { NewOp newList; int maxLocals; int maxStack; LoopContext(int locals) { maxLocals = locals; maxStack = 0; newList = null; } void updateMax(int locals, int stack) { if (maxLocals < locals) maxLocals = locals; if (maxStack < stack) maxStack = stack; } } final boolean loopBody(CodeIterator iterator, CtClass clazz, MethodInfo minfo, LoopContext context) throws CannotCompileException { try { Expr expr = null; int pos = iterator.next(); int c = iterator.byteAt(pos); if (c < Opcode.GETSTATIC) // c < 178 /* skip */; else if (c < Opcode.NEWARRAY) { // c < 188 if (c == Opcode.INVOKESTATIC || c == Opcode.INVOKEINTERFACE || c == Opcode.INVOKEVIRTUAL) { expr = new MethodCall(pos, iterator, clazz, minfo); edit((MethodCall)expr); } else if (c == Opcode.GETFIELD || c == Opcode.GETSTATIC || c == Opcode.PUTFIELD || c == Opcode.PUTSTATIC) { expr = new FieldAccess(pos, iterator, clazz, minfo, c); edit((FieldAccess)expr); } else if (c == Opcode.NEW) { int index = iterator.u16bitAt(pos + 1); context.newList = new NewOp(context.newList, pos, minfo.getConstPool().getClassInfo(index)); } else if (c == Opcode.INVOKESPECIAL) { NewOp newList = context.newList; if (newList != null && minfo.getConstPool().isConstructor(newList.type, iterator.u16bitAt(pos + 1)) > 0) { expr = new NewExpr(pos, iterator, clazz, minfo, newList.type, newList.pos); edit((NewExpr)expr); context.newList = newList.next; } else { MethodCall mcall = new MethodCall(pos, iterator, clazz, minfo); if (mcall.getMethodName().equals(MethodInfo.nameInit)) { ConstructorCall ccall = new ConstructorCall(pos, iterator, clazz, minfo); expr = ccall; edit(ccall); } else { expr = mcall; edit(mcall); } } } } else { // c >= 188 if (c == Opcode.NEWARRAY || c == Opcode.ANEWARRAY || c == Opcode.MULTIANEWARRAY) { expr = new NewArray(pos, iterator, clazz, minfo, c); edit((NewArray)expr); } else if (c == Opcode.INSTANCEOF) { expr = new Instanceof(pos, iterator, clazz, minfo); edit((Instanceof)expr); } else if (c == Opcode.CHECKCAST) { expr = new Cast(pos, iterator, clazz, minfo); edit((Cast)expr); } } if (expr != null && expr.edited()) { context.updateMax(expr.locals(), expr.stack()); return true; } return false; } catch (BadBytecode e) { throw new CannotCompileException(e); } } /** * Edits a <code>new</code> expression (overridable). * The default implementation performs nothing. * * @param e the <code>new</code> expression creating an object. */ public void edit(NewExpr e) throws CannotCompileException {} /** * Edits an expression for array creation (overridable). * The default implementation performs nothing. * * @param a the <code>new</code> expression for creating an array. * @throws CannotCompileException */ public void edit(NewArray a) throws CannotCompileException {} /** * Edits a method call (overridable). * * The default implementation performs nothing. */ public void edit(MethodCall m) throws CannotCompileException {} /** * Edits a constructor call (overridable). * The constructor call is either * <code>super()</code> or <code>this()</code> * included in a constructor body. * * The default implementation performs nothing. * * @see #edit(NewExpr) */ public void edit(ConstructorCall c) throws CannotCompileException {} /** * Edits a field-access expression (overridable). * Field access means both read and write. * The default implementation performs nothing. */ public void edit(FieldAccess f) throws CannotCompileException {} /** * Edits an instanceof expression (overridable). * The default implementation performs nothing. */ public void edit(Instanceof i) throws CannotCompileException {} /** * Edits an expression for explicit type casting (overridable). * The default implementation performs nothing. */ public void edit(Cast c) throws CannotCompileException {} /** * Edits a catch clause (overridable). * The default implementation performs nothing. */ public void edit(Handler h) throws CannotCompileException {} }
boolean edited = false; while (iterator.hasNext() && iterator.lookAhead() < endPos) { int size = iterator.getCodeLength(); if (loopBody(iterator, clazz, minfo, context)) { edited = true; int size2 = iterator.getCodeLength(); if (size != size2) // the body was modified. endPos += size2 - size; } } return edited;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/expr/ExprEditor.java
LoopContext
updateMax
class LoopContext { NewOp newList; int maxLocals; int maxStack; LoopContext(int locals) { maxLocals = locals; maxStack = 0; newList = null; } void updateMax(int locals, int stack) {<FILL_FUNCTION_BODY>} }
if (maxLocals < locals) maxLocals = locals; if (maxStack < stack) maxStack = stack;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/expr/ExprEditor.java
LoopContext
loopBody
class LoopContext { NewOp newList; int maxLocals; int maxStack; LoopContext(int locals) { maxLocals = locals; maxStack = 0; newList = null; } void updateMax(int locals, int stack) { if (maxLocals < locals) maxLocals = locals; if (maxStack < stack) maxStack = stack; } } final boolean loopBody(CodeIterator iterator, CtClass clazz, MethodInfo minfo, LoopContext context) throws CannotCompileException {<FILL_FUNCTION_BODY>
try { Expr expr = null; int pos = iterator.next(); int c = iterator.byteAt(pos); if (c < Opcode.GETSTATIC) // c < 178 /* skip */; else if (c < Opcode.NEWARRAY) { // c < 188 if (c == Opcode.INVOKESTATIC || c == Opcode.INVOKEINTERFACE || c == Opcode.INVOKEVIRTUAL) { expr = new MethodCall(pos, iterator, clazz, minfo); edit((MethodCall)expr); } else if (c == Opcode.GETFIELD || c == Opcode.GETSTATIC || c == Opcode.PUTFIELD || c == Opcode.PUTSTATIC) { expr = new FieldAccess(pos, iterator, clazz, minfo, c); edit((FieldAccess)expr); } else if (c == Opcode.NEW) { int index = iterator.u16bitAt(pos + 1); context.newList = new NewOp(context.newList, pos, minfo.getConstPool().getClassInfo(index)); } else if (c == Opcode.INVOKESPECIAL) { NewOp newList = context.newList; if (newList != null && minfo.getConstPool().isConstructor(newList.type, iterator.u16bitAt(pos + 1)) > 0) { expr = new NewExpr(pos, iterator, clazz, minfo, newList.type, newList.pos); edit((NewExpr)expr); context.newList = newList.next; } else { MethodCall mcall = new MethodCall(pos, iterator, clazz, minfo); if (mcall.getMethodName().equals(MethodInfo.nameInit)) { ConstructorCall ccall = new ConstructorCall(pos, iterator, clazz, minfo); expr = ccall; edit(ccall); } else { expr = mcall; edit(mcall); } } } } else { // c >= 188 if (c == Opcode.NEWARRAY || c == Opcode.ANEWARRAY || c == Opcode.MULTIANEWARRAY) { expr = new NewArray(pos, iterator, clazz, minfo, c); edit((NewArray)expr); } else if (c == Opcode.INSTANCEOF) { expr = new Instanceof(pos, iterator, clazz, minfo); edit((Instanceof)expr); } else if (c == Opcode.CHECKCAST) { expr = new Cast(pos, iterator, clazz, minfo); edit((Cast)expr); } } if (expr != null && expr.edited()) { context.updateMax(expr.locals(), expr.stack()); return true; } return false; } catch (BadBytecode e) { throw new CannotCompileException(e); }
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/expr/ExprEditor.java
LoopContext
edit
class LoopContext { NewOp newList; int maxLocals; int maxStack; LoopContext(int locals) { maxLocals = locals; maxStack = 0; newList = null; } void updateMax(int locals, int stack) { if (maxLocals < locals) maxLocals = locals; if (maxStack < stack) maxStack = stack; } } final boolean loopBody(CodeIterator iterator, CtClass clazz, MethodInfo minfo, LoopContext context) throws CannotCompileException { try { Expr expr = null; int pos = iterator.next(); int c = iterator.byteAt(pos); if (c < Opcode.GETSTATIC) // c < 178 /* skip */; else if (c < Opcode.NEWARRAY) { // c < 188 if (c == Opcode.INVOKESTATIC || c == Opcode.INVOKEINTERFACE || c == Opcode.INVOKEVIRTUAL) { expr = new MethodCall(pos, iterator, clazz, minfo); edit((MethodCall)expr); } else if (c == Opcode.GETFIELD || c == Opcode.GETSTATIC || c == Opcode.PUTFIELD || c == Opcode.PUTSTATIC) { expr = new FieldAccess(pos, iterator, clazz, minfo, c); edit((FieldAccess)expr); } else if (c == Opcode.NEW) { int index = iterator.u16bitAt(pos + 1); context.newList = new NewOp(context.newList, pos, minfo.getConstPool().getClassInfo(index)); } else if (c == Opcode.INVOKESPECIAL) { NewOp newList = context.newList; if (newList != null && minfo.getConstPool().isConstructor(newList.type, iterator.u16bitAt(pos + 1)) > 0) { expr = new NewExpr(pos, iterator, clazz, minfo, newList.type, newList.pos); edit((NewExpr)expr); context.newList = newList.next; } else { MethodCall mcall = new MethodCall(pos, iterator, clazz, minfo); if (mcall.getMethodName().equals(MethodInfo.nameInit)) { ConstructorCall ccall = new ConstructorCall(pos, iterator, clazz, minfo); expr = ccall; edit(ccall); } else { expr = mcall; edit(mcall); } } } } else { // c >= 188 if (c == Opcode.NEWARRAY || c == Opcode.ANEWARRAY || c == Opcode.MULTIANEWARRAY) { expr = new NewArray(pos, iterator, clazz, minfo, c); edit((NewArray)expr); } else if (c == Opcode.INSTANCEOF) { expr = new Instanceof(pos, iterator, clazz, minfo); edit((Instanceof)expr); } else if (c == Opcode.CHECKCAST) { expr = new Cast(pos, iterator, clazz, minfo); edit((Cast)expr); } } if (expr != null && expr.edited()) { context.updateMax(expr.locals(), expr.stack()); return true; } return false; } catch (BadBytecode e) { throw new CannotCompileException(e); } } /** * Edits a <code>new</code> expression (overridable). * The default implementation performs nothing. * * @param e the <code>new</code> expression creating an object. */ public void edit(NewExpr e) throws CannotCompileException {<FILL_FUNCTION_BODY>
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/expr/ExprEditor.java
LoopContext
edit
class LoopContext { NewOp newList; int maxLocals; int maxStack; LoopContext(int locals) { maxLocals = locals; maxStack = 0; newList = null; } void updateMax(int locals, int stack) { if (maxLocals < locals) maxLocals = locals; if (maxStack < stack) maxStack = stack; } } final boolean loopBody(CodeIterator iterator, CtClass clazz, MethodInfo minfo, LoopContext context) throws CannotCompileException { try { Expr expr = null; int pos = iterator.next(); int c = iterator.byteAt(pos); if (c < Opcode.GETSTATIC) // c < 178 /* skip */; else if (c < Opcode.NEWARRAY) { // c < 188 if (c == Opcode.INVOKESTATIC || c == Opcode.INVOKEINTERFACE || c == Opcode.INVOKEVIRTUAL) { expr = new MethodCall(pos, iterator, clazz, minfo); edit((MethodCall)expr); } else if (c == Opcode.GETFIELD || c == Opcode.GETSTATIC || c == Opcode.PUTFIELD || c == Opcode.PUTSTATIC) { expr = new FieldAccess(pos, iterator, clazz, minfo, c); edit((FieldAccess)expr); } else if (c == Opcode.NEW) { int index = iterator.u16bitAt(pos + 1); context.newList = new NewOp(context.newList, pos, minfo.getConstPool().getClassInfo(index)); } else if (c == Opcode.INVOKESPECIAL) { NewOp newList = context.newList; if (newList != null && minfo.getConstPool().isConstructor(newList.type, iterator.u16bitAt(pos + 1)) > 0) { expr = new NewExpr(pos, iterator, clazz, minfo, newList.type, newList.pos); edit((NewExpr)expr); context.newList = newList.next; } else { MethodCall mcall = new MethodCall(pos, iterator, clazz, minfo); if (mcall.getMethodName().equals(MethodInfo.nameInit)) { ConstructorCall ccall = new ConstructorCall(pos, iterator, clazz, minfo); expr = ccall; edit(ccall); } else { expr = mcall; edit(mcall); } } } } else { // c >= 188 if (c == Opcode.NEWARRAY || c == Opcode.ANEWARRAY || c == Opcode.MULTIANEWARRAY) { expr = new NewArray(pos, iterator, clazz, minfo, c); edit((NewArray)expr); } else if (c == Opcode.INSTANCEOF) { expr = new Instanceof(pos, iterator, clazz, minfo); edit((Instanceof)expr); } else if (c == Opcode.CHECKCAST) { expr = new Cast(pos, iterator, clazz, minfo); edit((Cast)expr); } } if (expr != null && expr.edited()) { context.updateMax(expr.locals(), expr.stack()); return true; } return false; } catch (BadBytecode e) { throw new CannotCompileException(e); } } /** * Edits a <code>new</code> expression (overridable). * The default implementation performs nothing. * * @param e the <code>new</code> expression creating an object. */ public void edit(NewExpr e) throws CannotCompileException {} /** * Edits an expression for array creation (overridable). * The default implementation performs nothing. * * @param a the <code>new</code> expression for creating an array. * @throws CannotCompileException */ public void edit(NewArray a) throws CannotCompileException {<FILL_FUNCTION_BODY>
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/expr/ExprEditor.java
LoopContext
edit
class LoopContext { NewOp newList; int maxLocals; int maxStack; LoopContext(int locals) { maxLocals = locals; maxStack = 0; newList = null; } void updateMax(int locals, int stack) { if (maxLocals < locals) maxLocals = locals; if (maxStack < stack) maxStack = stack; } } final boolean loopBody(CodeIterator iterator, CtClass clazz, MethodInfo minfo, LoopContext context) throws CannotCompileException { try { Expr expr = null; int pos = iterator.next(); int c = iterator.byteAt(pos); if (c < Opcode.GETSTATIC) // c < 178 /* skip */; else if (c < Opcode.NEWARRAY) { // c < 188 if (c == Opcode.INVOKESTATIC || c == Opcode.INVOKEINTERFACE || c == Opcode.INVOKEVIRTUAL) { expr = new MethodCall(pos, iterator, clazz, minfo); edit((MethodCall)expr); } else if (c == Opcode.GETFIELD || c == Opcode.GETSTATIC || c == Opcode.PUTFIELD || c == Opcode.PUTSTATIC) { expr = new FieldAccess(pos, iterator, clazz, minfo, c); edit((FieldAccess)expr); } else if (c == Opcode.NEW) { int index = iterator.u16bitAt(pos + 1); context.newList = new NewOp(context.newList, pos, minfo.getConstPool().getClassInfo(index)); } else if (c == Opcode.INVOKESPECIAL) { NewOp newList = context.newList; if (newList != null && minfo.getConstPool().isConstructor(newList.type, iterator.u16bitAt(pos + 1)) > 0) { expr = new NewExpr(pos, iterator, clazz, minfo, newList.type, newList.pos); edit((NewExpr)expr); context.newList = newList.next; } else { MethodCall mcall = new MethodCall(pos, iterator, clazz, minfo); if (mcall.getMethodName().equals(MethodInfo.nameInit)) { ConstructorCall ccall = new ConstructorCall(pos, iterator, clazz, minfo); expr = ccall; edit(ccall); } else { expr = mcall; edit(mcall); } } } } else { // c >= 188 if (c == Opcode.NEWARRAY || c == Opcode.ANEWARRAY || c == Opcode.MULTIANEWARRAY) { expr = new NewArray(pos, iterator, clazz, minfo, c); edit((NewArray)expr); } else if (c == Opcode.INSTANCEOF) { expr = new Instanceof(pos, iterator, clazz, minfo); edit((Instanceof)expr); } else if (c == Opcode.CHECKCAST) { expr = new Cast(pos, iterator, clazz, minfo); edit((Cast)expr); } } if (expr != null && expr.edited()) { context.updateMax(expr.locals(), expr.stack()); return true; } return false; } catch (BadBytecode e) { throw new CannotCompileException(e); } } /** * Edits a <code>new</code> expression (overridable). * The default implementation performs nothing. * * @param e the <code>new</code> expression creating an object. */ public void edit(NewExpr e) throws CannotCompileException {} /** * Edits an expression for array creation (overridable). * The default implementation performs nothing. * * @param a the <code>new</code> expression for creating an array. * @throws CannotCompileException */ public void edit(NewArray a) throws CannotCompileException {} /** * Edits a method call (overridable). * * The default implementation performs nothing. */ public void edit(MethodCall m) throws CannotCompileException {<FILL_FUNCTION_BODY>
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/expr/ExprEditor.java
LoopContext
edit
class LoopContext { NewOp newList; int maxLocals; int maxStack; LoopContext(int locals) { maxLocals = locals; maxStack = 0; newList = null; } void updateMax(int locals, int stack) { if (maxLocals < locals) maxLocals = locals; if (maxStack < stack) maxStack = stack; } } final boolean loopBody(CodeIterator iterator, CtClass clazz, MethodInfo minfo, LoopContext context) throws CannotCompileException { try { Expr expr = null; int pos = iterator.next(); int c = iterator.byteAt(pos); if (c < Opcode.GETSTATIC) // c < 178 /* skip */; else if (c < Opcode.NEWARRAY) { // c < 188 if (c == Opcode.INVOKESTATIC || c == Opcode.INVOKEINTERFACE || c == Opcode.INVOKEVIRTUAL) { expr = new MethodCall(pos, iterator, clazz, minfo); edit((MethodCall)expr); } else if (c == Opcode.GETFIELD || c == Opcode.GETSTATIC || c == Opcode.PUTFIELD || c == Opcode.PUTSTATIC) { expr = new FieldAccess(pos, iterator, clazz, minfo, c); edit((FieldAccess)expr); } else if (c == Opcode.NEW) { int index = iterator.u16bitAt(pos + 1); context.newList = new NewOp(context.newList, pos, minfo.getConstPool().getClassInfo(index)); } else if (c == Opcode.INVOKESPECIAL) { NewOp newList = context.newList; if (newList != null && minfo.getConstPool().isConstructor(newList.type, iterator.u16bitAt(pos + 1)) > 0) { expr = new NewExpr(pos, iterator, clazz, minfo, newList.type, newList.pos); edit((NewExpr)expr); context.newList = newList.next; } else { MethodCall mcall = new MethodCall(pos, iterator, clazz, minfo); if (mcall.getMethodName().equals(MethodInfo.nameInit)) { ConstructorCall ccall = new ConstructorCall(pos, iterator, clazz, minfo); expr = ccall; edit(ccall); } else { expr = mcall; edit(mcall); } } } } else { // c >= 188 if (c == Opcode.NEWARRAY || c == Opcode.ANEWARRAY || c == Opcode.MULTIANEWARRAY) { expr = new NewArray(pos, iterator, clazz, minfo, c); edit((NewArray)expr); } else if (c == Opcode.INSTANCEOF) { expr = new Instanceof(pos, iterator, clazz, minfo); edit((Instanceof)expr); } else if (c == Opcode.CHECKCAST) { expr = new Cast(pos, iterator, clazz, minfo); edit((Cast)expr); } } if (expr != null && expr.edited()) { context.updateMax(expr.locals(), expr.stack()); return true; } return false; } catch (BadBytecode e) { throw new CannotCompileException(e); } } /** * Edits a <code>new</code> expression (overridable). * The default implementation performs nothing. * * @param e the <code>new</code> expression creating an object. */ public void edit(NewExpr e) throws CannotCompileException {} /** * Edits an expression for array creation (overridable). * The default implementation performs nothing. * * @param a the <code>new</code> expression for creating an array. * @throws CannotCompileException */ public void edit(NewArray a) throws CannotCompileException {} /** * Edits a method call (overridable). * * The default implementation performs nothing. */ public void edit(MethodCall m) throws CannotCompileException {} /** * Edits a constructor call (overridable). * The constructor call is either * <code>super()</code> or <code>this()</code> * included in a constructor body. * * The default implementation performs nothing. * * @see #edit(NewExpr) */ public void edit(ConstructorCall c) throws CannotCompileException {<FILL_FUNCTION_BODY>
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/expr/ExprEditor.java
LoopContext
edit
class LoopContext { NewOp newList; int maxLocals; int maxStack; LoopContext(int locals) { maxLocals = locals; maxStack = 0; newList = null; } void updateMax(int locals, int stack) { if (maxLocals < locals) maxLocals = locals; if (maxStack < stack) maxStack = stack; } } final boolean loopBody(CodeIterator iterator, CtClass clazz, MethodInfo minfo, LoopContext context) throws CannotCompileException { try { Expr expr = null; int pos = iterator.next(); int c = iterator.byteAt(pos); if (c < Opcode.GETSTATIC) // c < 178 /* skip */; else if (c < Opcode.NEWARRAY) { // c < 188 if (c == Opcode.INVOKESTATIC || c == Opcode.INVOKEINTERFACE || c == Opcode.INVOKEVIRTUAL) { expr = new MethodCall(pos, iterator, clazz, minfo); edit((MethodCall)expr); } else if (c == Opcode.GETFIELD || c == Opcode.GETSTATIC || c == Opcode.PUTFIELD || c == Opcode.PUTSTATIC) { expr = new FieldAccess(pos, iterator, clazz, minfo, c); edit((FieldAccess)expr); } else if (c == Opcode.NEW) { int index = iterator.u16bitAt(pos + 1); context.newList = new NewOp(context.newList, pos, minfo.getConstPool().getClassInfo(index)); } else if (c == Opcode.INVOKESPECIAL) { NewOp newList = context.newList; if (newList != null && minfo.getConstPool().isConstructor(newList.type, iterator.u16bitAt(pos + 1)) > 0) { expr = new NewExpr(pos, iterator, clazz, minfo, newList.type, newList.pos); edit((NewExpr)expr); context.newList = newList.next; } else { MethodCall mcall = new MethodCall(pos, iterator, clazz, minfo); if (mcall.getMethodName().equals(MethodInfo.nameInit)) { ConstructorCall ccall = new ConstructorCall(pos, iterator, clazz, minfo); expr = ccall; edit(ccall); } else { expr = mcall; edit(mcall); } } } } else { // c >= 188 if (c == Opcode.NEWARRAY || c == Opcode.ANEWARRAY || c == Opcode.MULTIANEWARRAY) { expr = new NewArray(pos, iterator, clazz, minfo, c); edit((NewArray)expr); } else if (c == Opcode.INSTANCEOF) { expr = new Instanceof(pos, iterator, clazz, minfo); edit((Instanceof)expr); } else if (c == Opcode.CHECKCAST) { expr = new Cast(pos, iterator, clazz, minfo); edit((Cast)expr); } } if (expr != null && expr.edited()) { context.updateMax(expr.locals(), expr.stack()); return true; } return false; } catch (BadBytecode e) { throw new CannotCompileException(e); } } /** * Edits a <code>new</code> expression (overridable). * The default implementation performs nothing. * * @param e the <code>new</code> expression creating an object. */ public void edit(NewExpr e) throws CannotCompileException {} /** * Edits an expression for array creation (overridable). * The default implementation performs nothing. * * @param a the <code>new</code> expression for creating an array. * @throws CannotCompileException */ public void edit(NewArray a) throws CannotCompileException {} /** * Edits a method call (overridable). * * The default implementation performs nothing. */ public void edit(MethodCall m) throws CannotCompileException {} /** * Edits a constructor call (overridable). * The constructor call is either * <code>super()</code> or <code>this()</code> * included in a constructor body. * * The default implementation performs nothing. * * @see #edit(NewExpr) */ public void edit(ConstructorCall c) throws CannotCompileException {} /** * Edits a field-access expression (overridable). * Field access means both read and write. * The default implementation performs nothing. */ public void edit(FieldAccess f) throws CannotCompileException {<FILL_FUNCTION_BODY>
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/expr/ExprEditor.java
LoopContext
edit
class LoopContext { NewOp newList; int maxLocals; int maxStack; LoopContext(int locals) { maxLocals = locals; maxStack = 0; newList = null; } void updateMax(int locals, int stack) { if (maxLocals < locals) maxLocals = locals; if (maxStack < stack) maxStack = stack; } } final boolean loopBody(CodeIterator iterator, CtClass clazz, MethodInfo minfo, LoopContext context) throws CannotCompileException { try { Expr expr = null; int pos = iterator.next(); int c = iterator.byteAt(pos); if (c < Opcode.GETSTATIC) // c < 178 /* skip */; else if (c < Opcode.NEWARRAY) { // c < 188 if (c == Opcode.INVOKESTATIC || c == Opcode.INVOKEINTERFACE || c == Opcode.INVOKEVIRTUAL) { expr = new MethodCall(pos, iterator, clazz, minfo); edit((MethodCall)expr); } else if (c == Opcode.GETFIELD || c == Opcode.GETSTATIC || c == Opcode.PUTFIELD || c == Opcode.PUTSTATIC) { expr = new FieldAccess(pos, iterator, clazz, minfo, c); edit((FieldAccess)expr); } else if (c == Opcode.NEW) { int index = iterator.u16bitAt(pos + 1); context.newList = new NewOp(context.newList, pos, minfo.getConstPool().getClassInfo(index)); } else if (c == Opcode.INVOKESPECIAL) { NewOp newList = context.newList; if (newList != null && minfo.getConstPool().isConstructor(newList.type, iterator.u16bitAt(pos + 1)) > 0) { expr = new NewExpr(pos, iterator, clazz, minfo, newList.type, newList.pos); edit((NewExpr)expr); context.newList = newList.next; } else { MethodCall mcall = new MethodCall(pos, iterator, clazz, minfo); if (mcall.getMethodName().equals(MethodInfo.nameInit)) { ConstructorCall ccall = new ConstructorCall(pos, iterator, clazz, minfo); expr = ccall; edit(ccall); } else { expr = mcall; edit(mcall); } } } } else { // c >= 188 if (c == Opcode.NEWARRAY || c == Opcode.ANEWARRAY || c == Opcode.MULTIANEWARRAY) { expr = new NewArray(pos, iterator, clazz, minfo, c); edit((NewArray)expr); } else if (c == Opcode.INSTANCEOF) { expr = new Instanceof(pos, iterator, clazz, minfo); edit((Instanceof)expr); } else if (c == Opcode.CHECKCAST) { expr = new Cast(pos, iterator, clazz, minfo); edit((Cast)expr); } } if (expr != null && expr.edited()) { context.updateMax(expr.locals(), expr.stack()); return true; } return false; } catch (BadBytecode e) { throw new CannotCompileException(e); } } /** * Edits a <code>new</code> expression (overridable). * The default implementation performs nothing. * * @param e the <code>new</code> expression creating an object. */ public void edit(NewExpr e) throws CannotCompileException {} /** * Edits an expression for array creation (overridable). * The default implementation performs nothing. * * @param a the <code>new</code> expression for creating an array. * @throws CannotCompileException */ public void edit(NewArray a) throws CannotCompileException {} /** * Edits a method call (overridable). * * The default implementation performs nothing. */ public void edit(MethodCall m) throws CannotCompileException {} /** * Edits a constructor call (overridable). * The constructor call is either * <code>super()</code> or <code>this()</code> * included in a constructor body. * * The default implementation performs nothing. * * @see #edit(NewExpr) */ public void edit(ConstructorCall c) throws CannotCompileException {} /** * Edits a field-access expression (overridable). * Field access means both read and write. * The default implementation performs nothing. */ public void edit(FieldAccess f) throws CannotCompileException {} /** * Edits an instanceof expression (overridable). * The default implementation performs nothing. */ public void edit(Instanceof i) throws CannotCompileException {<FILL_FUNCTION_BODY>
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/expr/ExprEditor.java
LoopContext
edit
class LoopContext { NewOp newList; int maxLocals; int maxStack; LoopContext(int locals) { maxLocals = locals; maxStack = 0; newList = null; } void updateMax(int locals, int stack) { if (maxLocals < locals) maxLocals = locals; if (maxStack < stack) maxStack = stack; } } final boolean loopBody(CodeIterator iterator, CtClass clazz, MethodInfo minfo, LoopContext context) throws CannotCompileException { try { Expr expr = null; int pos = iterator.next(); int c = iterator.byteAt(pos); if (c < Opcode.GETSTATIC) // c < 178 /* skip */; else if (c < Opcode.NEWARRAY) { // c < 188 if (c == Opcode.INVOKESTATIC || c == Opcode.INVOKEINTERFACE || c == Opcode.INVOKEVIRTUAL) { expr = new MethodCall(pos, iterator, clazz, minfo); edit((MethodCall)expr); } else if (c == Opcode.GETFIELD || c == Opcode.GETSTATIC || c == Opcode.PUTFIELD || c == Opcode.PUTSTATIC) { expr = new FieldAccess(pos, iterator, clazz, minfo, c); edit((FieldAccess)expr); } else if (c == Opcode.NEW) { int index = iterator.u16bitAt(pos + 1); context.newList = new NewOp(context.newList, pos, minfo.getConstPool().getClassInfo(index)); } else if (c == Opcode.INVOKESPECIAL) { NewOp newList = context.newList; if (newList != null && minfo.getConstPool().isConstructor(newList.type, iterator.u16bitAt(pos + 1)) > 0) { expr = new NewExpr(pos, iterator, clazz, minfo, newList.type, newList.pos); edit((NewExpr)expr); context.newList = newList.next; } else { MethodCall mcall = new MethodCall(pos, iterator, clazz, minfo); if (mcall.getMethodName().equals(MethodInfo.nameInit)) { ConstructorCall ccall = new ConstructorCall(pos, iterator, clazz, minfo); expr = ccall; edit(ccall); } else { expr = mcall; edit(mcall); } } } } else { // c >= 188 if (c == Opcode.NEWARRAY || c == Opcode.ANEWARRAY || c == Opcode.MULTIANEWARRAY) { expr = new NewArray(pos, iterator, clazz, minfo, c); edit((NewArray)expr); } else if (c == Opcode.INSTANCEOF) { expr = new Instanceof(pos, iterator, clazz, minfo); edit((Instanceof)expr); } else if (c == Opcode.CHECKCAST) { expr = new Cast(pos, iterator, clazz, minfo); edit((Cast)expr); } } if (expr != null && expr.edited()) { context.updateMax(expr.locals(), expr.stack()); return true; } return false; } catch (BadBytecode e) { throw new CannotCompileException(e); } } /** * Edits a <code>new</code> expression (overridable). * The default implementation performs nothing. * * @param e the <code>new</code> expression creating an object. */ public void edit(NewExpr e) throws CannotCompileException {} /** * Edits an expression for array creation (overridable). * The default implementation performs nothing. * * @param a the <code>new</code> expression for creating an array. * @throws CannotCompileException */ public void edit(NewArray a) throws CannotCompileException {} /** * Edits a method call (overridable). * * The default implementation performs nothing. */ public void edit(MethodCall m) throws CannotCompileException {} /** * Edits a constructor call (overridable). * The constructor call is either * <code>super()</code> or <code>this()</code> * included in a constructor body. * * The default implementation performs nothing. * * @see #edit(NewExpr) */ public void edit(ConstructorCall c) throws CannotCompileException {} /** * Edits a field-access expression (overridable). * Field access means both read and write. * The default implementation performs nothing. */ public void edit(FieldAccess f) throws CannotCompileException {} /** * Edits an instanceof expression (overridable). * The default implementation performs nothing. */ public void edit(Instanceof i) throws CannotCompileException {} /** * Edits an expression for explicit type casting (overridable). * The default implementation performs nothing. */ public void edit(Cast c) throws CannotCompileException {<FILL_FUNCTION_BODY>
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/expr/ExprEditor.java
LoopContext
edit
class LoopContext { NewOp newList; int maxLocals; int maxStack; LoopContext(int locals) { maxLocals = locals; maxStack = 0; newList = null; } void updateMax(int locals, int stack) { if (maxLocals < locals) maxLocals = locals; if (maxStack < stack) maxStack = stack; } } final boolean loopBody(CodeIterator iterator, CtClass clazz, MethodInfo minfo, LoopContext context) throws CannotCompileException { try { Expr expr = null; int pos = iterator.next(); int c = iterator.byteAt(pos); if (c < Opcode.GETSTATIC) // c < 178 /* skip */; else if (c < Opcode.NEWARRAY) { // c < 188 if (c == Opcode.INVOKESTATIC || c == Opcode.INVOKEINTERFACE || c == Opcode.INVOKEVIRTUAL) { expr = new MethodCall(pos, iterator, clazz, minfo); edit((MethodCall)expr); } else if (c == Opcode.GETFIELD || c == Opcode.GETSTATIC || c == Opcode.PUTFIELD || c == Opcode.PUTSTATIC) { expr = new FieldAccess(pos, iterator, clazz, minfo, c); edit((FieldAccess)expr); } else if (c == Opcode.NEW) { int index = iterator.u16bitAt(pos + 1); context.newList = new NewOp(context.newList, pos, minfo.getConstPool().getClassInfo(index)); } else if (c == Opcode.INVOKESPECIAL) { NewOp newList = context.newList; if (newList != null && minfo.getConstPool().isConstructor(newList.type, iterator.u16bitAt(pos + 1)) > 0) { expr = new NewExpr(pos, iterator, clazz, minfo, newList.type, newList.pos); edit((NewExpr)expr); context.newList = newList.next; } else { MethodCall mcall = new MethodCall(pos, iterator, clazz, minfo); if (mcall.getMethodName().equals(MethodInfo.nameInit)) { ConstructorCall ccall = new ConstructorCall(pos, iterator, clazz, minfo); expr = ccall; edit(ccall); } else { expr = mcall; edit(mcall); } } } } else { // c >= 188 if (c == Opcode.NEWARRAY || c == Opcode.ANEWARRAY || c == Opcode.MULTIANEWARRAY) { expr = new NewArray(pos, iterator, clazz, minfo, c); edit((NewArray)expr); } else if (c == Opcode.INSTANCEOF) { expr = new Instanceof(pos, iterator, clazz, minfo); edit((Instanceof)expr); } else if (c == Opcode.CHECKCAST) { expr = new Cast(pos, iterator, clazz, minfo); edit((Cast)expr); } } if (expr != null && expr.edited()) { context.updateMax(expr.locals(), expr.stack()); return true; } return false; } catch (BadBytecode e) { throw new CannotCompileException(e); } } /** * Edits a <code>new</code> expression (overridable). * The default implementation performs nothing. * * @param e the <code>new</code> expression creating an object. */ public void edit(NewExpr e) throws CannotCompileException {} /** * Edits an expression for array creation (overridable). * The default implementation performs nothing. * * @param a the <code>new</code> expression for creating an array. * @throws CannotCompileException */ public void edit(NewArray a) throws CannotCompileException {} /** * Edits a method call (overridable). * * The default implementation performs nothing. */ public void edit(MethodCall m) throws CannotCompileException {} /** * Edits a constructor call (overridable). * The constructor call is either * <code>super()</code> or <code>this()</code> * included in a constructor body. * * The default implementation performs nothing. * * @see #edit(NewExpr) */ public void edit(ConstructorCall c) throws CannotCompileException {} /** * Edits a field-access expression (overridable). * Field access means both read and write. * The default implementation performs nothing. */ public void edit(FieldAccess f) throws CannotCompileException {} /** * Edits an instanceof expression (overridable). * The default implementation performs nothing. */ public void edit(Instanceof i) throws CannotCompileException {} /** * Edits an expression for explicit type casting (overridable). * The default implementation performs nothing. */ public void edit(Cast c) throws CannotCompileException {} /** * Edits a catch clause (overridable). * The default implementation performs nothing. */ public void edit(Handler h) throws CannotCompileException {<FILL_FUNCTION_BODY>
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/DefinePackageHelper.java
Java9
definePackage
class Java9 extends Helper { // definePackage has been discontinued for JAVA 9 @Override Package definePackage(ClassLoader loader, String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase) throws IllegalArgumentException {<FILL_FUNCTION_BODY>} }
throw new RuntimeException("define package has been disabled for jigsaw");
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/DefinePackageHelper.java
Java7
getDefinePackageMethodHandle
class Java7 extends Helper { private final SecurityActions stack = SecurityActions.stack; private final MethodHandle definePackage = getDefinePackageMethodHandle(); private MethodHandle getDefinePackageMethodHandle() {<FILL_FUNCTION_BODY>} @Override Package definePackage(ClassLoader loader, String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase) throws IllegalArgumentException { if (stack.getCallerClass() != DefinePackageHelper.class) throw new IllegalAccessError("Access denied for caller."); try { return (Package) definePackage.invokeWithArguments(loader, name, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealBase); } catch (Throwable e) { if (e instanceof IllegalArgumentException) throw (IllegalArgumentException) e; if (e instanceof RuntimeException) throw (RuntimeException) e; } return null; } }
if (stack.getCallerClass() != this.getClass()) throw new IllegalAccessError("Access denied for caller."); try { return SecurityActions.getMethodHandle(ClassLoader.class, "definePackage", new Class[] { String.class, String.class, String.class, String.class, String.class, String.class, String.class, URL.class }); } catch (NoSuchMethodException e) { throw new RuntimeException("cannot initialize", e); }
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/DefinePackageHelper.java
Java7
definePackage
class Java7 extends Helper { private final SecurityActions stack = SecurityActions.stack; private final MethodHandle definePackage = getDefinePackageMethodHandle(); private MethodHandle getDefinePackageMethodHandle() { if (stack.getCallerClass() != this.getClass()) throw new IllegalAccessError("Access denied for caller."); try { return SecurityActions.getMethodHandle(ClassLoader.class, "definePackage", new Class[] { String.class, String.class, String.class, String.class, String.class, String.class, String.class, URL.class }); } catch (NoSuchMethodException e) { throw new RuntimeException("cannot initialize", e); } } @Override Package definePackage(ClassLoader loader, String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase) throws IllegalArgumentException {<FILL_FUNCTION_BODY>} }
if (stack.getCallerClass() != DefinePackageHelper.class) throw new IllegalAccessError("Access denied for caller."); try { return (Package) definePackage.invokeWithArguments(loader, name, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealBase); } catch (Throwable e) { if (e instanceof IllegalArgumentException) throw (IllegalArgumentException) e; if (e instanceof RuntimeException) throw (RuntimeException) e; } return null;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/DefinePackageHelper.java
JavaOther
getDefinePackageMethod
class JavaOther extends Helper { private final SecurityActions stack = SecurityActions.stack; private final Method definePackage = getDefinePackageMethod(); private Method getDefinePackageMethod() {<FILL_FUNCTION_BODY>} @Override Package definePackage(ClassLoader loader, String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase) throws IllegalArgumentException { if (stack.getCallerClass() != DefinePackageHelper.class) throw new IllegalAccessError("Access denied for caller."); try { definePackage.setAccessible(true); return (Package) definePackage.invoke(loader, new Object[] { name, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealBase }); } catch (Throwable e) { if (e instanceof InvocationTargetException) { Throwable t = ((InvocationTargetException) e).getTargetException(); if (t instanceof IllegalArgumentException) throw (IllegalArgumentException) t; } if (e instanceof RuntimeException) throw (RuntimeException) e; } finally { definePackage.setAccessible(false); } return null; } }
if (stack.getCallerClass() != this.getClass()) throw new IllegalAccessError("Access denied for caller."); try { return SecurityActions.getDeclaredMethod(ClassLoader.class, "definePackage", new Class[] { String.class, String.class, String.class, String.class, String.class, String.class, String.class, URL.class }); } catch (NoSuchMethodException e) { throw new RuntimeException("cannot initialize", e); }
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/DefinePackageHelper.java
JavaOther
definePackage
class JavaOther extends Helper { private final SecurityActions stack = SecurityActions.stack; private final Method definePackage = getDefinePackageMethod(); private Method getDefinePackageMethod() { if (stack.getCallerClass() != this.getClass()) throw new IllegalAccessError("Access denied for caller."); try { return SecurityActions.getDeclaredMethod(ClassLoader.class, "definePackage", new Class[] { String.class, String.class, String.class, String.class, String.class, String.class, String.class, URL.class }); } catch (NoSuchMethodException e) { throw new RuntimeException("cannot initialize", e); } } @Override Package definePackage(ClassLoader loader, String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase) throws IllegalArgumentException {<FILL_FUNCTION_BODY>} }
if (stack.getCallerClass() != DefinePackageHelper.class) throw new IllegalAccessError("Access denied for caller."); try { definePackage.setAccessible(true); return (Package) definePackage.invoke(loader, new Object[] { name, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealBase }); } catch (Throwable e) { if (e instanceof InvocationTargetException) { Throwable t = ((InvocationTargetException) e).getTargetException(); if (t instanceof IllegalArgumentException) throw (IllegalArgumentException) t; } if (e instanceof RuntimeException) throw (RuntimeException) e; } finally { definePackage.setAccessible(false); } return null;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/DefinePackageHelper.java
JavaOther
definePackage
class JavaOther extends Helper { private final SecurityActions stack = SecurityActions.stack; private final Method definePackage = getDefinePackageMethod(); private Method getDefinePackageMethod() { if (stack.getCallerClass() != this.getClass()) throw new IllegalAccessError("Access denied for caller."); try { return SecurityActions.getDeclaredMethod(ClassLoader.class, "definePackage", new Class[] { String.class, String.class, String.class, String.class, String.class, String.class, String.class, URL.class }); } catch (NoSuchMethodException e) { throw new RuntimeException("cannot initialize", e); } } @Override Package definePackage(ClassLoader loader, String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase) throws IllegalArgumentException { if (stack.getCallerClass() != DefinePackageHelper.class) throw new IllegalAccessError("Access denied for caller."); try { definePackage.setAccessible(true); return (Package) definePackage.invoke(loader, new Object[] { name, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealBase }); } catch (Throwable e) { if (e instanceof InvocationTargetException) { Throwable t = ((InvocationTargetException) e).getTargetException(); if (t instanceof IllegalArgumentException) throw (IllegalArgumentException) t; } if (e instanceof RuntimeException) throw (RuntimeException) e; } finally { definePackage.setAccessible(false); } return null; } }; private static final Helper privileged = ClassFile.MAJOR_VERSION >= ClassFile.JAVA_9 ? new Java9() : ClassFile.MAJOR_VERSION >= ClassFile.JAVA_7 ? new Java7() : new JavaOther(); /** * Defines a new package. If the package is already defined, this method * performs nothing. * * <p>You do not necessarily need to * call this method. If this method is called, then * <code>getPackage()</code> on the <code>Class</code> object returned * by <code>toClass()</code> will return a non-null object.</p> * * <p>The jigsaw module introduced by Java 9 has broken this method. * In Java 9 or later, the VM argument * <code>--add-opens java.base/java.lang=ALL-UNNAMED</code> * has to be given to the JVM so that this method can run. * </p> * * @param loader the class loader passed to <code>toClass()</code> or * the default one obtained by <code>getClassLoader()</code>. * @param className the package name. * @see Class#getClassLoader() * @see CtClass#toClass() */ public static void definePackage(String className, ClassLoader loader) throws CannotCompileException {<FILL_FUNCTION_BODY>
try { privileged.definePackage(loader, className, null, null, null, null, null, null, null); } catch (IllegalArgumentException e) { // if the package is already defined, an IllegalArgumentException // is thrown. return; } catch (Exception e) { throw new CannotCompileException(e); }
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/RuntimeSupport.java
DefaultMethodHandler
invoke
class DefaultMethodHandler implements MethodHandler, Serializable { /** default serialVersionUID */ private static final long serialVersionUID = 1L; @Override public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Exception {<FILL_FUNCTION_BODY>} }
return proceed.invoke(self, args);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/RuntimeSupport.java
DefaultMethodHandler
find2Methods
class DefaultMethodHandler implements MethodHandler, Serializable { /** default serialVersionUID */ private static final long serialVersionUID = 1L; @Override public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Exception { return proceed.invoke(self, args); } }; /** * Finds two methods specified by the parameters and stores them * into the given array. * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory */ public static void find2Methods(Class<?> clazz, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) {<FILL_FUNCTION_BODY>
methods[index + 1] = thisMethod == null ? null : findMethod(clazz, thisMethod, desc); methods[index] = findSuperClassMethod(clazz, superMethod, desc);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/RuntimeSupport.java
DefaultMethodHandler
find2Methods
class DefaultMethodHandler implements MethodHandler, Serializable { /** default serialVersionUID */ private static final long serialVersionUID = 1L; @Override public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Exception { return proceed.invoke(self, args); } }; /** * Finds two methods specified by the parameters and stores them * into the given array. * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory */ public static void find2Methods(Class<?> clazz, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(clazz, thisMethod, desc); methods[index] = findSuperClassMethod(clazz, superMethod, desc); } /** * Finds two methods specified by the parameters and stores them * into the given array. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory * @deprecated replaced by {@link #find2Methods(Class, String, String, int, String, Method[])} */ @Deprecated public static void find2Methods(Object self, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) {<FILL_FUNCTION_BODY>
methods[index + 1] = thisMethod == null ? null : findMethod(self, thisMethod, desc); methods[index] = findSuperMethod(self, superMethod, desc);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/RuntimeSupport.java
DefaultMethodHandler
findMethod
class DefaultMethodHandler implements MethodHandler, Serializable { /** default serialVersionUID */ private static final long serialVersionUID = 1L; @Override public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Exception { return proceed.invoke(self, args); } }; /** * Finds two methods specified by the parameters and stores them * into the given array. * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory */ public static void find2Methods(Class<?> clazz, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(clazz, thisMethod, desc); methods[index] = findSuperClassMethod(clazz, superMethod, desc); } /** * Finds two methods specified by the parameters and stores them * into the given array. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory * @deprecated replaced by {@link #find2Methods(Class, String, String, int, String, Method[])} */ @Deprecated public static void find2Methods(Object self, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(self, thisMethod, desc); methods[index] = findSuperMethod(self, superMethod, desc); } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the method is not found. * @deprecated replaced by {@link #findMethod(Class, String, String)} */ @Deprecated public static Method findMethod(Object self, String name, String desc) {<FILL_FUNCTION_BODY>
Method m = findMethod2(self.getClass(), name, desc); if (m == null) error(self.getClass(), name, desc); return m;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/RuntimeSupport.java
DefaultMethodHandler
findMethod
class DefaultMethodHandler implements MethodHandler, Serializable { /** default serialVersionUID */ private static final long serialVersionUID = 1L; @Override public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Exception { return proceed.invoke(self, args); } }; /** * Finds two methods specified by the parameters and stores them * into the given array. * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory */ public static void find2Methods(Class<?> clazz, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(clazz, thisMethod, desc); methods[index] = findSuperClassMethod(clazz, superMethod, desc); } /** * Finds two methods specified by the parameters and stores them * into the given array. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory * @deprecated replaced by {@link #find2Methods(Class, String, String, int, String, Method[])} */ @Deprecated public static void find2Methods(Object self, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(self, thisMethod, desc); methods[index] = findSuperMethod(self, superMethod, desc); } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the method is not found. * @deprecated replaced by {@link #findMethod(Class, String, String)} */ @Deprecated public static Method findMethod(Object self, String name, String desc) { Method m = findMethod2(self.getClass(), name, desc); if (m == null) error(self.getClass(), name, desc); return m; } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * @throws RuntimeException if the method is not found. */ public static Method findMethod(Class<?> clazz, String name, String desc) {<FILL_FUNCTION_BODY>
Method m = findMethod2(clazz, name, desc); if (m == null) error(clazz, name, desc); return m;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/RuntimeSupport.java
DefaultMethodHandler
findSuperMethod
class DefaultMethodHandler implements MethodHandler, Serializable { /** default serialVersionUID */ private static final long serialVersionUID = 1L; @Override public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Exception { return proceed.invoke(self, args); } }; /** * Finds two methods specified by the parameters and stores them * into the given array. * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory */ public static void find2Methods(Class<?> clazz, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(clazz, thisMethod, desc); methods[index] = findSuperClassMethod(clazz, superMethod, desc); } /** * Finds two methods specified by the parameters and stores them * into the given array. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory * @deprecated replaced by {@link #find2Methods(Class, String, String, int, String, Method[])} */ @Deprecated public static void find2Methods(Object self, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(self, thisMethod, desc); methods[index] = findSuperMethod(self, superMethod, desc); } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the method is not found. * @deprecated replaced by {@link #findMethod(Class, String, String)} */ @Deprecated public static Method findMethod(Object self, String name, String desc) { Method m = findMethod2(self.getClass(), name, desc); if (m == null) error(self.getClass(), name, desc); return m; } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * @throws RuntimeException if the method is not found. */ public static Method findMethod(Class<?> clazz, String name, String desc) { Method m = findMethod2(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperMethod(Object self, String name, String desc) {<FILL_FUNCTION_BODY>
// for JBoss Seam. See JASSIST-183. Class<?> clazz = self.getClass(); return findSuperClassMethod(clazz, name, desc);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/RuntimeSupport.java
DefaultMethodHandler
findSuperClassMethod
class DefaultMethodHandler implements MethodHandler, Serializable { /** default serialVersionUID */ private static final long serialVersionUID = 1L; @Override public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Exception { return proceed.invoke(self, args); } }; /** * Finds two methods specified by the parameters and stores them * into the given array. * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory */ public static void find2Methods(Class<?> clazz, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(clazz, thisMethod, desc); methods[index] = findSuperClassMethod(clazz, superMethod, desc); } /** * Finds two methods specified by the parameters and stores them * into the given array. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory * @deprecated replaced by {@link #find2Methods(Class, String, String, int, String, Method[])} */ @Deprecated public static void find2Methods(Object self, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(self, thisMethod, desc); methods[index] = findSuperMethod(self, superMethod, desc); } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the method is not found. * @deprecated replaced by {@link #findMethod(Class, String, String)} */ @Deprecated public static Method findMethod(Object self, String name, String desc) { Method m = findMethod2(self.getClass(), name, desc); if (m == null) error(self.getClass(), name, desc); return m; } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * @throws RuntimeException if the method is not found. */ public static Method findMethod(Class<?> clazz, String name, String desc) { Method m = findMethod2(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperMethod(Object self, String name, String desc) { // for JBoss Seam. See JASSIST-183. Class<?> clazz = self.getClass(); return findSuperClassMethod(clazz, name, desc); } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperClassMethod(Class<?> clazz, String name, String desc) {<FILL_FUNCTION_BODY>
Method m = findSuperMethod2(clazz.getSuperclass(), name, desc); if (m == null) m = searchInterfaces(clazz, name, desc); if (m == null) error(clazz, name, desc); return m;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/RuntimeSupport.java
DefaultMethodHandler
error
class DefaultMethodHandler implements MethodHandler, Serializable { /** default serialVersionUID */ private static final long serialVersionUID = 1L; @Override public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Exception { return proceed.invoke(self, args); } }; /** * Finds two methods specified by the parameters and stores them * into the given array. * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory */ public static void find2Methods(Class<?> clazz, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(clazz, thisMethod, desc); methods[index] = findSuperClassMethod(clazz, superMethod, desc); } /** * Finds two methods specified by the parameters and stores them * into the given array. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory * @deprecated replaced by {@link #find2Methods(Class, String, String, int, String, Method[])} */ @Deprecated public static void find2Methods(Object self, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(self, thisMethod, desc); methods[index] = findSuperMethod(self, superMethod, desc); } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the method is not found. * @deprecated replaced by {@link #findMethod(Class, String, String)} */ @Deprecated public static Method findMethod(Object self, String name, String desc) { Method m = findMethod2(self.getClass(), name, desc); if (m == null) error(self.getClass(), name, desc); return m; } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * @throws RuntimeException if the method is not found. */ public static Method findMethod(Class<?> clazz, String name, String desc) { Method m = findMethod2(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperMethod(Object self, String name, String desc) { // for JBoss Seam. See JASSIST-183. Class<?> clazz = self.getClass(); return findSuperClassMethod(clazz, name, desc); } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperClassMethod(Class<?> clazz, String name, String desc) { Method m = findSuperMethod2(clazz.getSuperclass(), name, desc); if (m == null) m = searchInterfaces(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } private static void error(Class<?> clazz, String name, String desc) {<FILL_FUNCTION_BODY>
throw new RuntimeException("not found " + name + ":" + desc + " in " + clazz.getName());
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/RuntimeSupport.java
DefaultMethodHandler
findSuperMethod2
class DefaultMethodHandler implements MethodHandler, Serializable { /** default serialVersionUID */ private static final long serialVersionUID = 1L; @Override public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Exception { return proceed.invoke(self, args); } }; /** * Finds two methods specified by the parameters and stores them * into the given array. * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory */ public static void find2Methods(Class<?> clazz, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(clazz, thisMethod, desc); methods[index] = findSuperClassMethod(clazz, superMethod, desc); } /** * Finds two methods specified by the parameters and stores them * into the given array. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory * @deprecated replaced by {@link #find2Methods(Class, String, String, int, String, Method[])} */ @Deprecated public static void find2Methods(Object self, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(self, thisMethod, desc); methods[index] = findSuperMethod(self, superMethod, desc); } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the method is not found. * @deprecated replaced by {@link #findMethod(Class, String, String)} */ @Deprecated public static Method findMethod(Object self, String name, String desc) { Method m = findMethod2(self.getClass(), name, desc); if (m == null) error(self.getClass(), name, desc); return m; } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * @throws RuntimeException if the method is not found. */ public static Method findMethod(Class<?> clazz, String name, String desc) { Method m = findMethod2(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperMethod(Object self, String name, String desc) { // for JBoss Seam. See JASSIST-183. Class<?> clazz = self.getClass(); return findSuperClassMethod(clazz, name, desc); } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperClassMethod(Class<?> clazz, String name, String desc) { Method m = findSuperMethod2(clazz.getSuperclass(), name, desc); if (m == null) m = searchInterfaces(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } private static void error(Class<?> clazz, String name, String desc) { throw new RuntimeException("not found " + name + ":" + desc + " in " + clazz.getName()); } private static Method findSuperMethod2(Class<?> clazz, String name, String desc) {<FILL_FUNCTION_BODY>
Method m = findMethod2(clazz, name, desc); if (m != null) return m; Class<?> superClass = clazz.getSuperclass(); if (superClass != null) { m = findSuperMethod2(superClass, name, desc); if (m != null) return m; } return searchInterfaces(clazz, name, desc);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/RuntimeSupport.java
DefaultMethodHandler
searchInterfaces
class DefaultMethodHandler implements MethodHandler, Serializable { /** default serialVersionUID */ private static final long serialVersionUID = 1L; @Override public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Exception { return proceed.invoke(self, args); } }; /** * Finds two methods specified by the parameters and stores them * into the given array. * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory */ public static void find2Methods(Class<?> clazz, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(clazz, thisMethod, desc); methods[index] = findSuperClassMethod(clazz, superMethod, desc); } /** * Finds two methods specified by the parameters and stores them * into the given array. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory * @deprecated replaced by {@link #find2Methods(Class, String, String, int, String, Method[])} */ @Deprecated public static void find2Methods(Object self, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(self, thisMethod, desc); methods[index] = findSuperMethod(self, superMethod, desc); } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the method is not found. * @deprecated replaced by {@link #findMethod(Class, String, String)} */ @Deprecated public static Method findMethod(Object self, String name, String desc) { Method m = findMethod2(self.getClass(), name, desc); if (m == null) error(self.getClass(), name, desc); return m; } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * @throws RuntimeException if the method is not found. */ public static Method findMethod(Class<?> clazz, String name, String desc) { Method m = findMethod2(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperMethod(Object self, String name, String desc) { // for JBoss Seam. See JASSIST-183. Class<?> clazz = self.getClass(); return findSuperClassMethod(clazz, name, desc); } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperClassMethod(Class<?> clazz, String name, String desc) { Method m = findSuperMethod2(clazz.getSuperclass(), name, desc); if (m == null) m = searchInterfaces(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } private static void error(Class<?> clazz, String name, String desc) { throw new RuntimeException("not found " + name + ":" + desc + " in " + clazz.getName()); } private static Method findSuperMethod2(Class<?> clazz, String name, String desc) { Method m = findMethod2(clazz, name, desc); if (m != null) return m; Class<?> superClass = clazz.getSuperclass(); if (superClass != null) { m = findSuperMethod2(superClass, name, desc); if (m != null) return m; } return searchInterfaces(clazz, name, desc); } private static Method searchInterfaces(Class<?> clazz, String name, String desc) {<FILL_FUNCTION_BODY>
Method m = null; Class<?>[] interfaces = clazz.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { m = findSuperMethod2(interfaces[i], name, desc); if (m != null) return m; } return m;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/RuntimeSupport.java
DefaultMethodHandler
findMethod2
class DefaultMethodHandler implements MethodHandler, Serializable { /** default serialVersionUID */ private static final long serialVersionUID = 1L; @Override public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Exception { return proceed.invoke(self, args); } }; /** * Finds two methods specified by the parameters and stores them * into the given array. * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory */ public static void find2Methods(Class<?> clazz, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(clazz, thisMethod, desc); methods[index] = findSuperClassMethod(clazz, superMethod, desc); } /** * Finds two methods specified by the parameters and stores them * into the given array. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory * @deprecated replaced by {@link #find2Methods(Class, String, String, int, String, Method[])} */ @Deprecated public static void find2Methods(Object self, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(self, thisMethod, desc); methods[index] = findSuperMethod(self, superMethod, desc); } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the method is not found. * @deprecated replaced by {@link #findMethod(Class, String, String)} */ @Deprecated public static Method findMethod(Object self, String name, String desc) { Method m = findMethod2(self.getClass(), name, desc); if (m == null) error(self.getClass(), name, desc); return m; } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * @throws RuntimeException if the method is not found. */ public static Method findMethod(Class<?> clazz, String name, String desc) { Method m = findMethod2(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperMethod(Object self, String name, String desc) { // for JBoss Seam. See JASSIST-183. Class<?> clazz = self.getClass(); return findSuperClassMethod(clazz, name, desc); } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperClassMethod(Class<?> clazz, String name, String desc) { Method m = findSuperMethod2(clazz.getSuperclass(), name, desc); if (m == null) m = searchInterfaces(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } private static void error(Class<?> clazz, String name, String desc) { throw new RuntimeException("not found " + name + ":" + desc + " in " + clazz.getName()); } private static Method findSuperMethod2(Class<?> clazz, String name, String desc) { Method m = findMethod2(clazz, name, desc); if (m != null) return m; Class<?> superClass = clazz.getSuperclass(); if (superClass != null) { m = findSuperMethod2(superClass, name, desc); if (m != null) return m; } return searchInterfaces(clazz, name, desc); } private static Method searchInterfaces(Class<?> clazz, String name, String desc) { Method m = null; Class<?>[] interfaces = clazz.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { m = findSuperMethod2(interfaces[i], name, desc); if (m != null) return m; } return m; } private static Method findMethod2(Class<?> clazz, String name, String desc) {<FILL_FUNCTION_BODY>
Method[] methods = SecurityActions.getDeclaredMethods(clazz); int n = methods.length; for (int i = 0; i < n; i++) if (methods[i].getName().equals(name) && makeDescriptor(methods[i]).equals(desc)) return methods[i]; return null;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/RuntimeSupport.java
DefaultMethodHandler
makeDescriptor
class DefaultMethodHandler implements MethodHandler, Serializable { /** default serialVersionUID */ private static final long serialVersionUID = 1L; @Override public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Exception { return proceed.invoke(self, args); } }; /** * Finds two methods specified by the parameters and stores them * into the given array. * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory */ public static void find2Methods(Class<?> clazz, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(clazz, thisMethod, desc); methods[index] = findSuperClassMethod(clazz, superMethod, desc); } /** * Finds two methods specified by the parameters and stores them * into the given array. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory * @deprecated replaced by {@link #find2Methods(Class, String, String, int, String, Method[])} */ @Deprecated public static void find2Methods(Object self, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(self, thisMethod, desc); methods[index] = findSuperMethod(self, superMethod, desc); } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the method is not found. * @deprecated replaced by {@link #findMethod(Class, String, String)} */ @Deprecated public static Method findMethod(Object self, String name, String desc) { Method m = findMethod2(self.getClass(), name, desc); if (m == null) error(self.getClass(), name, desc); return m; } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * @throws RuntimeException if the method is not found. */ public static Method findMethod(Class<?> clazz, String name, String desc) { Method m = findMethod2(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperMethod(Object self, String name, String desc) { // for JBoss Seam. See JASSIST-183. Class<?> clazz = self.getClass(); return findSuperClassMethod(clazz, name, desc); } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperClassMethod(Class<?> clazz, String name, String desc) { Method m = findSuperMethod2(clazz.getSuperclass(), name, desc); if (m == null) m = searchInterfaces(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } private static void error(Class<?> clazz, String name, String desc) { throw new RuntimeException("not found " + name + ":" + desc + " in " + clazz.getName()); } private static Method findSuperMethod2(Class<?> clazz, String name, String desc) { Method m = findMethod2(clazz, name, desc); if (m != null) return m; Class<?> superClass = clazz.getSuperclass(); if (superClass != null) { m = findSuperMethod2(superClass, name, desc); if (m != null) return m; } return searchInterfaces(clazz, name, desc); } private static Method searchInterfaces(Class<?> clazz, String name, String desc) { Method m = null; Class<?>[] interfaces = clazz.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { m = findSuperMethod2(interfaces[i], name, desc); if (m != null) return m; } return m; } private static Method findMethod2(Class<?> clazz, String name, String desc) { Method[] methods = SecurityActions.getDeclaredMethods(clazz); int n = methods.length; for (int i = 0; i < n; i++) if (methods[i].getName().equals(name) && makeDescriptor(methods[i]).equals(desc)) return methods[i]; return null; } /** * Makes a descriptor for a given method. */ public static String makeDescriptor(Method m) {<FILL_FUNCTION_BODY>
Class<?>[] params = m.getParameterTypes(); return makeDescriptor(params, m.getReturnType());
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/RuntimeSupport.java
DefaultMethodHandler
makeDescriptor
class DefaultMethodHandler implements MethodHandler, Serializable { /** default serialVersionUID */ private static final long serialVersionUID = 1L; @Override public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Exception { return proceed.invoke(self, args); } }; /** * Finds two methods specified by the parameters and stores them * into the given array. * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory */ public static void find2Methods(Class<?> clazz, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(clazz, thisMethod, desc); methods[index] = findSuperClassMethod(clazz, superMethod, desc); } /** * Finds two methods specified by the parameters and stores them * into the given array. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory * @deprecated replaced by {@link #find2Methods(Class, String, String, int, String, Method[])} */ @Deprecated public static void find2Methods(Object self, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(self, thisMethod, desc); methods[index] = findSuperMethod(self, superMethod, desc); } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the method is not found. * @deprecated replaced by {@link #findMethod(Class, String, String)} */ @Deprecated public static Method findMethod(Object self, String name, String desc) { Method m = findMethod2(self.getClass(), name, desc); if (m == null) error(self.getClass(), name, desc); return m; } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * @throws RuntimeException if the method is not found. */ public static Method findMethod(Class<?> clazz, String name, String desc) { Method m = findMethod2(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperMethod(Object self, String name, String desc) { // for JBoss Seam. See JASSIST-183. Class<?> clazz = self.getClass(); return findSuperClassMethod(clazz, name, desc); } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperClassMethod(Class<?> clazz, String name, String desc) { Method m = findSuperMethod2(clazz.getSuperclass(), name, desc); if (m == null) m = searchInterfaces(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } private static void error(Class<?> clazz, String name, String desc) { throw new RuntimeException("not found " + name + ":" + desc + " in " + clazz.getName()); } private static Method findSuperMethod2(Class<?> clazz, String name, String desc) { Method m = findMethod2(clazz, name, desc); if (m != null) return m; Class<?> superClass = clazz.getSuperclass(); if (superClass != null) { m = findSuperMethod2(superClass, name, desc); if (m != null) return m; } return searchInterfaces(clazz, name, desc); } private static Method searchInterfaces(Class<?> clazz, String name, String desc) { Method m = null; Class<?>[] interfaces = clazz.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { m = findSuperMethod2(interfaces[i], name, desc); if (m != null) return m; } return m; } private static Method findMethod2(Class<?> clazz, String name, String desc) { Method[] methods = SecurityActions.getDeclaredMethods(clazz); int n = methods.length; for (int i = 0; i < n; i++) if (methods[i].getName().equals(name) && makeDescriptor(methods[i]).equals(desc)) return methods[i]; return null; } /** * Makes a descriptor for a given method. */ public static String makeDescriptor(Method m) { Class<?>[] params = m.getParameterTypes(); return makeDescriptor(params, m.getReturnType()); } /** * Makes a descriptor for a given method. * * @param params parameter types. * @param retType return type. */ public static String makeDescriptor(Class<?>[] params, Class<?> retType) {<FILL_FUNCTION_BODY>
StringBuffer sbuf = new StringBuffer(); sbuf.append('('); for (int i = 0; i < params.length; i++) makeDesc(sbuf, params[i]); sbuf.append(')'); if (retType != null) makeDesc(sbuf, retType); return sbuf.toString();
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/RuntimeSupport.java
DefaultMethodHandler
makeDescriptor
class DefaultMethodHandler implements MethodHandler, Serializable { /** default serialVersionUID */ private static final long serialVersionUID = 1L; @Override public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Exception { return proceed.invoke(self, args); } }; /** * Finds two methods specified by the parameters and stores them * into the given array. * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory */ public static void find2Methods(Class<?> clazz, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(clazz, thisMethod, desc); methods[index] = findSuperClassMethod(clazz, superMethod, desc); } /** * Finds two methods specified by the parameters and stores them * into the given array. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory * @deprecated replaced by {@link #find2Methods(Class, String, String, int, String, Method[])} */ @Deprecated public static void find2Methods(Object self, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(self, thisMethod, desc); methods[index] = findSuperMethod(self, superMethod, desc); } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the method is not found. * @deprecated replaced by {@link #findMethod(Class, String, String)} */ @Deprecated public static Method findMethod(Object self, String name, String desc) { Method m = findMethod2(self.getClass(), name, desc); if (m == null) error(self.getClass(), name, desc); return m; } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * @throws RuntimeException if the method is not found. */ public static Method findMethod(Class<?> clazz, String name, String desc) { Method m = findMethod2(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperMethod(Object self, String name, String desc) { // for JBoss Seam. See JASSIST-183. Class<?> clazz = self.getClass(); return findSuperClassMethod(clazz, name, desc); } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperClassMethod(Class<?> clazz, String name, String desc) { Method m = findSuperMethod2(clazz.getSuperclass(), name, desc); if (m == null) m = searchInterfaces(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } private static void error(Class<?> clazz, String name, String desc) { throw new RuntimeException("not found " + name + ":" + desc + " in " + clazz.getName()); } private static Method findSuperMethod2(Class<?> clazz, String name, String desc) { Method m = findMethod2(clazz, name, desc); if (m != null) return m; Class<?> superClass = clazz.getSuperclass(); if (superClass != null) { m = findSuperMethod2(superClass, name, desc); if (m != null) return m; } return searchInterfaces(clazz, name, desc); } private static Method searchInterfaces(Class<?> clazz, String name, String desc) { Method m = null; Class<?>[] interfaces = clazz.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { m = findSuperMethod2(interfaces[i], name, desc); if (m != null) return m; } return m; } private static Method findMethod2(Class<?> clazz, String name, String desc) { Method[] methods = SecurityActions.getDeclaredMethods(clazz); int n = methods.length; for (int i = 0; i < n; i++) if (methods[i].getName().equals(name) && makeDescriptor(methods[i]).equals(desc)) return methods[i]; return null; } /** * Makes a descriptor for a given method. */ public static String makeDescriptor(Method m) { Class<?>[] params = m.getParameterTypes(); return makeDescriptor(params, m.getReturnType()); } /** * Makes a descriptor for a given method. * * @param params parameter types. * @param retType return type. */ public static String makeDescriptor(Class<?>[] params, Class<?> retType) { StringBuffer sbuf = new StringBuffer(); sbuf.append('('); for (int i = 0; i < params.length; i++) makeDesc(sbuf, params[i]); sbuf.append(')'); if (retType != null) makeDesc(sbuf, retType); return sbuf.toString(); } /** * Makes a descriptor for a given method. * * @param params the descriptor of parameter types. * @param retType return type. */ public static String makeDescriptor(String params, Class<?> retType) {<FILL_FUNCTION_BODY>
StringBuffer sbuf = new StringBuffer(params); makeDesc(sbuf, retType); return sbuf.toString();
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/RuntimeSupport.java
DefaultMethodHandler
makeDesc
class DefaultMethodHandler implements MethodHandler, Serializable { /** default serialVersionUID */ private static final long serialVersionUID = 1L; @Override public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Exception { return proceed.invoke(self, args); } }; /** * Finds two methods specified by the parameters and stores them * into the given array. * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory */ public static void find2Methods(Class<?> clazz, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(clazz, thisMethod, desc); methods[index] = findSuperClassMethod(clazz, superMethod, desc); } /** * Finds two methods specified by the parameters and stores them * into the given array. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory * @deprecated replaced by {@link #find2Methods(Class, String, String, int, String, Method[])} */ @Deprecated public static void find2Methods(Object self, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(self, thisMethod, desc); methods[index] = findSuperMethod(self, superMethod, desc); } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the method is not found. * @deprecated replaced by {@link #findMethod(Class, String, String)} */ @Deprecated public static Method findMethod(Object self, String name, String desc) { Method m = findMethod2(self.getClass(), name, desc); if (m == null) error(self.getClass(), name, desc); return m; } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * @throws RuntimeException if the method is not found. */ public static Method findMethod(Class<?> clazz, String name, String desc) { Method m = findMethod2(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperMethod(Object self, String name, String desc) { // for JBoss Seam. See JASSIST-183. Class<?> clazz = self.getClass(); return findSuperClassMethod(clazz, name, desc); } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperClassMethod(Class<?> clazz, String name, String desc) { Method m = findSuperMethod2(clazz.getSuperclass(), name, desc); if (m == null) m = searchInterfaces(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } private static void error(Class<?> clazz, String name, String desc) { throw new RuntimeException("not found " + name + ":" + desc + " in " + clazz.getName()); } private static Method findSuperMethod2(Class<?> clazz, String name, String desc) { Method m = findMethod2(clazz, name, desc); if (m != null) return m; Class<?> superClass = clazz.getSuperclass(); if (superClass != null) { m = findSuperMethod2(superClass, name, desc); if (m != null) return m; } return searchInterfaces(clazz, name, desc); } private static Method searchInterfaces(Class<?> clazz, String name, String desc) { Method m = null; Class<?>[] interfaces = clazz.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { m = findSuperMethod2(interfaces[i], name, desc); if (m != null) return m; } return m; } private static Method findMethod2(Class<?> clazz, String name, String desc) { Method[] methods = SecurityActions.getDeclaredMethods(clazz); int n = methods.length; for (int i = 0; i < n; i++) if (methods[i].getName().equals(name) && makeDescriptor(methods[i]).equals(desc)) return methods[i]; return null; } /** * Makes a descriptor for a given method. */ public static String makeDescriptor(Method m) { Class<?>[] params = m.getParameterTypes(); return makeDescriptor(params, m.getReturnType()); } /** * Makes a descriptor for a given method. * * @param params parameter types. * @param retType return type. */ public static String makeDescriptor(Class<?>[] params, Class<?> retType) { StringBuffer sbuf = new StringBuffer(); sbuf.append('('); for (int i = 0; i < params.length; i++) makeDesc(sbuf, params[i]); sbuf.append(')'); if (retType != null) makeDesc(sbuf, retType); return sbuf.toString(); } /** * Makes a descriptor for a given method. * * @param params the descriptor of parameter types. * @param retType return type. */ public static String makeDescriptor(String params, Class<?> retType) { StringBuffer sbuf = new StringBuffer(params); makeDesc(sbuf, retType); return sbuf.toString(); } private static void makeDesc(StringBuffer sbuf, Class<?> type) {<FILL_FUNCTION_BODY>
if (type.isArray()) { sbuf.append('['); makeDesc(sbuf, type.getComponentType()); } else if (type.isPrimitive()) { if (type == Void.TYPE) sbuf.append('V'); else if (type == Integer.TYPE) sbuf.append('I'); else if (type == Byte.TYPE) sbuf.append('B'); else if (type == Long.TYPE) sbuf.append('J'); else if (type == Double.TYPE) sbuf.append('D'); else if (type == Float.TYPE) sbuf.append('F'); else if (type == Character.TYPE) sbuf.append('C'); else if (type == Short.TYPE) sbuf.append('S'); else if (type == Boolean.TYPE) sbuf.append('Z'); else throw new RuntimeException("bad type: " + type.getName()); } else sbuf.append('L').append(type.getName().replace('.', '/')) .append(';');
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/RuntimeSupport.java
DefaultMethodHandler
makeSerializedProxy
class DefaultMethodHandler implements MethodHandler, Serializable { /** default serialVersionUID */ private static final long serialVersionUID = 1L; @Override public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Exception { return proceed.invoke(self, args); } }; /** * Finds two methods specified by the parameters and stores them * into the given array. * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory */ public static void find2Methods(Class<?> clazz, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(clazz, thisMethod, desc); methods[index] = findSuperClassMethod(clazz, superMethod, desc); } /** * Finds two methods specified by the parameters and stores them * into the given array. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory * @deprecated replaced by {@link #find2Methods(Class, String, String, int, String, Method[])} */ @Deprecated public static void find2Methods(Object self, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(self, thisMethod, desc); methods[index] = findSuperMethod(self, superMethod, desc); } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the method is not found. * @deprecated replaced by {@link #findMethod(Class, String, String)} */ @Deprecated public static Method findMethod(Object self, String name, String desc) { Method m = findMethod2(self.getClass(), name, desc); if (m == null) error(self.getClass(), name, desc); return m; } /** * Finds a method with the given name and descriptor. * It searches only the class of self. * * @throws RuntimeException if the method is not found. */ public static Method findMethod(Class<?> clazz, String name, String desc) { Method m = findMethod2(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperMethod(Object self, String name, String desc) { // for JBoss Seam. See JASSIST-183. Class<?> clazz = self.getClass(); return findSuperClassMethod(clazz, name, desc); } /** * Finds a method that has the given name and descriptor and is declared * in the super class. * * @throws RuntimeException if the method is not found. */ public static Method findSuperClassMethod(Class<?> clazz, String name, String desc) { Method m = findSuperMethod2(clazz.getSuperclass(), name, desc); if (m == null) m = searchInterfaces(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; } private static void error(Class<?> clazz, String name, String desc) { throw new RuntimeException("not found " + name + ":" + desc + " in " + clazz.getName()); } private static Method findSuperMethod2(Class<?> clazz, String name, String desc) { Method m = findMethod2(clazz, name, desc); if (m != null) return m; Class<?> superClass = clazz.getSuperclass(); if (superClass != null) { m = findSuperMethod2(superClass, name, desc); if (m != null) return m; } return searchInterfaces(clazz, name, desc); } private static Method searchInterfaces(Class<?> clazz, String name, String desc) { Method m = null; Class<?>[] interfaces = clazz.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { m = findSuperMethod2(interfaces[i], name, desc); if (m != null) return m; } return m; } private static Method findMethod2(Class<?> clazz, String name, String desc) { Method[] methods = SecurityActions.getDeclaredMethods(clazz); int n = methods.length; for (int i = 0; i < n; i++) if (methods[i].getName().equals(name) && makeDescriptor(methods[i]).equals(desc)) return methods[i]; return null; } /** * Makes a descriptor for a given method. */ public static String makeDescriptor(Method m) { Class<?>[] params = m.getParameterTypes(); return makeDescriptor(params, m.getReturnType()); } /** * Makes a descriptor for a given method. * * @param params parameter types. * @param retType return type. */ public static String makeDescriptor(Class<?>[] params, Class<?> retType) { StringBuffer sbuf = new StringBuffer(); sbuf.append('('); for (int i = 0; i < params.length; i++) makeDesc(sbuf, params[i]); sbuf.append(')'); if (retType != null) makeDesc(sbuf, retType); return sbuf.toString(); } /** * Makes a descriptor for a given method. * * @param params the descriptor of parameter types. * @param retType return type. */ public static String makeDescriptor(String params, Class<?> retType) { StringBuffer sbuf = new StringBuffer(params); makeDesc(sbuf, retType); return sbuf.toString(); } private static void makeDesc(StringBuffer sbuf, Class<?> type) { if (type.isArray()) { sbuf.append('['); makeDesc(sbuf, type.getComponentType()); } else if (type.isPrimitive()) { if (type == Void.TYPE) sbuf.append('V'); else if (type == Integer.TYPE) sbuf.append('I'); else if (type == Byte.TYPE) sbuf.append('B'); else if (type == Long.TYPE) sbuf.append('J'); else if (type == Double.TYPE) sbuf.append('D'); else if (type == Float.TYPE) sbuf.append('F'); else if (type == Character.TYPE) sbuf.append('C'); else if (type == Short.TYPE) sbuf.append('S'); else if (type == Boolean.TYPE) sbuf.append('Z'); else throw new RuntimeException("bad type: " + type.getName()); } else sbuf.append('L').append(type.getName().replace('.', '/')) .append(';'); } /** * Converts a proxy object to an object that is writable to an * object stream. This method is called by <code>writeReplace()</code> * in a proxy class. * * @since 3.4 */ public static SerializedProxy makeSerializedProxy(Object proxy) throws java.io.InvalidClassException {<FILL_FUNCTION_BODY>
Class<?> clazz = proxy.getClass(); MethodHandler methodHandler = null; if (proxy instanceof ProxyObject) methodHandler = ((ProxyObject)proxy).getHandler(); else if (proxy instanceof Proxy) methodHandler = ProxyFactory.getHandler((Proxy)proxy); return new SerializedProxy(clazz, ProxyFactory.getFilterSignature(clazz), methodHandler);
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/util/HotswapTransformer.java
RegisteredTransformersRecord
getIncludedClassLoaderPatterns
class RegisteredTransformersRecord { Pattern pattern; List<HaClassFileTransformer> transformerList = new LinkedList<>(); } protected Map<String, RegisteredTransformersRecord> redefinitionTransformers = new LinkedHashMap<>(); protected Map<String, RegisteredTransformersRecord> otherTransformers = new LinkedHashMap<>(); // keep track about which classloader requested which transformer protected Map<ClassFileTransformer, ClassLoader> classLoaderTransformers = new LinkedHashMap<>(); protected Map<ClassLoader, Boolean> seenClassLoaders = new WeakHashMap<>(); private List<Pattern> includedClassLoaderPatterns; private List<Pattern> excludedClassLoaderPatterns; public List<Pattern> getIncludedClassLoaderPatterns() {<FILL_FUNCTION_BODY>
return includedClassLoaderPatterns;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/util/HotswapTransformer.java
RegisteredTransformersRecord
setIncludedClassLoaderPatterns
class RegisteredTransformersRecord { Pattern pattern; List<HaClassFileTransformer> transformerList = new LinkedList<>(); } protected Map<String, RegisteredTransformersRecord> redefinitionTransformers = new LinkedHashMap<>(); protected Map<String, RegisteredTransformersRecord> otherTransformers = new LinkedHashMap<>(); // keep track about which classloader requested which transformer protected Map<ClassFileTransformer, ClassLoader> classLoaderTransformers = new LinkedHashMap<>(); protected Map<ClassLoader, Boolean> seenClassLoaders = new WeakHashMap<>(); private List<Pattern> includedClassLoaderPatterns; private List<Pattern> excludedClassLoaderPatterns; public List<Pattern> getIncludedClassLoaderPatterns() { return includedClassLoaderPatterns; } public void setIncludedClassLoaderPatterns(List<Pattern> includedClassLoaderPatterns) {<FILL_FUNCTION_BODY>
this.includedClassLoaderPatterns = includedClassLoaderPatterns;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/util/HotswapTransformer.java
RegisteredTransformersRecord
setExcludedClassLoaderPatterns
class RegisteredTransformersRecord { Pattern pattern; List<HaClassFileTransformer> transformerList = new LinkedList<>(); } protected Map<String, RegisteredTransformersRecord> redefinitionTransformers = new LinkedHashMap<>(); protected Map<String, RegisteredTransformersRecord> otherTransformers = new LinkedHashMap<>(); // keep track about which classloader requested which transformer protected Map<ClassFileTransformer, ClassLoader> classLoaderTransformers = new LinkedHashMap<>(); protected Map<ClassLoader, Boolean> seenClassLoaders = new WeakHashMap<>(); private List<Pattern> includedClassLoaderPatterns; private List<Pattern> excludedClassLoaderPatterns; public List<Pattern> getIncludedClassLoaderPatterns() { return includedClassLoaderPatterns; } public void setIncludedClassLoaderPatterns(List<Pattern> includedClassLoaderPatterns) { this.includedClassLoaderPatterns = includedClassLoaderPatterns; } /** * @param excludedClassLoaderPatterns * the excludedClassLoaderPatterns to set */ public void setExcludedClassLoaderPatterns(List<Pattern> excludedClassLoaderPatterns) {<FILL_FUNCTION_BODY>
this.excludedClassLoaderPatterns = excludedClassLoaderPatterns;
HotswapProjects_HotswapAgent
HotswapAgent/hotswap-agent-core/src/main/java/org/hotswap/agent/util/HotswapTransformer.java
RegisteredTransformersRecord
getExcludedClassLoaderPatterns
class RegisteredTransformersRecord { Pattern pattern; List<HaClassFileTransformer> transformerList = new LinkedList<>(); } protected Map<String, RegisteredTransformersRecord> redefinitionTransformers = new LinkedHashMap<>(); protected Map<String, RegisteredTransformersRecord> otherTransformers = new LinkedHashMap<>(); // keep track about which classloader requested which transformer protected Map<ClassFileTransformer, ClassLoader> classLoaderTransformers = new LinkedHashMap<>(); protected Map<ClassLoader, Boolean> seenClassLoaders = new WeakHashMap<>(); private List<Pattern> includedClassLoaderPatterns; private List<Pattern> excludedClassLoaderPatterns; public List<Pattern> getIncludedClassLoaderPatterns() { return includedClassLoaderPatterns; } public void setIncludedClassLoaderPatterns(List<Pattern> includedClassLoaderPatterns) { this.includedClassLoaderPatterns = includedClassLoaderPatterns; } /** * @param excludedClassLoaderPatterns * the excludedClassLoaderPatterns to set */ public void setExcludedClassLoaderPatterns(List<Pattern> excludedClassLoaderPatterns) { this.excludedClassLoaderPatterns = excludedClassLoaderPatterns; } public List<Pattern> getExcludedClassLoaderPatterns() {<FILL_FUNCTION_BODY>
return excludedClassLoaderPatterns;