Commit 44609277 authored by ebruneton's avatar ebruneton
Browse files

added build options to create customized jars

parent e5c4e088
......@@ -78,6 +78,37 @@
<condition property="product.shrink">
<not><isset property="product.noshrink"/></not>
</condition>
<condition property="SIGV" value="false" else="true">
<isset property="nosignatures"/>
</condition>
<condition property="SIG" value="-signatures" else="">
<isset property="nosignatures"/>
</condition>
<condition property="ANNV" value="false" else="true">
<isset property="noannotations"/>
</condition>
<condition property="ANN" value="-annotations" else="">
<isset property="noannotations"/>
</condition>
<condition property="FRAMESV" value="false" else="true">
<isset property="noframes"/>
</condition>
<condition property="FRAMES" value="-frames" else="">
<isset property="noframes"/>
</condition>
<condition property="WRITERV" value="false" else="true">
<isset property="nowriter"/>
</condition>
<condition property="WRITER" value="-writer" else="">
<isset property="nowriter"/>
</condition>
<condition property="RESIZEV" value="false" else="true">
<isset property="noresize"/>
</condition>
<condition property="RESIZE" value="-resize" else="">
<isset property="noresize"/>
</condition>
</target>
......@@ -119,13 +150,36 @@
<!-- ========== COMPILE ========== -->
<!-- =================================== -->
<target name="compile-debug" depends="init">
<target name="compile-init">
<mkdir dir="${out.build}/tmp"/>
<javac destdir="${out.build}/tmp" debug="on" source="1.3" target="1.2">
<condition property="config.uptodate">
<uptodate srcfile="${src}/org/objectweb/asm/ClassReader.java"
targetfile="${out.build}/tmp/org/objectweb/asm/ClassReader.java"/>
</condition>
<copy todir="${out.build}/tmp">
<fileset dir="${src}">
<include name="**/*"/>
</fileset>
</copy>
</target>
<target name="compile-config" unless="config.uptodate">
<replace dir="${out.build}/tmp">
<include name="**/ClassReader.java"/>
<replacefilter token="SIGNATURES = true" value="SIGNATURES = ${SIGV}"/>
<replacefilter token="ANNOTATIONS = true" value="ANNOTATIONS = ${ANNV}"/>
<replacefilter token="FRAMES = true" value="FRAMES = ${FRAMESV}"/>
<replacefilter token="WRITER = true" value="WRITER = ${SIGV}"/>
<replacefilter token="RESIZE = true" value="RESIZE = ${RESIZEV}"/>
</replace>
</target>
<target name="compile-debug" depends="init,compile-init,compile-config">
<javac destdir="${out.build}/tmp" debug="on" source="1.3" target="1.2">
<classpath>
<pathelement location="${out.build}/tmp"/>
</classpath>
<src path="${src}"/>
<src path="${out.build}/tmp"/>
<include name="**/*.java"/>
</javac>
</target>
......@@ -137,6 +191,11 @@
<pathelement location="${out.build}/tmp"/>
</classpath>
<arg value="${src}/org/objectweb/asm/optimizer/shrink.properties"/>
<arg value="${src}/org/objectweb/asm/optimizer/shrink${SIG}.properties"/>
<arg value="${src}/org/objectweb/asm/optimizer/shrink${ANN}.properties"/>
<arg value="${src}/org/objectweb/asm/optimizer/shrink${FRAMES}.properties"/>
<arg value="${src}/org/objectweb/asm/optimizer/shrink${WRITER}.properties"/>
<arg value="${src}/org/objectweb/asm/optimizer/shrink${RESIZE}.properties"/>
<arg value="${out.build}/tmp"/>
<arg value="${out.build}"/>
</java>
......@@ -252,7 +311,9 @@
<target name="jar" depends="dist.init,dist.version,compile,shrink">
<multipleAnt dir="${archive}"/>
<java classname="org.objectweb.asm.optimizer.JarOptimizer">
<classpath refid="classpath"/>
<classpath>
<pathelement location="${out.build}/tmp"/>
</classpath>
<!--arg value="${src}/org/objectweb/asm/optimizer/jdk1.2.2_017.txt.gz"/-->
<arg value="${src}/org/objectweb/asm/optimizer/jdk1.3.1_19.txt.gz"/>
<arg value="${out.dist.lib}"/>
......
......@@ -43,6 +43,31 @@ import java.io.IOException;
*/
public class ClassReader {
/**
* True to enable signatures support.
*/
final static boolean SIGNATURES = true;
/**
* True to enable annotations support.
*/
final static boolean ANNOTATIONS = true;
/**
* True to enable stack map frames support.
*/
final static boolean FRAMES = true;
/**
* True to enable bytecode writing support.
*/
final static boolean WRITER = true;
/**
* True to enable JSR_W and GOTO_W support.
*/
final static boolean RESIZE = true;
/**
* Flag to skip method code. If this class is set <code>CODE</code>
* attribute won't be visited. This can be used, for example, to retrieve
......@@ -496,9 +521,9 @@ public class ClassReader {
enclosingName = readUTF8(items[item], c);
enclosingDesc = readUTF8(items[item] + 2, c);
}
} else if (attrName.equals("Signature")) {
} else if (SIGNATURES && attrName.equals("Signature")) {
signature = readUTF8(v + 6, c);
} else if (attrName.equals("RuntimeVisibleAnnotations")) {
} else if (ANNOTATIONS && attrName.equals("RuntimeVisibleAnnotations")) {
anns = v + 6;
} else if (attrName.equals("Deprecated")) {
access |= Opcodes.ACC_DEPRECATED;
......@@ -507,7 +532,7 @@ public class ClassReader {
} else if (attrName.equals("SourceDebugExtension")) {
int len = readInt(v + 2);
sourceDebug = readUTF(v + 6, len, new char[len]);
} else if (attrName.equals("RuntimeInvisibleAnnotations")) {
} else if (ANNOTATIONS && attrName.equals("RuntimeInvisibleAnnotations")) {
ianns = v + 6;
} else {
attr = readAttribute(attrs,
......@@ -545,16 +570,18 @@ public class ClassReader {
}
// visits the class annotations
for (i = 1; i >= 0; --i) {
v = i == 0 ? ianns : anns;
if (v != 0) {
j = readUnsignedShort(v);
v += 2;
for (; j > 0; --j) {
v = readAnnotationValues(v + 2,
c,
true,
classVisitor.visitAnnotation(readUTF8(v, c), i != 0));
if (ANNOTATIONS) {
for (i = 1; i >= 0; --i) {
v = i == 0 ? ianns : anns;
if (v != 0) {
j = readUnsignedShort(v);
v += 2;
for (; j > 0; --j) {
v = readAnnotationValues(v + 2,
c,
true,
classVisitor.visitAnnotation(readUTF8(v, c), i != 0));
}
}
}
}
......@@ -606,15 +633,15 @@ public class ClassReader {
// (based on frequencies observed on typical classes)
if (attrName.equals("ConstantValue")) {
fieldValueItem = readUnsignedShort(u + 6);
} else if (attrName.equals("Signature")) {
} else if (SIGNATURES && attrName.equals("Signature")) {
signature = readUTF8(u + 6, c);
} else if (attrName.equals("Deprecated")) {
access |= Opcodes.ACC_DEPRECATED;
} else if (attrName.equals("Synthetic")) {
access |= Opcodes.ACC_SYNTHETIC;
} else if (attrName.equals("RuntimeVisibleAnnotations")) {
} else if (ANNOTATIONS && attrName.equals("RuntimeVisibleAnnotations")) {
anns = u + 6;
} else if (attrName.equals("RuntimeInvisibleAnnotations")) {
} else if (ANNOTATIONS && attrName.equals("RuntimeInvisibleAnnotations")) {
ianns = u + 6;
} else {
attr = readAttribute(attrs,
......@@ -639,16 +666,18 @@ public class ClassReader {
fieldValueItem == 0 ? null : readConst(fieldValueItem, c));
// visits the field annotations and attributes
if (fv != null) {
for (j = 1; j >= 0; --j) {
v = j == 0 ? ianns : anns;
if (v != 0) {
k = readUnsignedShort(v);
v += 2;
for (; k > 0; --k) {
v = readAnnotationValues(v + 2,
c,
true,
fv.visitAnnotation(readUTF8(v, c), j != 0));
if (ANNOTATIONS) {
for (j = 1; j >= 0; --j) {
v = j == 0 ? ianns : anns;
if (v != 0) {
k = readUnsignedShort(v);
v += 2;
for (; k > 0; --k) {
v = readAnnotationValues(v + 2,
c,
true,
fv.visitAnnotation(readUTF8(v, c), j != 0));
}
}
}
}
......@@ -695,22 +724,22 @@ public class ClassReader {
}
} else if (attrName.equals("Exceptions")) {
w = u;
} else if (attrName.equals("Signature")) {
} else if (SIGNATURES && attrName.equals("Signature")) {
signature = readUTF8(u, c);
} else if (attrName.equals("Deprecated")) {
access |= Opcodes.ACC_DEPRECATED;
} else if (attrName.equals("RuntimeVisibleAnnotations")) {
} else if (ANNOTATIONS && attrName.equals("RuntimeVisibleAnnotations")) {
anns = u;
} else if (attrName.equals("AnnotationDefault")) {
} else if (ANNOTATIONS && attrName.equals("AnnotationDefault")) {
dann = u;
} else if (attrName.equals("Synthetic")) {
access |= Opcodes.ACC_SYNTHETIC;
} else if (attrName.equals("RuntimeInvisibleAnnotations")) {
} else if (ANNOTATIONS && attrName.equals("RuntimeInvisibleAnnotations")) {
ianns = u;
} else if (attrName.equals("RuntimeVisibleParameterAnnotations"))
} else if (ANNOTATIONS && attrName.equals("RuntimeVisibleParameterAnnotations"))
{
mpanns = u;
} else if (attrName.equals("RuntimeInvisibleParameterAnnotations"))
} else if (ANNOTATIONS && attrName.equals("RuntimeInvisibleParameterAnnotations"))
{
impanns = u;
} else {
......@@ -760,7 +789,7 @@ public class ClassReader {
* and descriptor can have been changed, this is not important
* since they are not copied as is from the reader).
*/
if (mv instanceof MethodWriter) {
if (WRITER && mv instanceof MethodWriter) {
MethodWriter mw = (MethodWriter) mv;
if (mw.cw.cr == this) {
if (signature == mw.signature) {
......@@ -796,30 +825,32 @@ public class ClassReader {
}
}
if (dann != 0) {
if (ANNOTATIONS && dann != 0) {
AnnotationVisitor dv = mv.visitAnnotationDefault();
readAnnotationValue(dann, c, null, dv);
if (dv != null) {
dv.visitEnd();
}
}
for (j = 1; j >= 0; --j) {
w = j == 0 ? ianns : anns;
if (w != 0) {
k = readUnsignedShort(w);
w += 2;
for (; k > 0; --k) {
w = readAnnotationValues(w + 2,
c,
true,
mv.visitAnnotation(readUTF8(w, c), j != 0));
if (ANNOTATIONS) {
for (j = 1; j >= 0; --j) {
w = j == 0 ? ianns : anns;
if (w != 0) {
k = readUnsignedShort(w);
w += 2;
for (; k > 0; --k) {
w = readAnnotationValues(w + 2,
c,
true,
mv.visitAnnotation(readUTF8(w, c), j != 0));
}
}
}
}
if (mpanns != 0) {
if (ANNOTATIONS && mpanns != 0) {
readParameterAnnotations(mpanns, c, true, mv);
}
if (impanns != 0) {
if (ANNOTATIONS && impanns != 0) {
readParameterAnnotations(impanns, c, false, mv);
}
while (cattrs != null) {
......@@ -983,7 +1014,7 @@ public class ClassReader {
w += 4;
}
}
} else if (attrName.equals("StackMapTable")) {
} else if (FRAMES && attrName.equals("StackMapTable")) {
if ((flags & SKIP_FRAMES) == 0) {
stackMap = v + 8;
frameCount = readUnsignedShort(v + 6);
......@@ -1004,7 +1035,7 @@ public class ClassReader {
*/
// TODO true for frame offsets,
// but for UNINITIALIZED type offsets?
} else if (attrName.equals("StackMap")) {
} else if (FRAMES && attrName.equals("StackMap")) {
if ((flags & SKIP_FRAMES) == 0) {
stackMap = v + 8;
frameCount = readUnsignedShort(v + 6);
......@@ -1035,7 +1066,7 @@ public class ClassReader {
}
// 2nd phase: visits each instruction
if (stackMap != 0) {
if (FRAMES && stackMap != 0) {
// creates the very first (implicit) frame from the method
// descriptor
frameLocal = new Object[maxLocals];
......@@ -1115,7 +1146,7 @@ public class ClassReader {
}
}
while (frameLocal != null
while (FRAMES && frameLocal != null
&& (frameOffset == w || frameOffset == -1))
{
// if there is a frame for this offset,
......
......@@ -589,7 +589,7 @@ public class ClassWriter implements ClassVisitor {
this.access = access;
this.name = newClass(name);
thisName = name;
if (signature != null) {
if (ClassReader.SIGNATURES && signature != null) {
this.signature = newUTF8(signature);
}
this.superName = superName == null ? 0 : newClass(superName);
......@@ -626,6 +626,9 @@ public class ClassWriter implements ClassVisitor {
final String desc,
final boolean visible)
{
if (!ClassReader.ANNOTATIONS) {
return null;
}
ByteVector bv = new ByteVector();
// write type, and reserve space for values count
bv.putShort(newUTF8(desc)).putShort(0);
......@@ -718,7 +721,7 @@ public class ClassWriter implements ClassVisitor {
mb = mb.next;
}
int attributeCount = 0;
if (signature != 0) {
if (ClassReader.SIGNATURES && signature != 0) {
++attributeCount;
size += 8;
newUTF8("Signature");
......@@ -755,12 +758,12 @@ public class ClassWriter implements ClassVisitor {
size += 8 + innerClasses.length;
newUTF8("InnerClasses");
}
if (anns != null) {
if (ClassReader.ANNOTATIONS && anns != null) {
++attributeCount;
size += 8 + anns.getSize();
newUTF8("RuntimeVisibleAnnotations");
}
if (ianns != null) {
if (ClassReader.ANNOTATIONS && ianns != null) {
++attributeCount;
size += 8 + ianns.getSize();
newUTF8("RuntimeInvisibleAnnotations");
......@@ -793,7 +796,7 @@ public class ClassWriter implements ClassVisitor {
mb = mb.next;
}
out.putShort(attributeCount);
if (signature != 0) {
if (ClassReader.SIGNATURES && signature != 0) {
out.putShort(newUTF8("Signature")).putInt(2).putShort(signature);
}
if (sourceFile != 0) {
......@@ -821,11 +824,11 @@ public class ClassWriter implements ClassVisitor {
out.putInt(innerClasses.length + 2).putShort(innerClassesCount);
out.putByteArray(innerClasses.data, 0, innerClasses.length);
}
if (anns != null) {
if (ClassReader.ANNOTATIONS && anns != null) {
out.putShort(newUTF8("RuntimeVisibleAnnotations"));
anns.put(out);
}
if (ianns != null) {
if (ClassReader.ANNOTATIONS && ianns != null) {
out.putShort(newUTF8("RuntimeInvisibleAnnotations"));
ianns.put(out);
}
......
......@@ -122,7 +122,7 @@ final class FieldWriter implements FieldVisitor {
this.access = access;
this.name = cw.newUTF8(name);
this.desc = cw.newUTF8(desc);
if (signature != null) {
if (ClassReader.SIGNATURES && signature != null) {
this.signature = cw.newUTF8(signature);
}
if (value != null) {
......@@ -138,6 +138,9 @@ final class FieldWriter implements FieldVisitor {
final String desc,
final boolean visible)
{
if (!ClassReader.ANNOTATIONS) {
return null;
}
ByteVector bv = new ByteVector();
// write type, and reserve space for values count
bv.putShort(cw.newUTF8(desc)).putShort(0);
......@@ -185,15 +188,15 @@ final class FieldWriter implements FieldVisitor {
cw.newUTF8("Deprecated");
size += 6;
}
if (signature != 0) {
if (ClassReader.SIGNATURES && signature != 0) {
cw.newUTF8("Signature");
size += 8;
}
if (anns != null) {
if (ClassReader.ANNOTATIONS && anns != null) {
cw.newUTF8("RuntimeVisibleAnnotations");
size += 8 + anns.getSize();
}
if (ianns != null) {
if (ClassReader.ANNOTATIONS && ianns != null) {
cw.newUTF8("RuntimeInvisibleAnnotations");
size += 8 + ianns.getSize();
}
......@@ -222,13 +225,13 @@ final class FieldWriter implements FieldVisitor {
if ((access & Opcodes.ACC_DEPRECATED) != 0) {
++attributeCount;
}
if (signature != 0) {
if (ClassReader.SIGNATURES && signature != 0) {
++attributeCount;
}
if (anns != null) {
if (ClassReader.ANNOTATIONS && anns != null) {
++attributeCount;
}
if (ianns != null) {
if (ClassReader.ANNOTATIONS && ianns != null) {
++attributeCount;
}
if (attrs != null) {
......@@ -247,15 +250,15 @@ final class FieldWriter implements FieldVisitor {
if ((access & Opcodes.ACC_DEPRECATED) != 0) {
out.putShort(cw.newUTF8("Deprecated")).putInt(0);
}
if (signature != 0) {
if (ClassReader.SIGNATURES && signature != 0) {
out.putShort(cw.newUTF8("Signature"));
out.putInt(2).putShort(signature);
}
if (anns != null) {
if (ClassReader.ANNOTATIONS && anns != null) {
out.putShort(cw.newUTF8("RuntimeVisibleAnnotations"));
anns.put(out);
}
if (ianns != null) {
if (ClassReader.ANNOTATIONS && ianns != null) {
out.putShort(cw.newUTF8("RuntimeInvisibleAnnotations"));
ianns.put(out);
}
......
......@@ -396,7 +396,7 @@ public class Label {
* @return the first label of the series to which this label belongs.
*/
Label getFirst() {
return frame == null ? this : frame.owner;
return !ClassReader.FRAMES || frame == null ? this : frame.owner;
}
// ------------------------------------------------------------------------
......
......@@ -424,7 +424,9 @@ class MethodWriter implements MethodVisitor {
this.name = cw.newUTF8(name);
this.desc = cw.newUTF8(desc);
this.descriptor = desc;
this.signature = signature;
if (ClassReader.SIGNATURES) {
this.signature = signature;
}
if (exceptions != null && exceptions.length > 0) {
exceptionCount = exceptions.length;
this.exceptions = new int[exceptionCount];
......@@ -455,6 +457,9 @@ class MethodWriter implements MethodVisitor {
// ------------------------------------------------------------------------
public AnnotationVisitor visitAnnotationDefault() {
if (!ClassReader.ANNOTATIONS) {
return null;
}
annd = new ByteVector();
return new AnnotationWriter(cw, false, annd, null, 0);
}
......@@ -463,6 +468,9 @@ class MethodWriter implements MethodVisitor {
final String desc,
final boolean visible)
{
if (!ClassReader.ANNOTATIONS) {
return null;
}
ByteVector bv = new ByteVector();
// write type, and reserve space for values count
bv.putShort(cw.newUTF8(desc)).putShort(0);
......@@ -482,6 +490,9 @@ class MethodWriter implements MethodVisitor {
final String desc,
final boolean visible)
{
if (!ClassReader.ANNOTATIONS) {
return null;
}
ByteVector bv = new ByteVector();
// write type, and reserve space for values count
bv.putShort(cw.newUTF8(desc)).putShort(0);
......@@ -522,7 +533,7 @@ class MethodWriter implements MethodVisitor {
final int nStack,
final Object[] stack)
{
if (compute == FRAMES) {
if (!ClassReader.FRAMES || compute == FRAMES) {
return;
}
......@@ -1178,7 +1189,7 @@ class MethodWriter implements MethodVisitor {
}
public void visitMaxs(final int maxStack, final int maxLocals) {
if (compute == FRAMES) {
if (ClassReader.FRAMES && compute == FRAMES) {
// completes the control flow graph with exception handler blocks
Handler handler = firstHandler;
while (handler != null) {
......@@ -1841,7 +1852,11 @@ class MethodWriter implements MethodVisitor {
}
if (resize) {
// replaces the temporary jump opcodes introduced by Label.resolve.
resizeInstructions();
if (ClassReader.RESIZE) {
resizeInstructions();
} else {
throw new RuntimeException("Method code too large!");
}
}
int size = 8;
if (code.length > 0) {
......@@ -1886,31 +1901,31 @@ class MethodWriter implements MethodVisitor {
cw.newUTF8("Deprecated");
size += 6;
}
if (signature != null) {
if (ClassReader.SIGNATURES && signature != null) {
cw.newUTF8("Signature");
cw.newUTF8(signature);
size += 8;
}
if (annd != null) {
if (ClassReader.ANNOTATIONS && annd != null) {
cw.newUTF8("AnnotationDefault");
size += 6 + annd.length;
}
if (anns != null) {
if (ClassReader.ANNOTATIONS && anns != null) {
cw.newUTF8("RuntimeVisibleAnnotations");
size += 8 + anns.getSize();
}
if (ianns != null) {
if (ClassReader.ANNOTATIONS && ianns != null) {
cw.newUTF8("RuntimeInvisibleAnnotations");
size += 8 + ianns.getSize();
}
if (panns != null) {
if (ClassReader.ANNOTATIONS && panns != null) {
cw.newUTF8("RuntimeVisibleParameterAnnotations");
size += 7 + 2 * panns.length;
for (int i = panns.length - 1; i >= 0; --i) {
size += panns[i] == null ? 0 : panns[i].getSize();
}
}
if (ipanns != null) {
if (ClassReader.ANNOTATIONS && ipanns != null) {
cw.newUTF8("RuntimeInvisibleParameterAnnotations");
size += 7 + 2 * ipanns.length;
for (int i = ipanns.length - 1; i >= 0; --i) {