You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by sj...@apache.org on 2008/11/27 12:30:10 UTC
svn commit: r721161 - in
/harmony/enhanced/classlib/trunk/modules/pack200/src:
main/java/org/apache/harmony/pack200/
test/java/org/apache/harmony/pack200/tests/
Author: sjanuary
Date: Thu Nov 27 03:30:06 2008
New Revision: 721161
URL: http://svn.apache.org/viewvc?rev=721161&view=rev
Log:
New pack200 test cases, and bug fixes to enable them to pass, including:
- Improved support for Synthetic attributes
- Fix for an encoding bug
- Empty LocalVariableTable attributes added to all Code attributes
Modified:
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BHSDCodec.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BHSDCodec.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BHSDCodec.java?rev=721161&r1=721160&r2=721161&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BHSDCodec.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BHSDCodec.java Thu Nov 27 03:30:06 2008
@@ -285,6 +285,8 @@
if (isSigned()) {
if(z < Integer.MIN_VALUE) {
z += 4294967296L;
+ } else if (z > Integer.MAX_VALUE) {
+ z -= 4294967296L;
}
if (z < 0) {
z = (-z << s) - 1;
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java?rev=721161&r1=721160&r2=721161&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java Thu Nov 27 03:30:06 2008
@@ -133,7 +133,7 @@
private List classInnerClassesNameRUN;
public void addClass(int major, int flags, String className,
- String superName, String[] interfaces) {
+ String signature, String superName, String[] interfaces) {
class_this[index] = cpBands.getCPClass(className);
class_super[index] = cpBands.getCPClass(superName);
class_interface_count[index] = interfaces.length;
@@ -143,10 +143,14 @@
}
major_versions[index] = major;
class_flags[index] = flags;
- if(!anySyntheticClasses && ((flags & (1 << 12)) != 0)) {
+ if(!anySyntheticClasses && ((flags & (1 << 12)) != 0) && segment.getCurrentClassReader().hasSyntheticAttributes()) {
cpBands.addCPUtf8("Synthetic");
anySyntheticClasses = true;
}
+ if(signature != null) {
+ class_flags[index] |= (1 << 19);
+ classSignature.add(cpBands.getCPSignature(signature));
+ }
}
public void currentClassReferencesInnerClass(CPClass inner) {
@@ -176,7 +180,7 @@
fieldConstantValueKQ.add(cpBands.getConstant(value));
flags |= (1 << 17);
}
- if(!anySyntheticFields && ((flags & (1 << 12)) != 0)) {
+ if(!anySyntheticFields && ((flags & (1 << 12)) != 0) && segment.getCurrentClassReader().hasSyntheticAttributes()) {
cpBands.addCPUtf8("Synthetic");
anySyntheticFields = true;
}
@@ -484,7 +488,7 @@
}
tempMethodFlags.add(new Long(flags));
numMethodArgs = countArgs(desc);
- if(!anySyntheticMethods && ((flags & (1 << 12)) != 0)) {
+ if(!anySyntheticMethods && ((flags & (1 << 12)) != 0) && segment.getCurrentClassReader().hasSyntheticAttributes()) {
cpBands.addCPUtf8("Synthetic");
anySyntheticMethods = true;
}
@@ -601,7 +605,8 @@
public void addCode() {
codeHandlerCount.add(ZERO);
- codeFlags.add(new Long(0));
+ codeFlags.add(new Long((1 << 2))); // TODO: What if there's no debug information?
+ codeLocalVariableTableN.add(new Integer(0));
}
public void addHandler(Label start, Label end, Label handler, String type) {
@@ -652,16 +657,9 @@
codeLocalVariableTypeTableSlot.add(new Integer(indx));
}
// LocalVariableTable attribute
- Long latestCodeFlag = (Long) codeFlags.get(codeFlags.size() - 1);
- if ((latestCodeFlag.intValue() & (1 << 2)) == 0) {
- codeFlags.remove(codeFlags.size() - 1);
- codeFlags.add(new Long(latestCodeFlag.intValue() | (1 << 2)));
- codeLocalVariableTableN.add(new Integer(1));
- } else {
- Integer numLocals = (Integer) codeLocalVariableTableN
- .remove(codeLocalVariableTableN.size() - 1);
- codeLocalVariableTableN.add(new Integer(numLocals.intValue() + 1));
- }
+ Integer numLocals = (Integer) codeLocalVariableTableN
+ .remove(codeLocalVariableTableN.size() - 1);
+ codeLocalVariableTableN.add(new Integer(numLocals.intValue() + 1));
codeLocalVariableTableBciP.add(start);
codeLocalVariableTableSpanO.add(end);
codeLocalVariableTableNameRU.add(cpBands.getCPUtf8(name));
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java?rev=721161&r1=721160&r2=721161&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java Thu Nov 27 03:30:06 2008
@@ -434,7 +434,19 @@
removeCpUtf8(signature);
for (Iterator iterator2 = classes.iterator(); iterator2
.hasNext();) {
- cpClasses.add(getCPClass((String) iterator2.next()));
+ String className = (String) iterator2.next();
+ CPClass cpClass = null;
+ if(className!= null) {
+ className = className.replace('.', '/');
+ cpClass = (CPClass) stringsToCpClass.get(className);
+ if (cpClass == null) {
+ CPUTF8 cpUtf8 = getCPUtf8(className);
+ cpClass = new CPClass(cpUtf8);
+ cp_Class.add(cpClass);
+ stringsToCpClass.put(className, cpClass);
+ }
+ }
+ cpClasses.add(cpClass);
}
signatureUTF8 = getCPUtf8(signatureString.toString());
@@ -515,8 +527,15 @@
constant = new CPString(getCPUtf8((String) value));
cp_String.add(constant);
} else if (value instanceof Type) {
- constant = new CPClass(getCPUtf8(((Type) value).getClassName()));
- cp_Class.add(constant);
+ String className = ((Type) value).getClassName();
+ if(className.endsWith("[]")) {
+ className = "[L" + className.substring(0, className.length() - 2);
+ while(className.endsWith("[]")) {
+ className = "[" + className.substring(0, className.length() - 2);
+ }
+ className += ";";
+ }
+ constant = getCPClass(className);
}
objectsToCPConstant.put(value, constant);
}
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java?rev=721161&r1=721160&r2=721161&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java Thu Nov 27 03:30:06 2008
@@ -28,6 +28,8 @@
public class Pack200ClassReader extends ClassReader {
private boolean lastConstantHadWideIndex;
+ private int lastUnsignedShort;
+ private static boolean anySyntheticAttributes;
/**
* @param b
@@ -52,11 +54,31 @@
super(name);
}
+ public int readUnsignedShort(int index) {
+ // Doing this to check whether last load-constant instruction was ldc (18) or ldc_w (19)
+ // TODO: Assess whether this impacts on performance
+ int unsignedShort = super.readUnsignedShort(index);
+ if(b[index - 1] == 19) {
+ lastUnsignedShort = unsignedShort;
+ } else {
+ lastUnsignedShort = Short.MIN_VALUE;
+ }
+ return unsignedShort;
+ }
+
public Object readConst(int item, char[] buf) {
- lastConstantHadWideIndex = item > Byte.MAX_VALUE;
+ lastConstantHadWideIndex = item == lastUnsignedShort;
return super.readConst(item, buf);
}
+ public String readUTF8(int arg0, char[] arg1) {
+ String utf8 = super.readUTF8(arg0, arg1);
+ if(!anySyntheticAttributes && utf8.equals("Synthetic")) {
+ anySyntheticAttributes = true;
+ }
+ return utf8;
+ }
+
/**
* @param b
* @param off
@@ -70,4 +92,12 @@
return lastConstantHadWideIndex;
}
+ public static boolean hasSyntheticAttributes() {
+ return anySyntheticAttributes;
+ }
+
+ public static void resetSyntheticCounter() {
+ anySyntheticAttributes = false;
+ }
+
}
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java?rev=721161&r1=721160&r2=721161&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java Thu Nov 27 03:30:06 2008
@@ -45,6 +45,7 @@
public void pack(List classes, List files, OutputStream out)
throws IOException, Pack200Exception {
+ Pack200ClassReader.resetSyntheticCounter();
segmentHeader = new SegmentHeader();
segmentHeader.setFile_count(files.size());
cpBands = new CpBands(this);
@@ -87,7 +88,7 @@
bcBands.setCurrentClass(name);
bcBands.setSuperClass(superName);
segmentHeader.addMajorVersion(version);
- classBands.addClass(version, access, name, superName, interfaces);
+ classBands.addClass(version, access, name, signature, superName, interfaces);
}
public void visitSource(String source, String debug) {
@@ -307,4 +308,8 @@
public IcBands getIcBands() {
return icBands;
}
+
+ public Pack200ClassReader getCurrentClassReader() {
+ return currentClassReader;
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java?rev=721161&r1=721160&r2=721161&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java Thu Nov 27 03:30:06 2008
@@ -25,6 +25,7 @@
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URISyntaxException;
+import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarInputStream;
@@ -38,12 +39,11 @@
public class ArchiveTest extends TestCase {
- File file;
JarInputStream in;
OutputStream out;
+ File file;
- public void testHelloWorld() throws IOException, Pack200Exception,
- URISyntaxException {
+ public void testHelloWorld() throws IOException, Pack200Exception, URISyntaxException {
in = new JarInputStream(
Archive.class
.getResourceAsStream("/org/apache/harmony/pack200/tests/hw.jar"));
@@ -92,7 +92,87 @@
}
reader1.close();
reader2.close();
+ }
+
+ public void testSQL() throws IOException, Pack200Exception, URISyntaxException {
+ in = new JarInputStream(Archive.class
+ .getResourceAsStream("/org/apache/harmony/pack200/tests/sqlUnpacked.jar"));
+ file = File.createTempFile("sql", ".pack");
+ out = new FileOutputStream(file);
+ new Archive(in, out, false).pack();
+ in.close();
+ out.close();
+
+ // now unpack
+ InputStream in2 = new FileInputStream(file);
+ File file2 = File.createTempFile("sqlout", ".jar");
+ JarOutputStream out2 = new JarOutputStream(new FileOutputStream(file2));
+ org.apache.harmony.unpack200.Archive archive = new org.apache.harmony.unpack200.Archive(in2, out2);
+ archive.unpack();
+ JarFile jarFile = new JarFile(file2);
+ file2.deleteOnExit();
+ JarFile jarFile2 = new JarFile(new File(Archive.class.getResource(
+ "/org/apache/harmony/pack200/tests/sqlUnpacked.jar").toURI()));
+
+ compareFiles(jarFile, jarFile2);
+ }
+
+ public void testJNDI() throws IOException, Pack200Exception, URISyntaxException {
+ in = new JarInputStream(Archive.class
+ .getResourceAsStream("/org/apache/harmony/pack200/tests/jndi.jar"));
+ file = File.createTempFile("jndi", ".pack");
+ out = new FileOutputStream(file);
+ new Archive(in, out, false).pack();
+ in.close();
+ out.close();
+
+ // now unpack
+ InputStream in2 = new FileInputStream(file);
+ File file2 = File.createTempFile("jndiout", ".jar");
+ JarOutputStream out2 = new JarOutputStream(new FileOutputStream(file2));
+ org.apache.harmony.unpack200.Archive archive = new org.apache.harmony.unpack200.Archive(in2, out2);
+ archive.unpack();
+ JarFile jarFile = new JarFile(file2);
+ file2.deleteOnExit();
+ JarFile jarFile2 = new JarFile(new File(Archive.class.getResource(
+ "/org/apache/harmony/pack200/tests/jndiUnpacked.jar").toURI()));
+
+ compareFiles(jarFile, jarFile2);
+ }
+
+ private void compareFiles(JarFile jarFile, JarFile jarFile2)
+ throws IOException {
+ Enumeration entries = jarFile.entries();
+ while (entries.hasMoreElements()) {
+
+ JarEntry entry = (JarEntry) entries.nextElement();
+ assertNotNull(entry);
+
+ String name = entry.getName();
+ JarEntry entry2 = jarFile2.getJarEntry(name);
+ assertNotNull(entry2);
+ if(!name.equals("META-INF/MANIFEST.MF")) { // Manifests aren't necessarily byte-for-byte identical
+
+ InputStream ours = jarFile.getInputStream(entry);
+ InputStream expected = jarFile2.getInputStream(entry2);
+
+ BufferedReader reader1 = new BufferedReader(new InputStreamReader(ours));
+ BufferedReader reader2 = new BufferedReader(new InputStreamReader(
+ expected));
+ String line1 = reader1.readLine();
+ String line2 = reader2.readLine();
+ int i = 1;
+ while (line1 != null || line2 != null) {
+ assertEquals("Unpacked files differ for " + name, line2, line1);
+ line1 = reader1.readLine();
+ line2 = reader2.readLine();
+ i++;
+ }
+ reader1.close();
+ reader2.close();
+ }
+ }
}
}
Re: svn commit: r721161 - in /harmony/enhanced/classlib/trunk/modules/pack200/src: main/java/org/apache/harmony/pack200/ test/java/org/apache/harmony/pack200/tests/
Posted by Sian January <si...@googlemail.com>.
It would be ok to use multiple instances of the reader concurrently as
long as they relates to the same pack file, but I suppose you're right
in that there could be a situation where two different files are being
packed concurrently in the same VM. I will have a re-think.
Thanks,
Sian
2008/11/27 Nathan Beyer <nd...@apache.org>:
> I was browsing this comment and noticed this bit below, inline ...
>
> On Thu, Nov 27, 2008 at 5:30 AM, <sj...@apache.org> wrote:
>> Author: sjanuary
>> Date: Thu Nov 27 03:30:06 2008
>> New Revision: 721161
>>
>> URL: http://svn.apache.org/viewvc?rev=721161&view=rev
>> Log:
>> New pack200 test cases, and bug fixes to enable them to pass, including:
>> - Improved support for Synthetic attributes
>> - Fix for an encoding bug
>> - Empty LocalVariableTable attributes added to all Code attributes
>>
>> Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java
>> URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java?rev=721161&r1=721160&r2=721161&view=diff
>> ==============================================================================
>> --- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java (original)
>> +++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java Thu Nov 27 03:30:06 2008
>> @@ -28,6 +28,8 @@
>> public class Pack200ClassReader extends ClassReader {
>>
>> private boolean lastConstantHadWideIndex;
>> + private int lastUnsignedShort;
>
> Shouldn't this be a instance field, rather than a class field? If it's
> a class field (static), then you couldn't use multiple instances of
> the reader concurrently.
>
>> + private static boolean anySyntheticAttributes;
>>
>
--
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
Re: svn commit: r721161 - in /harmony/enhanced/classlib/trunk/modules/pack200/src: main/java/org/apache/harmony/pack200/ test/java/org/apache/harmony/pack200/tests/
Posted by Nathan Beyer <nd...@apache.org>.
I was browsing this comment and noticed this bit below, inline ...
On Thu, Nov 27, 2008 at 5:30 AM, <sj...@apache.org> wrote:
> Author: sjanuary
> Date: Thu Nov 27 03:30:06 2008
> New Revision: 721161
>
> URL: http://svn.apache.org/viewvc?rev=721161&view=rev
> Log:
> New pack200 test cases, and bug fixes to enable them to pass, including:
> - Improved support for Synthetic attributes
> - Fix for an encoding bug
> - Empty LocalVariableTable attributes added to all Code attributes
>
> Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java
> URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java?rev=721161&r1=721160&r2=721161&view=diff
> ==============================================================================
> --- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java (original)
> +++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java Thu Nov 27 03:30:06 2008
> @@ -28,6 +28,8 @@
> public class Pack200ClassReader extends ClassReader {
>
> private boolean lastConstantHadWideIndex;
> + private int lastUnsignedShort;
Shouldn't this be a instance field, rather than a class field? If it's
a class field (static), then you couldn't use multiple instances of
the reader concurrently.
> + private static boolean anySyntheticAttributes;
>