harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r609928 [3/5] - in /harmony/enhanced/classlib/branches/java6: ./ make/ modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/ modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/ modules/awt/src/main/native/gl/share...
Date Tue, 08 Jan 2008 10:55:41 GMT
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java Tue Jan  8 02:55:24 2008
@@ -275,42 +275,74 @@
                 timeout);
     }
 
-	/*
-	 * 
-	 * @param 
-     *      readChannels all channels interested in read and accept 
-     * @param
-	 *      writeChannels all channels interested in write and connect 
+	/**
+     * Select the given file descriptors for read and write operations.
+     * 
+     * The file descriptors passed in as readFDs will be selected for read-ready
+     * operations, and those in the writeFDs will be selected for write-ready
+     * operations. A file descriptor can appear in either or both array, and
+     * must not be <code>null</code>. If the file descriptor is closed during
+     * the select the behavior depends upon the underlying OS.
+     * 
+     * Upon return the result is a single array of length
+     * <code>readFDs.length</code> + <code>writeFDs.length</code> laid out
+     * as the result of the select operation on the corresponding file
+     * descriptors.
+     * 
+     * @param readChannels
+     *            all channels interested in read and accept
+     * @param writeChannels
+     *            all channels interested in write and connect
      * @param timeout
-	 *      timeout in millis @return a set of channels that are ready for operation
-	 * @throws 
-     *      SocketException @return int array, each int approve one of the	 * channel if OK
-	 */
-
-	public int[] select(FileDescriptor[] readFDs,
-            FileDescriptor[] writeFDs, long timeout)
-			throws SocketException {
-		int countRead = readFDs.length;
-		int countWrite = writeFDs.length;
-		int result = 0;
+     *            timeout in millis
+     * @returns int array, each element describes the corresponding state of the
+     *          descriptor in the read and write arrays.
+     * @throws SocketException
+     */
+    public int[] select(FileDescriptor[] readFDs, FileDescriptor[] writeFDs,
+            long timeout) throws SocketException {
+        int countRead = readFDs.length;
+        int countWrite = writeFDs.length;
+        int result = 0;
         if (0 == countRead + countWrite) {
             return (new int[0]);
         }
-		int[] flags = new int[countRead + countWrite];
+        int[] flags = new int[countRead + countWrite];
+
+        assert validateFDs(readFDs, writeFDs) : "Invalid file descriptor arrays";
 
         // handle timeout in native
-		result = selectImpl(readFDs, writeFDs, countRead, countWrite, flags,
-				timeout);
+        result = selectImpl(readFDs, writeFDs, countRead, countWrite, flags,
+                timeout);
 
-		if (0 <= result) {
-			return flags;
-		}
-		if (ERRORCODE_SOCKET_TIMEOUT == result) {
-			return new int[0];
-		}
-		throw new SocketException();
+        if (0 <= result) {
+            return flags;
+        }
+        if (ERRORCODE_SOCKET_TIMEOUT == result) {
+            return new int[0];
+        }
+        throw new SocketException();
+    }
 
-	}
+    /*
+     * Used to check if the file descriptor arrays are valid before passing them
+     * into the select native call.
+     */
+    private boolean validateFDs(FileDescriptor[] readFDs,
+            FileDescriptor[] writeFDs) {
+        for (FileDescriptor fd : readFDs) {
+            // Also checks fd not null
+            if (!fd.valid()) {
+                return false;
+            }
+        }
+        for (FileDescriptor fd : writeFDs) {
+            if (!fd.valid()) {
+                return false;
+            }
+        }
+        return true;
+    }
 
 	public InetAddress getSocketLocalAddress(FileDescriptor aFD,
 			boolean preferIPv6Addresses) {

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/include/unix/jclprots.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/include/unix/jclprots.h?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/include/unix/jclprots.h (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/include/unix/jclprots.h Tue Jan  8 02:55:24 2008
@@ -228,7 +228,6 @@
 /* NativesCommonFileDescriptor*/
 void JNICALL Java_java_io_FileDescriptor_oneTimeInitialization PROTOTYPE((JNIEnv * env, jclass fdClazz));
 void JNICALL Java_java_io_FileDescriptor_sync PROTOTYPE((JNIEnv * env, jobject recv));
-jboolean JNICALL Java_java_io_FileDescriptor_valid PROTOTYPE((JNIEnv * env, jobject recv));
 
 /* NativesCommonProcess*/
 jint JNICALL Java_org_apache_harmony_luni_internal_process_ProcessInputStream_availableImpl PROTOTYPE((JNIEnv * env, jobject recv));

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/include/windows/jclprots.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/include/windows/jclprots.h?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/include/windows/jclprots.h (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/include/windows/jclprots.h Tue Jan  8 02:55:24 2008
@@ -405,8 +405,6 @@
     PROTOTYPE ((JNIEnv * env, jclass fdClazz));
   JNIEXPORT void JNICALL Java_java_io_FileDescriptor_sync
     PROTOTYPE ((JNIEnv * env, jobject recv));
-  JNIEXPORT jboolean JNICALL Java_java_io_FileDescriptor_valid
-    PROTOTYPE ((JNIEnv * env, jobject recv));
     
   /* NativesCommonProcess*/
   JNIEXPORT jint JNICALL Java_org_apache_harmony_luni_internal_process_ProcessInputStream_availableImpl

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/filedesc.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/filedesc.c?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/filedesc.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/filedesc.c Tue Jan  8 02:55:24 2008
@@ -20,17 +20,6 @@
 #include "exceptions.h"
 #include "harmonyglob.h"
 
-JNIEXPORT jboolean JNICALL
-Java_java_io_FileDescriptor_valid (JNIEnv * env, jobject recv)
-{
-  /**
-    * Currently only answer false if the descriptor is -1.  Possibly there 
-    * could be an OS check to see if the handle has been invalidated 
-    */
-  void *descriptor = getJavaIoFileDescriptorContentsAsAPointer (env, recv);
-  return (IDATA) descriptor != -1;
-}
-
 JNIEXPORT void JNICALL
 Java_java_io_FileDescriptor_syncImpl (JNIEnv * env, jobject recv)
 {

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/luniglob.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/luniglob.c?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/luniglob.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/luniglob.c Tue Jan  8 02:55:24 2008
@@ -346,10 +346,6 @@
             returnCode = JNI_ERR;
             goto cleanup;
         }
-        if (!bootstrapClassPath) {
-            /* no such property yet */
-            bootstrapClassPath = "";
-        }
 
         qsort(props, number, sizeof(key_value_pair), props_compare);
 
@@ -362,11 +358,13 @@
             if (tokensScanned == 1)
             {
                 char *oldPath = bootstrapClassPath;
-                bootstrapClassPath = str_concat (PORTLIB, 
-                    bootstrapClassPath, cpSeparator,
-                    bootDirectory, props[i].value, NULL);
-                if (i != 0) 
-                {
+                if ((!oldPath) || (strlen(bootstrapClassPath) == 0)) {
+                    bootstrapClassPath = str_concat (PORTLIB, 
+                        bootDirectory, props[i].value, NULL);
+                } else {
+                    bootstrapClassPath = str_concat (PORTLIB, 
+                        bootstrapClassPath, cpSeparator,
+                        bootDirectory, props[i].value, NULL);
                     hymem_free_memory (oldPath);
                 }
 

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/nethelp.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/nethelp.c?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/nethelp.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/nethelp.c Tue Jan  8 02:55:24 2008
@@ -307,27 +307,27 @@
   char *errorMessage = netLookupErrorString (env, errorNumber);
   jstring errorMessageString = (*env)->NewStringUTF (env,errorMessage);
   if (HYPORT_ERROR_SOCKET_WOULDBLOCK == errorNumber){
-  	   errorCodeExClass = (*env)->FindClass (env, "org/apache/harmony/luni/util/ErrorCodeException");
-  	   if (!errorCodeExClass){
-  	           return;
-  	   }
-  	   errorCodeExConstructor = (*env)->GetMethodID(env,errorCodeExClass,"<init>","(I)V");
-       if (!errorCodeExConstructor){
-               return;
-       }
-       errorCodeEx = (*env)->NewObject(env, errorCodeExClass,errorCodeExConstructor,errorNumber);
-       socketExClass = (*env)->FindClass (env, "java/net/SocketException");
-  	   if (!socketExClass) {
-  	           return;
-  	   }
-  	   socketExConstructor = (*env)->GetMethodID(env,socketExClass,"<init>","(Ljava/lang/String;)V");
-       if (!socketExConstructor) {
-               return;
-       }
-       socketEx = (*env)->NewObject(env, socketExClass, socketExConstructor, errorMessageString); 
-       socketExCauseMethod = (*env)->GetMethodID(env,socketExClass,"initCause","(Ljava/lang/Throwable;)Ljava/lang/Throwable;");
-       (*env)->CallObjectMethod(env,socketEx,socketExCauseMethod,errorCodeEx);
-       (*env)->Throw(env,socketEx);
+    errorCodeExClass = (*env)->FindClass (env, "org/apache/harmony/luni/util/ErrorCodeException");
+    if (!errorCodeExClass){
+      return;
+    }
+    errorCodeExConstructor = (*env)->GetMethodID(env,errorCodeExClass,"<init>","(I)V");
+    if (!errorCodeExConstructor){
+      return;
+    }
+    errorCodeEx = (*env)->NewObject(env, errorCodeExClass,errorCodeExConstructor,errorNumber);
+    socketExClass = (*env)->FindClass (env, "java/net/SocketException");
+    if (!socketExClass) {
+      return;
+    }
+    socketExConstructor = (*env)->GetMethodID(env,socketExClass,"<init>","(Ljava/lang/String;)V");
+    if (!socketExConstructor) {
+      return;
+    }
+    socketEx = (*env)->NewObject(env, socketExClass, socketExConstructor, errorMessageString); 
+    socketExCauseMethod = (*env)->GetMethodID(env,socketExClass,"initCause","(Ljava/lang/Throwable;)Ljava/lang/Throwable;");
+    (*env)->CallObjectMethod(env,socketEx,socketExCauseMethod,errorCodeEx);
+    (*env)->Throw(env,socketEx);
   }
   throwNewExceptionByName(env, "java/net/SocketException", errorMessage);
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c Tue Jan  8 02:55:24 2008
@@ -267,7 +267,8 @@
 	  hysocketP = getJavaIoFileDescriptorContentsAsAPointer	(env, gotFD);
       (*env)->DeleteLocalRef(env, gotFD);
 
-      my_pollfds[val].fd = hysocketP->sock;
+      /* hysocketP is -1 if the socket is closed */
+      my_pollfds[val].fd = hysocketP == -1 ? -1 : hysocketP->sock;
       my_pollfds[val].events = POLLIN | POLLPRI;
       my_pollfds[val].revents = 0;
   }
@@ -277,7 +278,8 @@
 	  hysocketP = getJavaIoFileDescriptorContentsAsAPointer	(env, gotFD);
       (*env)->DeleteLocalRef(env, gotFD);
 
-      my_pollfds[countReadC + val].fd = hysocketP->sock;
+      /* hysocketP is -1 if the socket is closed */
+      my_pollfds[countReadC + val].fd = hysocketP == -1 ? -1 : hysocketP->sock;
       my_pollfds[countReadC + val].events = POLLOUT;
       my_pollfds[countReadC + val].revents = 0;
   }

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/windows/makefile
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/windows/makefile?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/windows/makefile (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/windows/makefile Tue Jan  8 02:55:24 2008
@@ -53,6 +53,6 @@
   $(LIBPATH)hyfdlibm$(HY_LINKLIB_SUFFIX) $(LIBPATH)vmi$(HY_LINKLIB_SUFFIX)
 
 DLLBASE=0x13200000
-COMMENT=/comment:"LUNI component native code. (c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable."
+COMMENT=/comment:"LUNI component native code. (c) Copyright 1991, 2007 The Apache Software Foundation or its licensors, as applicable."
 
 !include <$(HY_HDK)\build\make\rules.mak>

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/DataInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/DataInputStreamTest.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/DataInputStreamTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/DataInputStreamTest.java Tue Jan  8 02:55:24 2008
@@ -18,6 +18,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.DataInput;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.EOFException;
@@ -540,6 +541,67 @@
                 assertTrue("Incorrect string read", dis.readUTF().equals(unihw));
 	}
 
+    static class TestDataInputStream implements DataInput {
+        public boolean readBoolean() throws IOException {
+            return false;
+        }
+
+        public byte readByte() throws IOException {
+            return (byte) 0;
+        }
+
+        public char readChar() throws IOException {
+            return (char) 0;
+        }
+
+        public double readDouble() throws IOException {
+            return 0.0;
+        }
+
+        public float readFloat() throws IOException {
+            return (float) 0.0;
+        }
+
+        public void readFully(byte[] buffer) throws IOException {
+        }
+
+        public void readFully(byte[] buffer, int offset, int count)
+            throws IOException {
+        }
+
+        public int readInt() throws IOException {
+            return 0;
+        }
+
+        public String readLine() throws IOException {
+            return null;
+        }
+
+        public long readLong() throws IOException {
+            return (long) 0;
+        }
+
+        public short readShort() throws IOException {
+            return (short) 0;
+        }
+
+        public int readUnsignedByte() throws IOException {
+            return 0;
+        }
+
+        public int readUnsignedShort() throws IOException {
+            return 0;
+        }
+
+        public String readUTF() throws IOException {
+            return DataInputStream.readUTF(this);
+        }
+
+        public int skipBytes(int count) throws IOException {
+            return 0;
+        }
+    }
+
 	/**
 	 * @tests java.io.DataInputStream#readUTF(java.io.DataInput)
 	 */
@@ -553,6 +615,9 @@
                                 dis.available() == unihw.length() + 2);
                 assertTrue("Incorrect string read", DataInputStream.readUTF(dis)
                                 .equals(unihw));
+
+                // Regression test for HARMONY-5336
+                new TestDataInputStream().readUTF();
 	}
 
 	/**

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/FileOutputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/FileOutputStreamTest.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/FileOutputStreamTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/FileOutputStreamTest.java Tue Jan  8 02:55:24 2008
@@ -229,7 +229,7 @@
 		tmpfile.deleteOnExit();
 		FileOutputStream fos = new FileOutputStream(tmpfile);
 		byte[] b = new byte[10];
-		for (int i = 10; i < b.length; i++) {
+		for (int i = 0; i < b.length; i++) {
 			b[i] = (byte) i;
 		}
 		fos.write(b);

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/ObjectInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/ObjectInputStreamTest.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/ObjectInputStreamTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/ObjectInputStreamTest.java Tue Jan  8 02:55:24 2008
@@ -20,6 +20,7 @@
 import java.io.BufferedInputStream;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.Externalizable;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -27,8 +28,10 @@
 import java.io.InputStream;
 import java.io.InvalidObjectException;
 import java.io.NotActiveException;
+import java.io.ObjectInput;
 import java.io.ObjectInputStream;
 import java.io.ObjectInputValidation;
+import java.io.ObjectOutput;
 import java.io.ObjectOutputStream;
 import java.io.ObjectStreamClass;
 import java.io.OutputStream;
@@ -1034,6 +1037,57 @@
         testArray = (TestArray) oin.readObject();
         Integer[] integers = new Integer[] { 10, 20 };
         assertTrue(java.util.Arrays.equals(integers, testArray.array));
+    }
+
+    public static class TestExtObject implements Externalizable {
+        public void writeExternal(ObjectOutput out) throws IOException {
+            out.writeInt(10);
+        }
+
+        public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+            in.readInt();
+        }
+    }
+
+    static class TestObjectOutputStream extends ObjectOutputStream {
+        private ObjectStreamClass[] objs;
+        private int pos = 0;
+
+        public TestObjectOutputStream(OutputStream out, ObjectStreamClass[] objs) throws IOException {
+            super(out);
+            this.objs = objs;
+        }
+
+        protected void writeClassDescriptor(ObjectStreamClass osc) throws IOException {
+            objs[pos++] = osc;        }
+    }
+
+    static class TestObjectInputStream extends ObjectInputStream {
+        private ObjectStreamClass[] objs;
+        private int pos = 0;
+
+        public TestObjectInputStream(InputStream in, ObjectStreamClass[] objs) throws IOException {
+            super(in);
+            this.objs = objs;
+        }
+
+        protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
+            return (ObjectStreamClass) objs[pos++];
+        }
+    }
+
+    // Regression test for HARMONY-4996
+    public void test_readObject_replacedClassDescriptor() throws Exception {
+        ObjectStreamClass[] objs = new ObjectStreamClass[1000];
+        PipedOutputStream pout = new PipedOutputStream();
+        PipedInputStream pin = new PipedInputStream(pout);
+        ObjectOutputStream oout = new TestObjectOutputStream(pout, objs);
+        oout.writeObject(new TestExtObject());
+        oout.writeObject("test");
+        oout.close();
+        ObjectInputStream oin = new TestObjectInputStream(pin, objs);
+        oin.readObject();
+        oin.readObject();
     }
 
     /**

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/io/WinFileTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/io/WinFileTest.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/io/WinFileTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/io/WinFileTest.java Tue Jan  8 02:55:24 2008
@@ -120,19 +120,16 @@
 
         f = new File(folder, FILENAME);        
         assertEquals("Invalid file name", FILENAME, f.getName()); 
-        if (f.exists()) {
-            byte tmp[] = new byte[256];
-            String wasRed;
-            int n;
+        assertTrue("File does not exist", f.exists());
+        byte tmp[] = new byte[256];
+        String wasRed;
+        int n;
 
-            fis = new FileInputStream(f);
-            n = fis.read(tmp);
-            fis.close();
-            wasRed = new String(tmp, 0, n, CNTNT_CHARSET);
-            assertEquals("Invalid content was red", CONTENT, wasRed);
-        } else {
-            fail("File does not exist");
-        }
+        fis = new FileInputStream(f);
+        n = fis.read(tmp);
+        fis.close();
+        wasRed = new String(tmp, 0, n, CNTNT_CHARSET);
+        assertEquals("Invalid content was red", CONTENT, wasRed);
     }
 
 

Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java Tue Jan  8 02:55:24 2008
@@ -359,8 +359,14 @@
      */
     void modKey(SelectionKey sk) {
         // TODO: update indexes rather than recreate the key
-        delKey(sk);
-        addKey(sk);
+        synchronized (this) {
+            synchronized (keysSet) {
+                synchronized (selectedKeys) {
+                    delKey(sk);
+                    addKey(sk);
+                }
+            }
+        }
     }
 
     /**
@@ -578,6 +584,9 @@
         return unaddableSelectedKeys;
     }
 
+    /*
+     * Assumes calling thread holds locks on 'this', 'keysSet', and 'selectedKeys'. 
+     */
     private void doCancel() {
         Set<SelectionKey> cancelledKeys = cancelledKeys();
         synchronized (cancelledKeys) {

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttrDefinitionBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttrDefinitionBands.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttrDefinitionBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttrDefinitionBands.java Tue Jan  8 02:55:24 2008
@@ -18,7 +18,6 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 
 /**
  *
@@ -41,14 +40,6 @@
     }
 
     /* (non-Javadoc)
-     * @see org.apache.harmony.pack200.BandSet#pack(java.io.OutputStream)
-     */
-    public void pack(OutputStream outputStream) {
-        // TODO Auto-generated method stub
-
-    }
-
-    /* (non-Javadoc)
      * @see org.apache.harmony.pack200.BandSet#unpack(java.io.InputStream)
      */
     public void unpack(InputStream in) throws IOException,
@@ -73,9 +64,11 @@
             if(index == -1) {
                 index = overflowIndex++;
             }
-            attributeDefinitionMap.add(new AttributeLayout(
+            AttributeLayout layout = new AttributeLayout(
                     attributeDefinitionName[i], context,
-                    attributeDefinitionLayout[i], index));
+                    attributeDefinitionLayout[i], index, false);
+            NewAttributeBands newBands = new NewAttributeBands(segment, layout);
+            attributeDefinitionMap.add(layout, newBands);
         }
         attributeDefinitionMap.checkMap();
     }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeLayout.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeLayout.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeLayout.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeLayout.java Tue Jan  8 02:55:24 2008
@@ -98,28 +98,46 @@
 	private long mask;
     
     private String name;
+    private boolean isDefault;
+    private int backwardsCallCount;
+    
 
+    /**
+     * Construct a default AttributeLayout
+     *  (equivalent to <code>new AttributeLayout(name, context, layout, index, true);</code>)
+     * @param name
+     * @param context
+     * @param layout
+     * @param index
+     * @throws Pack200Exception
+     */
 	public AttributeLayout(String name, int context, String layout, int index)
 			throws Pack200Exception {
-		super();
+		this(name, context, layout, index, true);
+	}
+    
+    public AttributeLayout(String name, int context, String layout, int index,
+            boolean isDefault) throws Pack200Exception {
+        super();
         this.index = index;
         this.context = context;
-		if (index >= 0) {
-			this.mask = 1L << index;
-		} else {
-			this.mask = 0;
-		}
+        if (index >= 0) {
+            this.mask = 1L << index;
+        } else {
+            this.mask = 0;
+        }
         if (context != CONTEXT_CLASS && context != CONTEXT_CODE
                 && context != CONTEXT_FIELD && context != CONTEXT_METHOD)
             throw new Pack200Exception("Attribute context out of range: "
                     + context);
-		if (layout == null) // || layout.length() == 0)
-			throw new Pack200Exception("Cannot have a null layout");
+        if (layout == null) // || layout.length() == 0)
+            throw new Pack200Exception("Cannot have a null layout");
         if (name == null || name.length() == 0)
-                throw new Pack200Exception("Cannot have an unnamed layout");
+            throw new Pack200Exception("Cannot have an unnamed layout");
         this.name = name;
-		this.layout = layout;
-	}
+        this.layout = layout;
+        this.isDefault = isDefault;
+    }
     
     
 	public boolean equals(Object obj) {
@@ -243,18 +261,19 @@
     
     public int numBackwardsCallables() {
         if(layout == "*") {
-            return 1; // TODO: complicated attributes (shouldn't be *'s at all...)
-        }
-        int num = 0;
-        String[] split = layout.split("\\(");
-        if(split.length > 0) {
-            for (int i = 1; i < split.length; i++) {
-                if(split[i].startsWith("-") || split[i].startsWith("0")) {
-                    num++;
-                }
-            }
+            return 1;
+        } else {
+            return backwardsCallCount;
         }
-        return num;
+    }
+
+
+    public boolean isDefaultLayout() {
+        return isDefault;
+    }
+
+    public void setBackwardsCallCount(int backwardsCallCount) {
+        this.backwardsCallCount = backwardsCallCount;
     }
 
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeLayoutMap.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeLayoutMap.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeLayoutMap.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeLayoutMap.java Tue Jan  8 02:55:24 2008
@@ -198,6 +198,8 @@
     // the value of their context constants (AttributeLayout.CONTEXT_CLASS etc.)
     private final Map[] layouts = new Map[] {classLayouts, fieldLayouts, methodLayouts, codeLayouts};
 
+    private final Map layoutsToBands = new HashMap();
+    
 	public AttributeLayoutMap() throws Pack200Exception {
 		AttributeLayout[] defaultAttributeLayouts = getDefaultAttributeLayouts();
 		for (int i = 0; i < defaultAttributeLayouts.length; i++) {
@@ -208,6 +210,13 @@
 	public void add(AttributeLayout layout) {
         layouts[layout.getContext()].put(new Integer(layout.getIndex()), layout);
 	}
+    
+
+
+    public void add(AttributeLayout layout, NewAttributeBands newBands) {
+        add(layout);
+        layoutsToBands.put(layout, newBands);
+    }
 
 	public AttributeLayout getAttributeLayout(String name, int context)
 			throws Pack200Exception {
@@ -257,6 +266,10 @@
                 }
             }
         }
+    }
+
+    public NewAttributeBands getAttributeBands(AttributeLayout layout) {
+        return (NewAttributeBands) layoutsToBands.get(layout);
     }
     
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java Tue Jan  8 02:55:24 2008
@@ -19,20 +19,24 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 
+import org.apache.harmony.pack200.bytecode.CPClass;
 import org.apache.harmony.pack200.bytecode.CPDouble;
