aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist/bytecode
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2010-04-30 15:20:53 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2010-04-30 15:20:53 +0000
commiteb36a2f1aa2dfeedea085f29ba1e1bb76a8da399 (patch)
treebe0ff29c54c05e43bb36ca163afbae9856b1d45d /src/main/javassist/bytecode
parent5a38e854c0c4fb5854e7d5475ed132b38beb19f8 (diff)
downloadjavassist-eb36a2f1aa2dfeedea085f29ba1e1bb76a8da399.tar.gz
javassist-eb36a2f1aa2dfeedea085f29ba1e1bb76a8da399.zip
performance tuning
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@541 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/bytecode')
-rw-r--r--src/main/javassist/bytecode/Bytecode.java31
-rw-r--r--src/main/javassist/bytecode/ClassFile.java35
-rw-r--r--src/main/javassist/bytecode/ClassFilePrinter.java (renamed from src/main/javassist/bytecode/ClassFileWriter.java)2
3 files changed, 44 insertions, 24 deletions
diff --git a/src/main/javassist/bytecode/Bytecode.java b/src/main/javassist/bytecode/Bytecode.java
index 64128c53..92fd1f02 100644
--- a/src/main/javassist/bytecode/Bytecode.java
+++ b/src/main/javassist/bytecode/Bytecode.java
@@ -37,7 +37,7 @@ class ByteVector implements Cloneable {
public final byte[] copy() {
byte[] b = new byte[size];
- arraycopy(buffer, b, size);
+ System.arraycopy(buffer, 0, b, 0, size);
return b;
}
@@ -60,6 +60,20 @@ class ByteVector implements Cloneable {
buffer[size - 1] = (byte)code;
}
+ public void add(int b1, int b2) {
+ addGap(2);
+ buffer[size - 2] = (byte)b1;
+ buffer[size - 1] = (byte)b2;
+ }
+
+ public void add(int b1, int b2, int b3, int b4) {
+ addGap(4);
+ buffer[size - 4] = (byte)b1;
+ buffer[size - 3] = (byte)b2;
+ buffer[size - 2] = (byte)b3;
+ buffer[size - 1] = (byte)b4;
+ }
+
public void addGap(int length) {
if (size + length > buffer.length) {
int newSize = size << 1;
@@ -67,17 +81,12 @@ class ByteVector implements Cloneable {
newSize = size + length;
byte[] newBuf = new byte[newSize];
- arraycopy(buffer, newBuf, size);
+ System.arraycopy(buffer, 0, newBuf, 0, size);
buffer = newBuf;
}
size += length;
}
-
- private static void arraycopy(byte[] src, byte[] dest, int size) {
- for (int i = 0; i < size; i++)
- dest[i] = src[i];
- }
}
/**
@@ -376,10 +385,7 @@ public class Bytecode extends ByteVector implements Cloneable, Opcode {
* Appends a 32bit value to the end of the bytecode sequence.
*/
public void add32bit(int value) {
- add(value >> 24);
- add(value >> 16);
- add(value >> 8);
- add(value);
+ add(value >> 24, value >> 16, value >> 8, value);
}
/**
@@ -441,8 +447,7 @@ public class Bytecode extends ByteVector implements Cloneable, Opcode {
* It never changes the current stack depth.
*/
public void addIndex(int index) {
- add(index >> 8);
- add(index);
+ add(index >> 8, index);
}
/**
diff --git a/src/main/javassist/bytecode/ClassFile.java b/src/main/javassist/bytecode/ClassFile.java
index 1cd9048b..e6017aac 100644
--- a/src/main/javassist/bytecode/ClassFile.java
+++ b/src/main/javassist/bytecode/ClassFile.java
@@ -19,7 +19,6 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
@@ -40,7 +39,7 @@ public final class ClassFile {
int[] interfaces;
ArrayList fields;
ArrayList methods;
- LinkedList attributes;
+ ArrayList attributes;
String thisclassname; // not JVM-internal name
String[] cachedInterfaces;
String cachedSuperclass;
@@ -135,7 +134,7 @@ public final class ClassFile {
methods = new ArrayList();
thisclassname = classname;
- attributes = new LinkedList();
+ attributes = new ArrayList();
attributes.add(new SourceFileAttribute(constPool,
getSourcefileName(thisclassname)));
}
@@ -209,7 +208,7 @@ public final class ClassFile {
*/
public void prune() {
ConstPool cp = compact0();
- LinkedList newAttributes = new LinkedList();
+ ArrayList newAttributes = new ArrayList();
AttributeInfo invisibleAnnotations
= getAttribute(AnnotationsAttribute.invisibleTag);
if (invisibleAnnotations != null) {
@@ -545,7 +544,15 @@ public final class ClassFile {
fields.add(finfo);
}
- private void addField0(FieldInfo finfo) {
+ /**
+ * Just appends a field to the class.
+ * It does not check field duplication.
+ * Use this method only when minimizing performance overheads
+ * is seriously required.
+ *
+ * @since 3.13
+ */
+ public final void addField2(FieldInfo finfo) {
fields.add(finfo);
}
@@ -607,7 +614,15 @@ public final class ClassFile {
methods.add(minfo);
}
- private void addMethod0(MethodInfo minfo) {
+ /**
+ * Just appends a method to the class.
+ * It does not check method duplication or remove a bridge method.
+ * Use this method only when minimizing performance overheads
+ * is seriously required.
+ *
+ * @since 3.13
+ */
+ public final void addMethod2(MethodInfo minfo) {
methods.add(minfo);
}
@@ -675,7 +690,7 @@ public final class ClassFile {
* @see #getAttributes()
*/
public AttributeInfo getAttribute(String name) {
- LinkedList list = attributes;
+ ArrayList list = attributes;
int n = list.size();
for (int i = 0; i < n; ++i) {
AttributeInfo ai = (AttributeInfo)list.get(i);
@@ -737,14 +752,14 @@ public final class ClassFile {
n = in.readUnsignedShort();
fields = new ArrayList();
for (i = 0; i < n; ++i)
- addField0(new FieldInfo(cp, in));
+ addField2(new FieldInfo(cp, in));
n = in.readUnsignedShort();
methods = new ArrayList();
for (i = 0; i < n; ++i)
- addMethod0(new MethodInfo(cp, in));
+ addMethod2(new MethodInfo(cp, in));
- attributes = new LinkedList();
+ attributes = new ArrayList();
n = in.readUnsignedShort();
for (i = 0; i < n; ++i)
addAttribute(AttributeInfo.read(cp, in));
diff --git a/src/main/javassist/bytecode/ClassFileWriter.java b/src/main/javassist/bytecode/ClassFilePrinter.java
index e1d835bd..49f70661 100644
--- a/src/main/javassist/bytecode/ClassFileWriter.java
+++ b/src/main/javassist/bytecode/ClassFilePrinter.java
@@ -24,7 +24,7 @@ import java.util.List;
* It prints a constant pool table, fields, and methods in a
* human readable representation.
*/
-public class ClassFileWriter {
+public class ClassFilePrinter {
/**
* Prints the contents of a class file to the standard output stream.
*/