+import org.apache.harmony.pack200.bytecode.CPFieldRef;
 import org.apache.harmony.pack200.bytecode.CPFloat;
 import org.apache.harmony.pack200.bytecode.CPInteger;
+import org.apache.harmony.pack200.bytecode.CPInterfaceMethodRef;
 import org.apache.harmony.pack200.bytecode.CPLong;
+import org.apache.harmony.pack200.bytecode.CPMethodRef;
+import org.apache.harmony.pack200.bytecode.CPNameAndType;
+import org.apache.harmony.pack200.bytecode.CPString;
 import org.apache.harmony.pack200.bytecode.CPUTF8;
+import org.apache.harmony.pack200.bytecode.ClassConstantPool;
 
 public abstract class BandSet {
     
     public abstract void unpack(InputStream inputStream) throws IOException, Pack200Exception;
     
-    public abstract void pack(OutputStream outputStream);
-    
     protected Segment segment;
     
     protected SegmentHeader header;
@@ -451,7 +455,7 @@
             if (index < 0 || index >= reference.length)
                 throw new Pack200Exception(
                         "Something has gone wrong during parsing references, index = " + index + ", array size = " + reference.length);
-            result[i1] = new CPUTF8(reference[index]);
+            result[i1] = new CPUTF8(reference[index], ClassConstantPool.DOMAIN_UNDEFINED);
         }
         return result;
     }
@@ -472,7 +476,7 @@
             if (index < 0 || index >= reference.length)
                 throw new Pack200Exception(
                         "Something has gone wrong during parsing references, index = " + index + ", array size = " + reference.length);
-            result1[i1] = new CPUTF8(reference[index]);
+            result1[i1] = new CPUTF8(reference[index], ClassConstantPool.DOMAIN_UNDEFINED);
         }
         CPUTF8[] refs = result1;
         int pos = 0;
@@ -481,6 +485,107 @@
             result[i] = new CPUTF8[num];
             System.arraycopy(refs, pos, result[i], 0, num);
             pos += num;
+        }
+        return result;
+    }
+
+    public CPString[] parseCPStringReferences(String name, InputStream in, BHSDCodec codec, int count) throws IOException, Pack200Exception {
+        String[] reference = segment.getCpBands().getCpString();        
+        int[] indices = decodeBandInt(name, in, codec, count, reference.length - 1);
+        CPString[] result = new CPString[indices.length];
+        for (int i1 = 0; i1 < count; i1++) {
+            int index = indices[i1];
+            if (index < 0 || index >= reference.length)
+                throw new Pack200Exception(
+                        "Something has gone wrong during parsing references, index = " + index + ", array size = " + reference.length);
+            result[i1] = new CPString(reference[index]);
+        }
+        return result;
+    }
+
+    public CPInterfaceMethodRef[] parseCPInterfaceMethodRefReferences(String name, InputStream in, BHSDCodec codec, int count) throws IOException, Pack200Exception {
+        String[] reference = segment.getCpBands().getCpIMethodClass();
+        String[] descriptors = segment.getCpBands().getCpIMethodDescriptor();
+        int[] indices = decodeBandInt(name, in, codec, count, reference.length - 1);
+        CPInterfaceMethodRef[] result = new CPInterfaceMethodRef[indices.length];
+        for (int i1 = 0; i1 < count; i1++) {
+            int index = indices[i1];
+            if (index < 0 || index >= reference.length)
+                throw new Pack200Exception(
+                        "Something has gone wrong during parsing references, index = " + index + ", array size = " + reference.length);
+            result[i1] = new CPInterfaceMethodRef(reference[index], descriptors[index]);
+        }
+        return result;
+    }
+
+    public CPMethodRef[] parseCPMethodRefReferences(String name, InputStream in, BHSDCodec codec, int count) throws IOException, Pack200Exception {
+        String[] reference = segment.getCpBands().getCpMethodClass();        
+        String[] descriptors = segment.getCpBands().getCpMethodDescriptor();
+        int[] indices = decodeBandInt(name, in, codec, count, reference.length - 1);
+        CPMethodRef[] result = new CPMethodRef[indices.length];
+        for (int i1 = 0; i1 < count; i1++) {
+            int index = indices[i1];
+            if (index < 0 || index >= reference.length)
+                throw new Pack200Exception(
+                        "Something has gone wrong during parsing references, index = " + index + ", array size = " + reference.length);
+            result[i1] = new CPMethodRef(reference[index], descriptors[index]);
+        }
+        return result;
+    }
+
+    public CPFieldRef[] parseCPFieldRefReferences(String name, InputStream in, BHSDCodec codec, int count) throws IOException, Pack200Exception {
+        String[] reference = segment.getCpBands().getCpFieldClass();        
+        String[] descriptors = segment.getCpBands().getCpFieldDescriptor();
+        int[] indices = decodeBandInt(name, in, codec, count, reference.length - 1);
+        CPFieldRef[] result = new CPFieldRef[indices.length];
+        for (int i1 = 0; i1 < count; i1++) {
+            int index = indices[i1];
+            if (index < 0 || index >= reference.length)
+                throw new Pack200Exception(
+                        "Something has gone wrong during parsing references, index = " + index + ", array size = " + reference.length);
+            result[i1] = new CPFieldRef(reference[index], descriptors[index]);
+        }
+        return result;
+    }
+
+    public CPNameAndType[] parseCPDescriptorReferences(String name, InputStream in, BHSDCodec codec, int count) throws IOException, Pack200Exception {
+        String[] reference = segment.getCpBands().getCpDescriptor();        
+        int[] indices = decodeBandInt(name, in, codec, count, reference.length - 1);
+        CPNameAndType[] result = new CPNameAndType[indices.length];
+        for (int i1 = 0; i1 < count; i1++) {
+            int index = indices[i1];
+            if (index < 0 || index >= reference.length)
+                throw new Pack200Exception(
+                        "Something has gone wrong during parsing references, index = " + index + ", array size = " + reference.length);
+            result[i1] = new CPNameAndType(reference[index]);
+        }
+        return result;
+    }
+
+    public CPUTF8[] parseCPSignatureReferences(String name, InputStream in, BHSDCodec codec, int count) throws IOException, Pack200Exception {
+        String[] reference = segment.getCpBands().getCpSignature();        
+        int[] indices = decodeBandInt(name, in, codec, count, reference.length - 1);
+        CPUTF8[] result = new CPUTF8[indices.length];
+        for (int i1 = 0; i1 < count; i1++) {
+            int index = indices[i1];
+            if (index < 0 || index >= reference.length)
+                throw new Pack200Exception(
+                        "Something has gone wrong during parsing references, index = " + index + ", array size = " + reference.length);
+            result[i1] = new CPUTF8(reference[index], ClassConstantPool.DOMAIN_UNDEFINED);
+        }
+        return result;
+    }
+
+    public CPClass[] parseCPClassReferences(String name, InputStream in, BHSDCodec codec, int count) throws IOException, Pack200Exception {
+        String[] reference = segment.getCpBands().getCpClass();        
+        int[] indices = decodeBandInt(name, in, codec, count, reference.length - 1);
+        CPClass[] result = new CPClass[indices.length];
+        for (int i1 = 0; i1 < count; i1++) {
+            int index = indices[i1];
+            if (index < 0 || index >= reference.length)
+                throw new Pack200Exception(
+                        "Something has gone wrong during parsing references, index = " + index + ", array size = " + reference.length);
+            result[i1] = new CPClass(reference[index]);
         }
         return result;
     }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java Tue Jan  8 02:55:24 2008
@@ -19,14 +19,13 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.harmony.pack200.bytecode.Attribute;
 import org.apache.harmony.pack200.bytecode.BCIRenumberedAttribute;
 import org.apache.harmony.pack200.bytecode.ByteCode;
 import org.apache.harmony.pack200.bytecode.CodeAttribute;
-import org.apache.harmony.pack200.bytecode.LineNumberTableAttribute;
 import org.apache.harmony.pack200.bytecode.OperandManager;
 
 /**
@@ -40,7 +39,7 @@
     // The bands
     // TODO:  Haven't resolved references yet.  Do we want to?
     private int[] bcCaseCount;
-    private int[][] bcCaseValue;
+    private int[] bcCaseValue;
     private int[] bcByte;
     private int[] bcLocal;
     private int[] bcShort;
@@ -72,14 +71,6 @@
     }
 
     /* (non-Javadoc)
-     * @see org.apache.harmony.pack200.BandSet#pack(java.io.OutputStream)
-     */
-    public void pack(OutputStream outputStream) {
-        // TODO Auto-generated method stub
-
-    }
-
-    /* (non-Javadoc)
      * @see org.apache.harmony.pack200.BandSet#unpack(java.io.InputStream)
      */
     public void unpack(InputStream in) throws IOException,
@@ -126,6 +117,9 @@
                        AttributeLayout.CONTEXT_METHOD);
        methodByteCodePacked = new byte[classCount][][];
        int bcParsed = 0;
+       
+       List switchIsTableSwitch = new ArrayList();
+       List wideByteCodes = new ArrayList();
        for (int c = 0; c < classCount; c++) {
            int numberOfMethods = methodFlags[c].length;
            methodByteCodePacked[c] = new byte[numberOfMethods][];
@@ -200,7 +194,12 @@
                            bcLabelCount++;
                            break;
                        case 170: // tableswitch
+                           switchIsTableSwitch.add(new Boolean(true));
+                           bcCaseCountCount++;
+                           bcLabelCount++;
+                           break;
                        case 171: // lookupswitch
+                           switchIsTableSwitch.add(new Boolean(false));
                            bcCaseCountCount++;
                            bcLabelCount++;
                            break;
@@ -260,6 +259,7 @@
                            break;
                        case 196: // wide
                             int nextInstruction = 0xff & methodByteCodePacked[c][m][i+1];
+                            wideByteCodes.add(new Integer(nextInstruction));
                             if (nextInstruction == 132) { // iinc
                                 bcLocalCount += 2;
                                 bcShortCount++;
@@ -299,7 +299,22 @@
         // other bytecode bands
         debug("Parsed *bc_codes (" + bcParsed + ")");
         bcCaseCount = decodeBandInt("bc_case_count", in, Codec.UNSIGNED5, bcCaseCountCount);
-        bcCaseValue = decodeBandInt("bc_case_value", in, Codec.DELTA5, bcCaseCount);
+        int bcCaseValueCount = 0;
+        for (int i = 0; i < bcCaseCount.length; i++) {
+            boolean isTableSwitch = ((Boolean)switchIsTableSwitch.get(i)).booleanValue();
+            if(isTableSwitch) {
+                bcCaseValueCount += 1;
+            } else {
+                bcCaseValueCount += bcCaseCount[i];
+            }
+        }
+        bcCaseValue = decodeBandInt("bc_case_value", in, Codec.DELTA5, bcCaseValueCount );
+        // Every case value needs a label. We weren't able to count these
+        // above, because we didn't know how many cases there were.
+        // Have to correct it now.
+        for(int index=0; index < bcCaseCountCount; index++) {
+            bcLabelCount += bcCaseCount[index];
+        }
         bcByte = decodeBandInt("bc_byte", in, Codec.BYTE1, bcByteCount);
         bcShort = decodeBandInt("bc_short", in, Codec.DELTA5, bcShortCount);
         bcLocal = decodeBandInt("bc_local", in, Codec.UNSIGNED5, bcLocalCount);
@@ -337,11 +352,15 @@
         bcEscSize = decodeBandInt("bc_escsize", in, Codec.UNSIGNED5, bcEscCount);
         bcEscByte = decodeBandInt("bc_escbyte", in, Codec.BYTE1, bcEscSize);
 
-        OperandManager operandManager = new OperandManager(bcByte, bcShort,
-                bcLocal, bcLabel, bcIntRef, bcFloatRef, bcLongRef, bcDoubleRef,
-                bcStringRef, bcClassRef, bcFieldRef, bcMethodRef, bcIMethodRef,
-                bcThisField, bcSuperField, bcThisMethod, bcSuperMethod,
-                bcInitRef);
+        int[] wideByteCodeArray = new int[wideByteCodes.size()];
+        for(int index=0; index < wideByteCodeArray.length; index++) {
+            wideByteCodeArray[index] = ((Integer)wideByteCodes.get(index)).intValue();
+        }
+        OperandManager operandManager = new OperandManager(bcCaseCount, bcCaseValue,
+                bcByte, bcShort, bcLocal, bcLabel, bcIntRef, bcFloatRef, bcLongRef,
+                bcDoubleRef, bcStringRef, bcClassRef, bcFieldRef, bcMethodRef,
+                bcIMethodRef, bcThisField, bcSuperField, bcThisMethod, bcSuperMethod,
+                bcInitRef, wideByteCodeArray);
         operandManager.setSegment(segment);
 
         int i = 0;
@@ -357,26 +376,19 @@
                    if (!staticModifier.matches(methodFlag))
                        maxLocal++; // one for 'this' parameter
                    maxLocal += SegmentUtils.countArgs(methodDescr[c][m]);
-                   // TODO Move creation of code attribute until after constant
-                   // pool resolved
                    operandManager.setCurrentClass(segment.getClassBands().getClassThis()[c]);
                    operandManager.setSuperClass(segment.getClassBands().getClassSuper()[c]);
-                   CodeAttribute attr = new CodeAttribute(maxStack, maxLocal,
+                   CodeAttribute codeAttr = new CodeAttribute(maxStack, maxLocal,
                            methodByteCodePacked[c][m], segment, operandManager);
-                   methodAttributes[c][m].add(attr);
+                   methodAttributes[c][m].add(codeAttr);
                    // Should I add all the attributes in here?
                  ArrayList currentAttributes = (ArrayList)orderedCodeAttributes.get(i);
                  for(int index=0;index < currentAttributes.size(); index++) {
                      Attribute currentAttribute = (Attribute)currentAttributes.get(index);
-                     // TODO: The line below adds the LocalVariableTable
-                     // and LineNumber attributes. Currently things are
-                     // broken because these tables don't get renumbered
-                     // properly. Commenting out the add so the class files
-                     // will verify.
-                     //attr.attributes.add(currentAttribute);
+                     codeAttr.addAttribute(currentAttribute);
                      // Fix up the line numbers if needed
                      if(currentAttribute.hasBCIRenumbering()) {
-                         ((BCIRenumberedAttribute)currentAttribute).renumber(attr.byteCodeOffsets);
+                         ((BCIRenumberedAttribute)currentAttribute).renumber(codeAttr.byteCodeOffsets);
                      }
                  }
                  i++;
@@ -407,7 +419,7 @@
         return bcCaseCount;
     }
 
-    public int[][] getBcCaseValue() {
+    public int[] getBcCaseValue() {
         return bcCaseValue;
     }
 

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java Tue Jan  8 02:55:24 2008
@@ -18,15 +18,18 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
 
 import org.apache.harmony.pack200.IcBands.ICTuple;
 import org.apache.harmony.pack200.bytecode.Attribute;
 import org.apache.harmony.pack200.bytecode.CPClass;
+import org.apache.harmony.pack200.bytecode.CPNameAndType;
 import org.apache.harmony.pack200.bytecode.CPUTF8;
+import org.apache.harmony.pack200.bytecode.ClassConstantPool;
 import org.apache.harmony.pack200.bytecode.ConstantValueAttribute;
+import org.apache.harmony.pack200.bytecode.EnclosingMethodAttribute;
 import org.apache.harmony.pack200.bytecode.ExceptionsAttribute;
 import org.apache.harmony.pack200.bytecode.LineNumberTableAttribute;
 import org.apache.harmony.pack200.bytecode.LocalVariableTableAttribute;
@@ -35,7 +38,7 @@
 import org.apache.harmony.pack200.bytecode.SourceFileAttribute;
 
 /**
- * 
+ * Pack200 Class Bands
  */
 public class ClassBands extends BandSet {
 
@@ -105,16 +108,6 @@
     /*
      * (non-Javadoc)
      * 
-     * @see org.apache.harmony.pack200.BandSet#pack(java.io.OutputStream)
-     */
-    public void pack(OutputStream outputStream) {
-        // TODO Auto-generated method stub
-
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
      * @see org.apache.harmony.pack200.BandSet#unpack(java.io.InputStream)
      */
     public void unpack(InputStream in) throws IOException, Pack200Exception {
@@ -142,6 +135,10 @@
             Pack200Exception {
         fieldDescr = parseReferences("field_descr", in, Codec.DELTA5,
                 classFieldCount, cpBands.getCpDescriptor());
+        parseFieldAttrBands(in);
+    }
+
+    private void parseFieldAttrBands(InputStream in) throws IOException, Pack200Exception {
         fieldFlags = parseFlags("field_flags", in, classFieldCount,
                 Codec.UNSIGNED5, options.hasFieldFlagsHi());
         int fieldAttrCount = SegmentUtils.countBit16(fieldFlags);
@@ -153,6 +150,15 @@
                 AttributeLayout.CONTEXT_FIELD);
         int[] fieldAttrCalls = decodeBandInt("field_attr_calls", in,
                 Codec.UNSIGNED5, callCount);
+        
+        // Assign empty field attributes
+        fieldAttributes = new ArrayList[classCount][];
+        for (int i = 0; i < classCount; i++) {
+            fieldAttributes[i] = new ArrayList[fieldFlags[i].length];
+            for (int j = 0; j < fieldFlags[i].length; j++) {
+                fieldAttributes[i][j] = new ArrayList();
+            }
+        }
 
         AttributeLayout constantValueLayout = attrMap.getAttributeLayout(
                 "ConstantValue", AttributeLayout.CONTEXT_FIELD);
@@ -171,11 +177,38 @@
                 Codec.UNSIGNED5, signatureCount);
         int signatureIndex = 0;
 
-        fieldAttributes = new ArrayList[classCount][];
+        int backwardsCallsUsed = parseFieldMetadataBands(in, fieldAttrCalls);
+        
+        // Parse non-predefined attribute bands
+        int backwardsCallIndex = backwardsCallsUsed;
+        int limit = options.hasFieldFlagsHi() ? 62 : 31;
+        AttributeLayout[] otherLayouts = new AttributeLayout[limit + 1];
+        int[] counts = new int[limit + 1];
+        List[] otherAttributes = new List[limit + 1];
+        for (int i = 0; i < limit; i++) {
+            AttributeLayout layout = attrMap.getAttributeLayout(i, AttributeLayout.CONTEXT_FIELD);
+            if(layout != null && !(layout.isDefaultLayout())) {
+                otherLayouts[i] = layout;
+                counts[i] = SegmentUtils.countMatches(fieldFlags,
+                        layout);
+            }
+        }
+        for (int i = 0; i < counts.length; i++) {
+            if(counts[i] > 0) {
+                NewAttributeBands bands = attrMap.getAttributeBands(otherLayouts[i]);                
+                otherAttributes[i] = bands.parseAttributes(in, counts[i]);
+                int numBackwardsCallables = otherLayouts[i].numBackwardsCallables();
+                if(numBackwardsCallables > 0) {
+                    int[] backwardsCalls = new int[numBackwardsCallables];
+                    System.arraycopy(fieldAttrCalls, backwardsCallIndex, backwardsCalls, 0, numBackwardsCallables);
+                    bands.setBackwardsCalls(backwardsCalls);
+                    backwardsCallIndex+= numBackwardsCallables;
+                }
+            }
+        }
+
         for (int i = 0; i < classCount; i++) {
-            fieldAttributes[i] = new ArrayList[fieldFlags[i].length];
             for (int j = 0; j < fieldFlags[i].length; j++) {
-                fieldAttributes[i][j] = new ArrayList();
                 long flag = fieldFlags[i][j];
                 if (constantValueLayout.matches(flag)) {
                     // we've got a value to read
@@ -199,25 +232,33 @@
                     int colon = desc.indexOf(':');
                     String type = desc.substring(colon + 1);
                     CPUTF8 value = new CPUTF8((String) signatureLayout.getValue(result, type,
-                            cpBands.getConstantPool()));
+                            cpBands.getConstantPool()), ClassConstantPool.DOMAIN_SIGNATUREASCIIZ);
                     fieldAttributes[i][j]
                             .add(new SignatureAttribute(value));
                     signatureIndex++;
                 }
+                // Non-predefined attributes
+                for (int k = 0; k < otherLayouts.length; k++) {
+                    if(otherLayouts[k] != null && otherLayouts[k].matches(flag)) {
+                        // Add the next attribute
+                        fieldAttributes[i][j].add(otherAttributes[k].get(0));
+                        otherAttributes[k].remove(0);
+                    }
+                }
             }
         }
-        parseFieldMetadataBands(in, fieldAttrCalls);
-
-        // TODO: Parse other attribute bands
     }
 
     private void parseMethodBands(InputStream in) throws IOException,
             Pack200Exception {
         methodDescr = parseReferences("method_descr", in, Codec.MDELTA5,
-                classMethodCount, cpBands.getCpDescriptor());
+                classMethodCount, cpBands.getCpDescriptor());        
+        parseMethodAttrBands(in);
+    }
+
+    private void parseMethodAttrBands(InputStream in) throws IOException, Pack200Exception {
         methodFlags = parseFlags("method_flags", in, classMethodCount,
                 Codec.UNSIGNED5, options.hasMethodFlagsHi());
-
         int methodAttrCount = SegmentUtils.countBit16(methodFlags);
         int[] methodAttrCounts = decodeBandInt("method_attr_count", in,
                 Codec.UNSIGNED5, methodAttrCount);
@@ -227,7 +268,7 @@
                 AttributeLayout.CONTEXT_METHOD);
         methodAttrCalls = decodeBandInt("code_attr_calls", in, Codec.UNSIGNED5,
                 callCount);
-
+        
         // assign empty method attributes
         methodAttributes = new ArrayList[classCount][];
         for (int i = 0; i < classCount; i++) {
@@ -236,11 +277,98 @@
                 methodAttributes[i][j] = new ArrayList();
             }
         }
-        parseAttributeMethodExceptions(in);
-        parseAttributeMethodSigntaure(in);
-        parseMethodMetadataBands(in, methodAttrCalls);
 
-        // TODO: Parse other attribute bands
+        // Parse method exceptions attributes
+        AttributeLayout methodExceptionsLayout = attrMap.getAttributeLayout(AttributeLayout.ATTRIBUTE_EXCEPTIONS,
+                AttributeLayout.CONTEXT_METHOD);
+        int count = SegmentUtils.countMatches(methodFlags, methodExceptionsLayout);
+        int[] numExceptions = decodeBandInt("method_Exceptions_n", in,
+                Codec.UNSIGNED5, count);
+        String[][] methodExceptionsRS = parseReferences("method_Exceptions_RC",
+                in, Codec.UNSIGNED5, numExceptions, cpBands.getCpClass());
+        
+        // Parse method signature attributes
+        AttributeLayout methodSignatureLayout = attrMap.getAttributeLayout(
+                AttributeLayout.ATTRIBUTE_SIGNATURE,
+                AttributeLayout.CONTEXT_METHOD);
+        int count1 = SegmentUtils.countMatches(methodFlags, methodSignatureLayout);
+        long[] methodSignatureRS = decodeBandLong("method_signature_RS", in,
+                Codec.UNSIGNED5, count1);
+        
+        // Parse method metadata bands
+        int backwardsCallsUsed = parseMethodMetadataBands(in, methodAttrCalls);        
+        
+        // Parse non-predefined attribute bands
+        int backwardsCallIndex = backwardsCallsUsed;
+        int limit = options.hasMethodFlagsHi() ? 62 : 31;
+        AttributeLayout[] otherLayouts = new AttributeLayout[limit + 1];
+        int[] counts = new int[limit + 1];
+        List[] otherAttributes = new List[limit + 1];
+        for (int i = 0; i < limit; i++) {
+            AttributeLayout layout = attrMap.getAttributeLayout(i, AttributeLayout.CONTEXT_METHOD);
+            if(layout != null && !(layout.isDefaultLayout())) {
+                otherLayouts[i] = layout;
+                counts[i] = SegmentUtils.countMatches(methodFlags,
+                        layout);
+            }
+        }
+        for (int i = 0; i < counts.length; i++) {
+            if(counts[i] > 0) {
+                NewAttributeBands bands = attrMap.getAttributeBands(otherLayouts[i]);                
+                otherAttributes[i] = bands.parseAttributes(in, counts[i]);
+                int numBackwardsCallables = otherLayouts[i].numBackwardsCallables();
+                if(numBackwardsCallables > 0) {
+                    int[] backwardsCalls = new int[numBackwardsCallables];
+                    System.arraycopy(methodAttrCalls, backwardsCallIndex, backwardsCalls, 0, numBackwardsCallables);
+                    bands.setBackwardsCalls(backwardsCalls);
+                    backwardsCallIndex+= numBackwardsCallables;
+                }
+            }
+        }
+
+        // Add attributes to the attribute arrays
+        int methodExceptionsIndex = 0;
+        int methodSignatureIndex = 0;
+        for (int i = 0; i < methodAttributes.length; i++) {
+            for (int j = 0; j < methodAttributes[i].length; j++) {
+                long flag = methodFlags[i][j];
+                if (methodExceptionsLayout.matches(flag)) {
+                    int n = numExceptions[methodExceptionsIndex];
+                    String[] exceptions = methodExceptionsRS[methodExceptionsIndex];
+                    CPClass[] exceptionClasses = new CPClass[n];
+                    for (int k = 0; k < n; k++) {
+                        exceptionClasses[k] = new CPClass(exceptions[k]);
+                    }
+                    methodAttributes[i][j].add(new ExceptionsAttribute(
+                            exceptionClasses));
+                    methodExceptionsIndex++;
+                }
+                if (methodSignatureLayout.matches(flag)) {
+                    // We've got a signature attribute
+                    long result = methodSignatureRS[methodSignatureIndex];
+                    String desc = methodDescr[i][j];
+                    int colon = desc.indexOf(':');
+                    String type = desc.substring(colon + 1);
+                    // TODO Got to get better at this ... in any case, it should
+                    // be e.g. KIB or KIH
+                    if (type.equals("B") || type.equals("H"))
+                        type = "I";
+                    Object value = methodSignatureLayout.getValue(result, type, cpBands
+                            .getConstantPool());
+                    methodAttributes[i][j]
+                            .add(new ConstantValueAttribute(value));
+                    methodSignatureIndex++;
+                }
+                // Non-predefined attributes
+                for (int k = 0; k < otherLayouts.length; k++) {
+                    if(otherLayouts[k] != null && otherLayouts[k].matches(flag)) {
+                        // Add the next attribute
+                        methodAttributes[i][j].add(otherAttributes[k].get(0));
+                        otherAttributes[k].remove(0);
+                    }
+                }
+            }
+        }
     }
 
     private int getCallCount(int[][] methodAttrIndexes, long[][] flags,
@@ -269,71 +397,6 @@
         return callCount;
     }
 
-    private void parseAttributeMethodSigntaure(InputStream in)
-            throws IOException, Pack200Exception {
-        AttributeLayout layout = attrMap.getAttributeLayout(
-                AttributeLayout.ATTRIBUTE_SIGNATURE,
-                AttributeLayout.CONTEXT_METHOD);
-        int count = SegmentUtils.countMatches(methodFlags, layout);
-        long[] methodSignatureRS = decodeBandLong("method_signature_RS", in,
-                Codec.UNSIGNED5, count);
-        int index = 0;
-        for (int i = 0; i < methodAttributes.length; i++) {
-            for (int j = 0; j < methodAttributes[i].length; j++) {
-                long flag = methodFlags[i][j];
-                if (layout.matches(flag)) {
-                    // we've got a signature attribute
-                    long result = methodSignatureRS[index];
-                    String desc = methodDescr[i][j];
-                    int colon = desc.indexOf(':');
-                    String type = desc.substring(colon + 1);
-                    // TODO Got to get better at this ... in any case, it should
-                    // be e.g. KIB or KIH
-                    if (type.equals("B") || type.equals("H"))
-                        type = "I";
-                    Object value = layout.getValue(result, type, cpBands
-                            .getConstantPool());
-                    methodAttributes[i][j]
-                            .add(new ConstantValueAttribute(value));
-                    index++;
-                }
-            }
-        }
-    }
-
-    /**
-     * @param in
-     * @throws Pack200Exception
-     * @throws IOException
-     */
-    private void parseAttributeMethodExceptions(InputStream in)
-            throws Pack200Exception, IOException {
-        AttributeLayout layout = attrMap.getAttributeLayout("Exceptions",
-                AttributeLayout.CONTEXT_METHOD);
-        int count = SegmentUtils.countMatches(methodFlags, layout);
-        int[] numExceptions = decodeBandInt("method_Exceptions_n", in,
-                Codec.UNSIGNED5, count);
-        String[][] methodExceptionsRS = parseReferences("method_Exceptions_RC",
-                in, Codec.UNSIGNED5, numExceptions, cpBands.getCpClass());
-        int index = 0;
-        for (int i = 0; i < classCount; i++) {
-            for (int j = 0; j < methodFlags[i].length; j++) {
-                long flag = methodFlags[i][j];
-                if (layout.matches(flag)) {
-                    int n = numExceptions[index];
-                    String[] exceptions = methodExceptionsRS[index];
-                    CPClass[] exceptionClasses = new CPClass[n];
-                    for (int k = 0; k < n; k++) {
-                        exceptionClasses[k] = new CPClass(exceptions[k]);
-                    }
-                    methodAttributes[i][j].add(new ExceptionsAttribute(
-                            exceptionClasses));
-                    index++;
-                }
-            }
-        }
-    }
-
     private void parseClassAttrBands(InputStream in) throws IOException,
             Pack200Exception {
         String[] cpUTF8 = cpBands.getCpUTF8();
@@ -370,10 +433,11 @@
                 AttributeLayout.CONTEXT_CLASS);
         int enclosingMethodCount = SegmentUtils.countMatches(classFlags,
                 enclosingMethodLayout);
-        int[] enclosingMethodRC = decodeBandInt("class_EnclosingMethod_RC", in,
-                Codec.UNSIGNED5, enclosingMethodCount);
-        int[] enclosingMethodRDN = decodeBandInt("class_EnclosingMethod_RDN",
-                in, Codec.UNSIGNED5, enclosingMethodCount);
+        String[] enclosingMethodRC = parseReferences(
+                "class_EnclosingMethod_RC", in, Codec.UNSIGNED5,
+                enclosingMethodCount, cpClass);
+        String[] enclosingMethodRDN = parseReferences(
+                "class_EnclosingMethod_RDN", in, Codec.UNSIGNED5, enclosingMethodCount, cpBands.getCpDescriptor());
 
         AttributeLayout signatureLayout = attrMap.getAttributeLayout(
                 AttributeLayout.ATTRIBUTE_SIGNATURE,
@@ -383,7 +447,7 @@
         int[] classSignature = decodeBandInt("class_Signature_RS", in,
                 Codec.UNSIGNED5, signatureCount);
 
-        parseClassMetadataBands(in, classAttrCalls);
+        int backwardsCallsUsed = parseClassMetadataBands(in, classAttrCalls);
 
         AttributeLayout innerClassLayout = attrMap.getAttributeLayout(
                 AttributeLayout.ATTRIBUTE_INNER_CLASSES,
@@ -424,7 +488,34 @@
         int defaultVersionMajor = header.getDefaultClassMajorVersion();
         int defaultVersionMinor = header.getDefaultClassMinorVersion();
 
-        // TODO: Parse other attribute bands
+
+        // Parse non-predefined attribute bands
+        int backwardsCallIndex = backwardsCallsUsed;
+        int limit = options.hasClassFlagsHi() ? 62 : 31;
+        AttributeLayout[] otherLayouts = new AttributeLayout[limit + 1];
+        int[] counts = new int[limit + 1];
+        List[] otherAttributes = new List[limit + 1];
+        for (int i = 0; i < limit; i++) {
+            AttributeLayout layout = attrMap.getAttributeLayout(i, AttributeLayout.CONTEXT_CLASS);
+            if(layout != null && !(layout.isDefaultLayout())) {
+                otherLayouts[i] = layout;
+                counts[i] = SegmentUtils.countMatches(classFlags,
+                        layout);
+            }
+        }
+        for (int i = 0; i < counts.length; i++) {
+            if(counts[i] > 0) {
+                NewAttributeBands bands = attrMap.getAttributeBands(otherLayouts[i]);                
+                otherAttributes[i] = bands.parseAttributes(in, counts[i]);
+                int numBackwardsCallables = otherLayouts[i].numBackwardsCallables();
+                if(numBackwardsCallables > 0) {
+                    int[] backwardsCalls = new int[numBackwardsCallables];
+                    System.arraycopy(classAttrCalls, backwardsCallIndex, backwardsCalls, 0, numBackwardsCallables);
+                    bands.setBackwardsCalls(backwardsCalls);
+                    backwardsCallIndex+= numBackwardsCallables;
+                }
+            }
+        }
 
         // Now process the attribute bands we have parsed
         int sourceFileIndex = 0;
@@ -467,7 +558,10 @@
                 sourceFileIndex++;
             }
             if (enclosingMethodLayout.matches(flag)) {
-                // long result =
+                CPClass theClass = new CPClass(enclosingMethodRC[enclosingMethodIndex]);
+                CPNameAndType theMethod = new CPNameAndType(enclosingMethodRDN[enclosingMethodIndex]);
+                classAttributes[i].add(new EnclosingMethodAttribute(theClass, theMethod));
+                enclosingMethodIndex++;
             }
             if (signatureLayout.matches(flag)) {
                 long result = classSignature[signatureIndex];
@@ -513,6 +607,14 @@
                 classVersionMajor[i] = defaultVersionMajor;
                 classVersionMinor[i] = defaultVersionMinor;
             }
+            // Non-predefined attributes
+            for (int j = 0; j < otherLayouts.length; j++) {
+                if(otherLayouts[j] != null && otherLayouts[j].matches(flag)) {
+                    // Add the next attribute
+                    classAttributes[i].add(otherAttributes[j].get(0));
+                    otherAttributes[j].remove(0);
+                }
+            }
         }
     }
 
@@ -651,6 +753,22 @@
                 "code_LocalVariableTable_slot", in, Codec.UNSIGNED5,
                 localVariableTableN);
 
+        // Fix up localVariableTableTypeRS - for some reason,
+        // native signatures end up in DOMAINNORMALASCIIZ
+        // while nonnatives end up in DOMAINSIGNATUREASCIIZ.
+        // TODO: is this the right thing to do?
+        for(int x=0; x < localVariableTableTypeRS.length; x++) {
+            for(int y=0; y < localVariableTableTypeRS[x].length; y++) {
+                CPUTF8 element = localVariableTableTypeRS[x][y];
+                // TODO: come up with a better test for native vs nonnative signatures?
+                if(element.underlyingString().length() > 2) {
+                    element.setDomain(ClassConstantPool.DOMAIN_SIGNATUREASCIIZ);
+                } else {
+                    element.setDomain(ClassConstantPool.DOMAIN_NORMALASCIIZ);
+                }
+            }
+        }
+        
         int lengthLocalVariableTypeTableNBand = SegmentUtils.countMatches(
                 codeFlags, localVariableTypeTableLayout);
         int[] localVariableTypeTableN = decodeBandInt(
@@ -672,6 +790,34 @@
                 "code_LocalVariableTypeTable_slot", in, Codec.UNSIGNED5,
                 localVariableTypeTableN);
 
+        // Parse non-predefined attribute bands
+        int backwardsCallIndex = 0;
+        int limit = options.hasCodeFlagsHi() ? 62 : 31;
+        AttributeLayout[] otherLayouts = new AttributeLayout[limit + 1];
+        int[] counts = new int[limit + 1];
+        List[] otherAttributes = new List[limit + 1];
+        for (int i = 0; i < limit; i++) {
+            AttributeLayout layout = attrMap.getAttributeLayout(i, AttributeLayout.CONTEXT_CODE);
+            if(layout != null && !(layout.isDefaultLayout())) {
+                otherLayouts[i] = layout;
+                counts[i] = SegmentUtils.countMatches(codeFlags,
+                        layout);
+            }
+        }
+        for (int i = 0; i < counts.length; i++) {
+            if(counts[i] > 0) {
+                NewAttributeBands bands = attrMap.getAttributeBands(otherLayouts[i]);                
+                otherAttributes[i] = bands.parseAttributes(in, counts[i]);
+                int numBackwardsCallables = otherLayouts[i].numBackwardsCallables();
+                if(numBackwardsCallables > 0) {
+                    int[] backwardsCalls = new int[numBackwardsCallables];
+                    System.arraycopy(codeAttrCalls, backwardsCallIndex, backwardsCalls, 0, numBackwardsCallables);
+                    bands.setBackwardsCalls(backwardsCalls);
+                    backwardsCallIndex+= numBackwardsCallables;
+                }
+            }
+        }     
+
         int lineNumberIndex = 0;
         int lvtIndex = 0;
         int lvttIndex = 0;
@@ -706,8 +852,16 @@
                 lvttIndex++;
                 codeAttributes[i].add(lvtta);
             }
+            // Non-predefined attributes
+            for (int j = 0; j < otherLayouts.length; j++) {
+                if(otherLayouts[j] != null && otherLayouts[j].matches(codeFlags[i])) {
+                    // Add the next attribute
+                    codeAttributes[i].add(otherAttributes[j].get(0));
+                    otherAttributes[j].remove(0);
+                }
+            }
         }
-        // TODO: Parse other attribute bands
+        
     }
 
     private CPUTF8[][] stringsToCPUTF8(String[][] strings) {
@@ -715,7 +869,7 @@
         for (int i = 0; i < strings.length; i++) {
             cpUTF8s[i] = new CPUTF8[strings[i].length];
             for (int j = 0; j < strings[i].length; j++) {
-                cpUTF8s[i][j] = new CPUTF8(strings[i][j]);
+                cpUTF8s[i][j] = new CPUTF8(strings[i][j], ClassConstantPool.DOMAIN_NORMALASCIIZ);
             }
         }
         return cpUTF8s;
@@ -726,13 +880,14 @@
     private CPUTF8[] stringsToCPUTF8(String[] strings) {
         CPUTF8[] cpUTF8s = new CPUTF8[strings.length];
         for (int i = 0; i < strings.length; i++) {
-            cpUTF8s[i] = new CPUTF8(strings[i]);
+            cpUTF8s[i] = new CPUTF8(strings[i], ClassConstantPool.DOMAIN_UNDEFINED);
         }
         return cpUTF8s;
     }
 
-    private void parseFieldMetadataBands(InputStream in, int[] fieldAttrCalls)
+    private int parseFieldMetadataBands(InputStream in, int[] fieldAttrCalls)
             throws Pack200Exception, IOException {
+        int backwardsCallsUsed = 0;
         String[] RxA = new String[] { "RVA", "RIA" };
 
         AttributeLayout rvaLayout = attrMap.getAttributeLayout(
@@ -748,11 +903,14 @@
         int[] backwardsCalls = new int[] {0, 0};
         if(rvaCount > 0) {
             backwardsCalls[0] = fieldAttrCalls[0];
+            backwardsCallsUsed++;
             if(riaCount > 0) {
                 backwardsCalls[1] = fieldAttrCalls[1];
+                backwardsCallsUsed++;
             }
         } else if (riaCount > 0) {
             backwardsCalls[1] = fieldAttrCalls[0];
+            backwardsCallsUsed++;
         }
         MetadataBandGroup[] mb = parseMetadata(in, RxA, RxACount, backwardsCalls, "field");
         Iterator rvaAttributesIterator = mb[0].getAttributes().iterator();
@@ -767,6 +925,7 @@
                 }
             }
         }
+        return backwardsCallsUsed;
     }
 
     private MetadataBandGroup[] parseMetadata(InputStream in, String[] RxA, int[] RxACount,
@@ -867,14 +1026,16 @@
         return mbg;
     }
 
-    private void parseMethodMetadataBands(InputStream in, int[] methodAttrCalls)
+    private int parseMethodMetadataBands(InputStream in, int[] methodAttrCalls)
             throws Pack200Exception, IOException {
+        int backwardsCallsUsed = 0;
         String[] RxA = new String[] { "RVA", "RIA", "RVPA", "RIPA", "AD" };
         int[] rxaCounts = new int[] { 0, 0, 0, 0, 0 };
         int[] backwardsCalls = new int[5];
         int methodAttrIndex = 0;
         for (int i = 0; i < backwardsCalls.length; i++) {
             if(rxaCounts[i] > 0) {
+                backwardsCallsUsed++;
                 backwardsCalls[i] = methodAttrCalls[methodAttrIndex];
                 methodAttrIndex++;
             } else {
@@ -919,9 +1080,19 @@
                 }
             }
         }
+        return backwardsCallsUsed;
     }
 
-    private void parseClassMetadataBands(InputStream in, int[] classAttrCalls) throws Pack200Exception, IOException {
+    /**
+     * Parse the class metadata bands and return the number of backwards callables
+     * @param in
+     * @param classAttrCalls
+     * @return
+     * @throws Pack200Exception
+     * @throws IOException
+     */
+    private int parseClassMetadataBands(InputStream in, int[] classAttrCalls) throws Pack200Exception, IOException {
+        int numBackwardsCalls = 0;
         String[] RxA = new String[] { "RVA", "RIA" };
 
         AttributeLayout rvaLayout = attrMap.getAttributeLayout(
@@ -935,11 +1106,14 @@
         int[] RxACount = new int[] { rvaCount, riaCount };
         int[] backwardsCalls = new int[] {0, 0};
         if(rvaCount > 0) {
+            numBackwardsCalls++;
             backwardsCalls[0] = classAttrCalls[0];
             if(riaCount > 0) {
+                numBackwardsCalls++;
                 backwardsCalls[1] = classAttrCalls[1];
             }
         } else if (riaCount > 0) {
+            numBackwardsCalls++;
             backwardsCalls[1] = classAttrCalls[0];
         }
         MetadataBandGroup[] mbgs = parseMetadata(in, RxA, RxACount, backwardsCalls, "class");
@@ -953,6 +1127,7 @@
                 classAttributes[i].add(riaAttributesIterator.next());
             }
         }
+        return numBackwardsCalls;
     }
 
     public int[] getClassFieldCount() {

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java Tue Jan  8 02:55:24 2008
@@ -18,7 +18,6 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.util.ArrayList;
 
 public class CpBands extends BandSet {
@@ -78,10 +77,6 @@
         parseCpField(in);
         parseCpMethod(in);
         parseCpIMethod(in);
-    }
-
-    public void pack(OutputStream outputStream) {
-        
     }
     
     /**

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java Tue Jan  8 02:55:24 2008
@@ -18,7 +18,6 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 
 /**
  * Parses the file band headers (not including the actual bits themselves).
@@ -48,14 +47,6 @@
     public FileBands(Segment segment) {
         super(segment);
         this.cpUTF8 = segment.getCpBands().getCpUTF8();
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.harmony.pack200.BandSet#pack(java.io.OutputStream)
-     */
-    public void pack(OutputStream outputStream) {
-        // TODO Auto-generated method stub
-
     }
 
     /* (non-Javadoc)

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java Tue Jan  8 02:55:24 2008
@@ -18,7 +18,6 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 
 /**
  * Pack200 Inner Class Bands
@@ -47,14 +46,6 @@
         super(segment);
         this.cpClass = segment.getCpBands().getCpClass();
         this.cpUTF8 = segment.getCpBands().getCpUTF8();
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.harmony.pack200.BandSet#pack(java.io.OutputStream)
-     */
-    public void pack(OutputStream outputStream) {
-        // TODO Auto-generated method stub
-
     }
 
     /* (non-Javadoc)

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java Tue Jan  8 02:55:24 2008
@@ -28,6 +28,7 @@
 import org.apache.harmony.pack200.bytecode.CPMethodRef;
 import org.apache.harmony.pack200.bytecode.CPString;
 import org.apache.harmony.pack200.bytecode.CPUTF8;
+import org.apache.harmony.pack200.bytecode.ClassConstantPool;
 import org.apache.harmony.pack200.bytecode.ConstantPoolEntry;
 
 public class SegmentConstantPool {
@@ -230,7 +231,7 @@
         } else if (index < 0) {
             throw new Pack200Exception("Cannot have a negative range");
         } else if (cp == UTF_8) {
-            return new CPUTF8(bands.getCpUTF8()[index]);
+            return new CPUTF8(bands.getCpUTF8()[index], ClassConstantPool.DOMAIN_NORMALASCIIZ);
         } else if (cp == CP_INT) {
             return new CPInteger(new Integer(bands.getCpInt()[index]));
         } else if (cp == CP_FLOAT) {

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentUtils.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentUtils.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentUtils.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentUtils.java Tue Jan  8 02:55:24 2008
@@ -20,29 +20,81 @@
 public final class SegmentUtils {
     
 	public static int countArgs(String descriptor) {
-		int bra = descriptor.indexOf("(");
-		int ket = descriptor.indexOf(")");
-		if (bra == -1 || ket == -1 || ket < bra)
-			throw new IllegalArgumentException("No arguments");
+	    return countArgs(descriptor, 1);
+//		int bra = descriptor.indexOf("(");
+//		int ket = descriptor.indexOf(")");
+//		if (bra == -1 || ket == -1 || ket < bra)
+//			throw new IllegalArgumentException("No arguments");
+//
+//		boolean inType = false;
+//		int count = 0;
+//		for (int i = bra + 1; i < ket; i++) {
+//			char charAt = descriptor.charAt(i);
+//			if (inType && charAt == ';') {
+//				inType = false;
+//			} else if (!inType && charAt == 'L') {
+//				inType = true;
+//				count++;
+//			} else if (charAt == '[' || inType) {
+//				// NOP
+//			} else {
+//				count++;
+//			}
+//		}
+//		return count;
+	}
 
-		boolean inType = false;
-		int count = 0;
-		for (int i = bra + 1; i < ket; i++) {
-			char charAt = descriptor.charAt(i);
-			if (inType && charAt == ';') {
-				inType = false;
-			} else if (!inType && charAt == 'L') {
-				inType = true;
-				count++;
-			} else if (charAt == '[' || inType) {
-				// NOP
-			} else {
-				count++;
-			}
-		}
-		return count;
+	public static int countInvokeInterfaceArgs(String descriptor) {
+	    return countArgs(descriptor, 2);
 	}
+	
+	/**
+	 * Count the number of arguments in the descriptor. Each
+	 * long or double counts as widthOfLongsAndDoubles; all other
+	 * arguments count as 1.
+	 * @param descriptor String for which arguments are counted
+	 * @param widthOfLongsAndDoubles int increment to apply for longs
+	 *   doubles. This is typically 1 when counting arguments alone,
+	 *   or 2 when counting arguments for invokeinterface.
+	 * @return integer count
+	 */
+	protected static int countArgs(String descriptor, int widthOfLongsAndDoubles) {
+	    int bra = descriptor.indexOf("(");
+	    int ket = descriptor.indexOf(")");
+	    if (bra == -1 || ket == -1 || ket < bra)
+	        throw new IllegalArgumentException("No arguments");
 
+	    boolean inType = false;
+	    boolean consumingNextType = false;
+	    int count = 0;
+	    for (int i = bra + 1; i < ket; i++) {
+	        char charAt = descriptor.charAt(i);
+	        if (inType && charAt == ';') {
+	            inType = false;
+	            consumingNextType = false;
+	        } else if (!inType && charAt == 'L') {
+	            inType = true;
+	            count++;
+	        } else if (charAt == '[') {
+	            consumingNextType = true;
+	        } else if(inType) {
+	            // NOP
+	        } else {
+	            if(consumingNextType) {
+	                count++;
+	                consumingNextType = false;
+	            } else {
+	                if(charAt == 'D' || charAt == 'J') {
+	                    count+=widthOfLongsAndDoubles;
+	                } else {
+	                    count++;
+	                }
+	            }
+	        }
+	    }
+	    return count;
+	}
+	   
 	public static int countMatches(long[] flags, IMatcher matcher) {
 		int count = 0;
 		for (int i = 0; i < flags.length; i++) {

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/Attribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/Attribute.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/Attribute.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/Attribute.java Tue Jan  8 02:55:24 2008
@@ -25,7 +25,7 @@
     private int attributeNameIndex;
 
     public Attribute(String attributeName) {
-        this.attributeName = new CPUTF8(attributeName);
+        this.attributeName = new CPUTF8(attributeName, ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ);
     }
 
     protected void doWrite(DataOutputStream dos) throws IOException {



Mime
View raw message