You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2005/12/01 07:04:00 UTC
svn commit: r350181 [58/198] - in
/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core: ./ depends/
depends/files/ depends/jars/ depends/libs/ depends/libs/linux.IA32/
depends/libs/win.IA32/ depends/oss/ depends/oss/linux.IA32/
depends/oss/win.I...
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/ProcessOutputStream.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/ProcessOutputStream.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/ProcessOutputStream.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/ProcessOutputStream.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,138 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.oti.lang;
+
+
+class ProcessOutputStream extends java.io.OutputStream {
+
+ private long handle;
+
+ private java.io.FileDescriptor fd;
+
+ // Fill in the JNI id caches
+ private static native void oneTimeInitialization();
+
+ static {
+ oneTimeInitialization();
+ }
+
+ /**
+ * Open an OutputStream based on the handle.
+ */
+ protected ProcessOutputStream(long handle) {
+ this.fd = new java.io.FileDescriptor();
+ setFDImpl(fd, handle);
+ this.handle = handle;
+ }
+
+ /*
+ * There is no way, at the library/vm level, to know when the stream will be
+ * available for closing. If the user doesn't close it in its code, the
+ * finalize() will run (eventually ?) and close the dandling OS
+ * fileDescriptor.
+ */
+ protected void finalize() throws Throwable {
+ close();
+ }
+
+ /**
+ * Close the stream.
+ */
+ public void close() throws java.io.IOException {
+ synchronized (this) {
+ if (handle == -1)
+ return;
+ closeImpl();
+ handle = -1;
+ }
+ }
+
+ /**
+ * Native to close the stream.
+ */
+ private native void closeImpl() throws java.io.IOException;
+
+ /**
+ * Native to set the FileDescriptor handle.
+ */
+ private native void setFDImpl(java.io.FileDescriptor fd, long handle);
+
+ /**
+ * Writes the entire contents of the byte array <code>buf</code> to this
+ * OutputStream.
+ *
+ * @param buf
+ * the buffer to be written
+ *
+ * @throws java.io.IOException
+ * If an error occurs attempting to write to this OutputStream.
+ */
+ public void write(byte[] buf) throws java.io.IOException {
+ synchronized (this) {
+ writeImpl(buf, 0, buf.length, handle);
+ }
+ }
+
+ /**
+ * Writes <code>nbytes</code> <code>bytes</code> from the byte array
+ * <code>buf</code> starting at <code>offset</code> to this
+ * OutputStream.
+ *
+ * @param buf
+ * the buffer to be written
+ * @param offset
+ * offset in buffer to get bytes
+ * @param nbytes
+ * number of bytes in buffer to write
+ *
+ * @throws java.io.IOException
+ * If an error occurs attempting to write to this OutputStream.
+ * @throws java.lang.IndexOutOfBoundsException
+ * If offset or count are outside of bounds.
+ */
+ public void write(byte[] buf, int offset, int nbytes)
+ throws java.io.IOException {
+ synchronized (this) {
+ if (handle == -1)
+ return;
+ writeImpl(buf, offset, nbytes, handle);
+ }
+ }
+
+ /**
+ * Writes the specified byte <code>oneByte</code> to this OutputStream.
+ * Only the low order byte of <code>oneByte</code> is written.
+ *
+ * @param oneByte
+ * the byte to be written
+ *
+ * @throws java.io.IOException
+ * If an error occurs attempting to write to this OutputStream.
+ */
+ public void write(int oneByte) throws java.io.IOException {
+ byte buf[] = new byte[1];
+ buf[0] = (byte) oneByte;
+ synchronized (this) {
+ writeImpl(buf, 0, 1, handle);
+ }
+ }
+
+ /**
+ * Native to write the buffer to the stream.
+ */
+ private native void writeImpl(byte[] buf, int offset, int nbytes, long hndl)
+ throws java.io.IOException;
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/SystemProcess.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/SystemProcess.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/SystemProcess.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/SystemProcess.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,273 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.oti.lang;
+
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * This class provides the exec() implementation required for java.lang.Runtime.
+ *
+ * Instances of class Process provide control of and access to platform
+ * processes. This is the concrete implementation of class java.lang.Process.
+ *
+ * @see java.lang.Runtime
+ */
+public class SystemProcess extends java.lang.Process {
+ InputStream err; // STDERR for the process
+
+ InputStream out; // STDOUT for the process
+
+ OutputStream in; // STDIN for the process
+
+ long handle = -1; // Handle to OS process struct
+
+ /*
+ * When exitCodeAvailable == 1, exitCode has a meaning. When exitCode is
+ * available, it means that the underlying process had finished (for sure).
+ */
+ boolean exitCodeAvailable = false;
+
+ int exitCode;
+
+ Object lock;
+
+ boolean waiterStarted = false;
+
+ Throwable exception = null;
+
+ // Fill in the JNI id caches
+ private static native void oneTimeInitialization();
+
+ static {
+ oneTimeInitialization();
+ }
+
+ /**
+ * Prevents this class from being instantiated.
+ */
+ private SystemProcess() {
+ }
+
+ /**
+ * Answers a Process hooked to an OS process.
+ *
+ * @param progArray
+ * the array containing the program to execute as well as any
+ * arguments to the program.
+ * @param envp
+ * the array containing the environment to start the new process
+ * in.
+ * @param directory
+ * the directory to start the process in, or null
+ *
+ * @return a java.lang.Process
+ *
+ * @throws IOException
+ * when a problem occurs
+ * @throws NullPointerException
+ * when progArray or envp are null, or contain a null element in
+ * the array.
+ */
+ public static Process create(String[] progArray, String[] envp,
+ final File directory) throws IOException {
+ final byte[][] progBytes, envBytes;
+ progBytes = new byte[progArray.length][];
+ for (int i = 0; i < progArray.length; i++)
+ progBytes[i] = com.ibm.oti.util.Util.getBytes(progArray[i]);
+ envBytes = new byte[envp.length][];
+ for (int i = 0; i < envp.length; i++)
+ envBytes[i] = com.ibm.oti.util.Util.getBytes(envp[i]);
+
+ final SystemProcess p = new SystemProcess();
+
+ p.lock = new Object();
+
+ Runnable waitingThread = new Runnable() {
+ public void run() {
+ long[] procVals = null;
+ try {
+ procVals = createImpl(p, progBytes, envBytes,
+ directory == null ? null : com.ibm.oti.util.Util
+ .getBytes(directory.getPath()));
+ } catch (Throwable e) {
+ /* Creation errors need to be passed to the user thread. */
+ synchronized (p.lock) {
+ p.exception = e;
+ p.waiterStarted = true;
+ p.lock.notifyAll();
+ }
+ return;
+ }
+ p.handle = procVals[0];
+ p.in = new ProcessOutputStream(procVals[1]);
+ p.out = new ProcessInputStream(procVals[2]);
+ p.err = new ProcessInputStream(procVals[3]);
+
+ synchronized (p.lock) {
+ p.waiterStarted = true;
+ p.lock.notifyAll();
+ }
+
+ p.exitCode = p.waitForCompletionImpl();
+ synchronized (p.lock) {
+ p.closeImpl();
+ p.handle = -1;
+ }
+ p.exitCodeAvailable = true;
+ synchronized (p.lock) {
+ try {
+ p.in.close();
+ } catch (IOException e) {
+ }
+ p.lock.notifyAll();
+ }
+ }
+ };
+ Thread wait = new Thread(waitingThread);
+ wait.setDaemon(true);
+ wait.start();
+
+ try {
+ synchronized (p.lock) {
+ while (!p.waiterStarted)
+ p.lock.wait();
+ if (p.exception != null) {
+ /* Re-throw exception that originated in the helper thread */
+ p.exception.fillInStackTrace();
+ if (p.exception instanceof IOException)
+ throw (IOException) p.exception;
+ else if (p.exception instanceof Error)
+ throw (Error) p.exception;
+ else
+ throw (RuntimeException) p.exception;
+ }
+ }
+ } catch (InterruptedException e) {
+ throw new InternalError();
+ }
+
+ return p;
+ }
+
+ protected synchronized static native long[] createImpl(Process p,
+ byte[][] progArray, byte[][] envp, byte[] dir)
+ throws java.io.IOException;
+
+ /**
+ * Stops the process associated with the receiver.
+ */
+ public void destroy() {
+ synchronized (lock) {
+ if (handle != -1)
+ destroyImpl();
+ }
+ }
+
+ /**
+ * Internal implementation of the code that stops the process associated
+ * with the receiver.
+ */
+ private native void destroyImpl();
+
+ /**
+ * Internal implementation of the code that closes the handle.
+ */
+ native void closeImpl();
+
+ /**
+ * Answers the exit value of the receiving Process. It is available only
+ * when the OS subprocess is finished.
+ *
+ * @return int The exit value of the process.
+ */
+ public int exitValue() {
+ synchronized (lock) {
+ if (!exitCodeAvailable)
+ throw new IllegalThreadStateException();
+ return exitCode;
+ }
+ }
+
+ /**
+ * Answers the receiver's error output stream.
+ * <p>
+ * Note: This is an InputStream which allows reading of the other process'
+ * "stderr".
+ *
+ * @return InputStream The receiver's process' stderr.
+ */
+ public java.io.InputStream getErrorStream() {
+ return err;
+ }
+
+ /**
+ * Answers the receiver's standard output stream.
+ * <p>
+ * Note: This is an InputStream which allows reading of the other process'
+ * "stdout".
+ *
+ * @return InputStream The receiver's process' stdout.
+ */
+ public java.io.InputStream getInputStream() {
+ return out;
+ }
+
+ /**
+ * Answers the receiver's standard input stream
+ * <p>
+ * Note: This is an OutputStream which allows writing to the other process'
+ * "stdin".
+ *
+ * @return OutputStream The receiver's process' stdout.
+ */
+ public java.io.OutputStream getOutputStream() {
+ return in;
+ }
+
+ /**
+ * Causes the calling thread to wait for the process associated with the
+ * receiver to finish executing.
+ *
+ * @throws InterruptedException
+ * If the calling thread is interrupted
+ *
+ * @return int The exit value of the Process being waited on
+ */
+ public int waitFor() throws InterruptedException {
+ synchronized (lock) {
+ /*
+ * if the exitCode is available, it means that the underlying OS
+ * process is already dead, so the exitCode is just returned whitout
+ * any other OS checks
+ */
+ while (!exitCodeAvailable)
+ lock.wait();
+ return exitCode;
+ }
+ }
+
+ /**
+ * Internal implementation of the code that waits for the process to
+ * complete.
+ *
+ * @return int The exit value of the process.
+ */
+ native int waitForCompletionImpl();
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyCharArrayCache.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyCharArrayCache.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyCharArrayCache.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyCharArrayCache.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,121 @@
+/* Copyright 2001, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.oti.lang.reflect;
+
+
+class ProxyCharArrayCache {
+ // to avoid using Enumerations, walk the individual tables skipping nulls
+ char[] keyTable[];
+
+ int valueTable[];
+
+ int elementSize; // number of elements in the table
+
+ int threshold;
+
+ static boolean equals(char[] first, char[] second) {
+ if (first == second) {
+ return true;
+ }
+ if (first == null || second == null) {
+ return false;
+ }
+ if (first.length != second.length) {
+ return false;
+ }
+
+ for (int i = first.length; --i >= 0;)
+ if (first[i] != second[i]) {
+ return false;
+ }
+ return true;
+ }
+
+ ProxyCharArrayCache(int initialCapacity) {
+ if (initialCapacity < 13) {
+ initialCapacity = 13;
+ }
+ this.elementSize = 0;
+ this.threshold = (int) (initialCapacity * 0.66f);
+ this.keyTable = new char[initialCapacity][];
+ this.valueTable = new int[initialCapacity];
+ }
+
+ int get(char[] key) {
+ int index = hashCodeChar(key);
+ while (keyTable[index] != null) {
+ if (equals(keyTable[index], key))
+ return valueTable[index];
+ index = (index + 1) % keyTable.length;
+ }
+ return -1;
+ }
+
+ private int hashCodeChar(char[] val) {
+ int length = val.length;
+ int hash = 0;
+ int n = 2; // number of characters skipped
+ for (int i = 0; i < length; i += n)
+ hash += val[i];
+ return (hash & 0x7FFFFFFF) % keyTable.length;
+ }
+
+ int put(char[] key, int value) {
+ int index = hashCodeChar(key);
+ while (keyTable[index] != null) {
+ if (equals(keyTable[index], key))
+ return valueTable[index] = value;
+ index = (index + 1) % keyTable.length;
+ }
+ keyTable[index] = key;
+ valueTable[index] = value;
+
+ // assumes the threshold is never equal to the size of the table
+ if (++elementSize > threshold)
+ rehash();
+ return value;
+ }
+
+ private void rehash() {
+ ProxyCharArrayCache newHashtable = new ProxyCharArrayCache(
+ keyTable.length * 2);
+ for (int i = keyTable.length; --i >= 0;)
+ if (keyTable[i] != null)
+ newHashtable.put(keyTable[i], valueTable[i]);
+
+ this.keyTable = newHashtable.keyTable;
+ this.valueTable = newHashtable.valueTable;
+ this.threshold = newHashtable.threshold;
+ }
+
+ int size() {
+ return elementSize;
+ }
+
+ public String toString() {
+ int max = size();
+ StringBuffer buf = new StringBuffer();
+ buf.append("{");
+ for (int i = 0; i < max; ++i) {
+ if (keyTable[i] != null)
+ buf.append(keyTable[i]).append("->").append(valueTable[i]);
+ if (i < max)
+ buf.append(", ");
+ }
+ buf.append("}");
+ return buf.toString();
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyClassFile.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyClassFile.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyClassFile.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyClassFile.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,874 @@
+/* Copyright 2001, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.oti.lang.reflect;
+
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.util.ArrayList;
+import java.util.HashSet;
+
+public final class ProxyClassFile implements ProxyConstants {
+ private ProxyConstantPool constantPool;
+
+ byte[] header; // the header contains all the bytes till the end of the
+ // constant pool
+
+ int headerOffset;
+
+ private byte[] contents; // that collection contains all the remaining
+ // bytes of the .class file
+
+ private int contentsOffset;
+
+ private int constantPoolOffset;
+
+ private ProxyMethod[] proxyMethods;
+
+ private static final int INITIAL_CONTENTS_SIZE = 1000;
+
+ private static final int INITIAL_HEADER_SIZE = 500;
+
+ private static final int INCREMENT_SIZE = 250;
+
+ private static Method ObjectEqualsMethod, ObjectHashCodeMethod,
+ ObjectToStringMethod;
+
+ private static Method ClassForNameMethod, ClassGetMethod;
+
+ private static Method HandlerInvokeMethod;
+
+ private static Constructor ProxyConstructor,
+ UndeclaredThrowableExceptionConstructor;
+
+ private static Field ProxyHandlerField;
+
+ public static byte[] generateBytes(String typeName, Class[] interfaces) {
+ ProxyClassFile classFile = new ProxyClassFile(typeName, interfaces);
+ classFile.addFields();
+ classFile.findMethods(interfaces);
+ classFile.addMethods();
+ classFile.addAttributes();
+ return classFile.getBytes();
+ }
+
+ static char[] getConstantPoolName(Class c) {
+ if (c.isArray())
+ return c.getName().replace('.', '/').toCharArray(); // Array classes
+ // are named
+ // with their
+ // signature
+ if (c.isPrimitive()) {
+ // Special cases for each base type.
+ if (c == void.class)
+ return new char[] { 'V' };
+ if (c == int.class)
+ return new char[] { 'I' };
+ if (c == boolean.class)
+ return new char[] { 'Z' };
+ if (c == byte.class)
+ return new char[] { 'B' };
+ if (c == char.class)
+ return new char[] { 'C' };
+ if (c == short.class)
+ return new char[] { 'S' };
+ if (c == long.class)
+ return new char[] { 'J' };
+ if (c == float.class)
+ return new char[] { 'F' };
+ if (c == double.class)
+ return new char[] { 'D' };
+ }
+ return ("L" + c.getName().replace('.', '/') + ";").toCharArray();
+ }
+
+ static char[] getConstantPoolName(Constructor method) /* (ILjava/lang/Thread;)V */{
+ Class[] parameters = method.getParameterTypes();
+ StringBuffer buffer = new StringBuffer(parameters.length + 1 * 20);
+ buffer.append('(');
+ for (int i = 0, length = parameters.length; i < length; i++)
+ buffer.append(getConstantPoolName(parameters[i]));
+ buffer.append(')');
+ buffer.append(getConstantPoolName(void.class));
+ return buffer.toString().toCharArray();
+ }
+
+ static char[] getConstantPoolName(Method method) /* (ILjava/lang/Thread;)Ljava/lang/Object; */{
+ Class[] parameters = method.getParameterTypes();
+ StringBuffer buffer = new StringBuffer(parameters.length + 1 * 20);
+ buffer.append('(');
+ for (int i = 0, length = parameters.length; i < length; i++)
+ buffer.append(getConstantPoolName(parameters[i]));
+ buffer.append(')');
+ buffer.append(getConstantPoolName(method.getReturnType()));
+ return buffer.toString().toCharArray();
+ }
+
+ ProxyClassFile(String typeName, Class[] interfaces) {
+ header = new byte[INITIAL_HEADER_SIZE];
+ // generate the magic numbers inside the header
+ header[headerOffset++] = (byte) (0xCAFEBABEL >> 24);
+ header[headerOffset++] = (byte) (0xCAFEBABEL >> 16);
+ header[headerOffset++] = (byte) (0xCAFEBABEL >> 8);
+ header[headerOffset++] = (byte) (0xCAFEBABEL >> 0);
+ // Compatible with JDK 1.2
+ header[headerOffset++] = 0;
+ header[headerOffset++] = 0;
+ header[headerOffset++] = 0;
+ header[headerOffset++] = 46;
+ constantPoolOffset = headerOffset;
+ headerOffset += 2;
+ constantPool = new ProxyConstantPool(this);
+ contents = new byte[INITIAL_CONTENTS_SIZE];
+ // now we continue to generate the bytes inside the contents array
+ int accessFlags = AccPublic | AccFinal | AccSuper;
+ contents[contentsOffset++] = (byte) (accessFlags >> 8);
+ contents[contentsOffset++] = (byte) accessFlags;
+ int classNameIndex = constantPool.typeIndex(typeName);
+ contents[contentsOffset++] = (byte) (classNameIndex >> 8);
+ contents[contentsOffset++] = (byte) classNameIndex;
+ int superclassNameIndex = constantPool
+ .typeIndex("java/lang/reflect/Proxy");
+ contents[contentsOffset++] = (byte) (superclassNameIndex >> 8);
+ contents[contentsOffset++] = (byte) superclassNameIndex;
+ int interfacesCount = interfaces.length;
+ contents[contentsOffset++] = (byte) (interfacesCount >> 8);
+ contents[contentsOffset++] = (byte) interfacesCount;
+ for (int i = 0; i < interfacesCount; i++) {
+ int interfaceIndex = constantPool
+ .typeIndex(interfaces[i].getName());
+ contents[contentsOffset++] = (byte) (interfaceIndex >> 8);
+ contents[contentsOffset++] = (byte) interfaceIndex;
+ }
+ }
+
+ private void addAttributes() {
+ writeUnsignedShort(0); // classFile does not have attributes of its own
+
+ // resynchronize all offsets of the classfile
+ header = constantPool.poolContent;
+ headerOffset = constantPool.currentOffset;
+ int constantPoolCount = constantPool.currentIndex;
+ header[constantPoolOffset++] = (byte) (constantPoolCount >> 8);
+ header[constantPoolOffset] = (byte) constantPoolCount;
+ }
+
+ private void addFields() {
+ writeUnsignedShort(0); // we have no fields
+ }
+
+ private void addMethods() {
+ int methodCount = proxyMethods.length;
+ writeUnsignedShort(methodCount + 1);
+
+ // save constructor
+ writeUnsignedShort(AccPublic);
+ writeUnsignedShort(constantPool.literalIndex(Init));
+ if (ProxyConstructor == null) {
+ try {
+ ProxyConstructor = Proxy.class
+ .getDeclaredConstructor(new Class[] { InvocationHandler.class });
+ } catch (NoSuchMethodException e) {
+ throw new InternalError();
+ }
+ }
+ writeUnsignedShort(constantPool
+ .literalIndex(getConstantPoolName(ProxyConstructor)));
+ writeUnsignedShort(1); // store just the code attribute
+ writeUnsignedShort(constantPool.literalIndex(CodeName));
+ // save attribute_length(4), max_stack(2), max_locals(2), code_length(4)
+ int codeLength = 6;
+ writeUnsignedWord(12 + codeLength); // max_stack(2), max_locals(2),
+ // code_length(4), 2 zero shorts
+ writeUnsignedShort(2);
+ writeUnsignedShort(2);
+ writeUnsignedWord(codeLength);
+ writeUnsignedByte(OPC_aload_0);
+ writeUnsignedByte(OPC_aload_1);
+ writeUnsignedByte(OPC_invokespecial);
+ writeUnsignedShort(constantPool.literalIndex(ProxyConstructor));
+ writeUnsignedByte(OPC_return);
+ writeUnsignedShort(0); // no exceptions table
+ writeUnsignedShort(0); // there are no attributes for the code
+ // attribute
+
+ for (int i = 0; i < methodCount; i++) {
+ ProxyMethod pMethod = proxyMethods[i];
+ Method method = pMethod.method;
+ writeUnsignedShort(AccPublic | AccFinal);
+ writeUnsignedShort(constantPool.literalIndex(method.getName()
+ .toCharArray()));
+ writeUnsignedShort(constantPool
+ .literalIndex(getConstantPoolName(method)));
+ Class[] thrownsExceptions = pMethod.commonExceptions;
+ int eLength = thrownsExceptions.length;
+ if (eLength > 0) {
+ writeUnsignedShort(2); // store the exception & code attributes
+ // The method has a throw clause. So we need to add an exception
+ // attribute
+ writeUnsignedShort(constantPool.literalIndex(ExceptionsName));
+ // The attribute length = length * 2 + 2 in case of a exception
+ // attribute
+ writeUnsignedWord(eLength * 2 + 2);
+ writeUnsignedShort(eLength);
+ for (int e = 0; e < eLength; e++)
+ writeUnsignedShort(constantPool
+ .typeIndex(thrownsExceptions[e].getName()));
+ } else {
+ writeUnsignedShort(1); // store just the code attribute
+ }
+ generateCodeAttribute(pMethod);
+ }
+ }
+
+ private void findMethods(Class[] interfaces) {
+ // find all methods defined by the interfaces (including inherited
+ // interfaces) plus hashCode, equals & toString from Object
+ // build an array with the methods... no duplicates - check upto the
+ // array size when the interface's first method was added
+ if (ObjectEqualsMethod == null) {
+ try {
+ ObjectEqualsMethod = Object.class.getMethod("equals",
+ new Class[] { Object.class });
+ ObjectHashCodeMethod = Object.class.getMethod("hashCode",
+ new Class[0]);
+ ObjectToStringMethod = Object.class.getMethod("toString",
+ new Class[0]);
+ } catch (NoSuchMethodException ex) {
+ throw new InternalError();
+ }
+ }
+
+ ArrayList allMethods = new ArrayList(25);
+ allMethods.add(new ProxyMethod(ObjectEqualsMethod));
+ allMethods.add(new ProxyMethod(ObjectHashCodeMethod));
+ allMethods.add(new ProxyMethod(ObjectToStringMethod));
+
+ HashSet interfacesSeen = new HashSet();
+ for (int i = 0, length = interfaces.length; i < length; i++)
+ findMethods(interfaces[i], allMethods, interfacesSeen);
+
+ proxyMethods = new ProxyMethod[allMethods.size()];
+ allMethods.toArray(proxyMethods);
+ }
+
+ private void findMethods(Class nextInterface, ArrayList allMethods,
+ HashSet interfacesSeen) {
+ // add the nextInterface's methods to allMethods
+ // if an equivalent method already exists then return types must be
+ // identical... don't replace it
+
+ if (interfacesSeen.contains(nextInterface))
+ return; // already walked it
+ interfacesSeen.add(nextInterface);
+
+ int existingMethodCount = allMethods.size();
+ Method[] methods = nextInterface.getMethods();
+ nextMethod: for (int i = 0, length = methods.length; i < length; i++) {
+ Method method = methods[i];
+ for (int j = 0; j < existingMethodCount; j++)
+ if (((ProxyMethod) allMethods.get(j)).matchMethod(method))
+ continue nextMethod;
+ allMethods.add(new ProxyMethod(method));
+ }
+
+ Class[] superInterfaces = nextInterface.getInterfaces();
+ for (int i = 0, length = superInterfaces.length; i < length; i++)
+ findMethods(superInterfaces[i], allMethods, interfacesSeen); // recursion
+ // should
+ // be
+ // minimal
+ }
+
+ private void generateCodeAttribute(ProxyMethod pMethod) {
+ int codeAttributeOffset = contentsOffset;
+ int contentsLength = contents.length;
+ if (contentsOffset + 20 + 100 >= contentsLength)
+ System.arraycopy(contents, 0, (contents = new byte[contentsLength
+ + INCREMENT_SIZE]), 0, contentsLength);
+ writeUnsignedShort(constantPool.literalIndex(CodeName));
+ // leave space for attribute_length(4), max_stack(2), max_locals(2),
+ // code_length(4)
+ contentsOffset += 12;
+
+ /*
+ * to push the args for the call to invoke push the receiver field h 0
+ * aload0 1 getfield 33 java.lang.reflect.Proxy.h
+ * Ljava.lang.reflect.InvocationHandler; push the receiver as the first
+ * arg 4 aload0 push the method push the array of args call invoke 89
+ * invokeinterface 67
+ * java.lang.reflect.InvocationHandler.invoke(Ljava.lang.Object;Ljava.lang.reflect.Method;[Ljava.lang.Object;)Ljava.lang.Object;
+ * cast return result catch & convert exceptions if necessary
+ */
+
+ int codeStartOffset = contentsOffset;
+ writeUnsignedByte(OPC_aload_0);
+ writeUnsignedByte(OPC_getfield);
+ if (ProxyHandlerField == null) {
+ try {
+ ProxyHandlerField = Proxy.class.getDeclaredField("h");
+ } catch (NoSuchFieldException e) {
+ throw new InternalError();
+ }
+ }
+ writeUnsignedShort(constantPool.literalIndex(ProxyHandlerField));
+ writeUnsignedByte(OPC_aload_0);
+ Method method = pMethod.method;
+ Class[] argTypes = method.getParameterTypes();
+ genCallGetMethod(method.getDeclaringClass(), method.getName(), argTypes);
+ int maxLocals = genInvokeArgs(argTypes);
+ writeUnsignedByte(OPC_invokeinterface);
+ if (HandlerInvokeMethod == null) {
+ try {
+ HandlerInvokeMethod = InvocationHandler.class.getMethod(
+ "invoke", new Class[] { Object.class, Method.class,
+ Object[].class });
+ } catch (NoSuchMethodException e) {
+ throw new InternalError();
+ }
+ }
+ writeUnsignedShort(constantPool.literalIndex(HandlerInvokeMethod));
+ writeUnsignedByte(4); // invoke has 3 args
+ writeUnsignedByte(0); // 4th operand must be 0
+ genCastReturnType(method.getReturnType());
+ int codeLength = contentsOffset - codeStartOffset;
+
+ Class[] checkedExceptions = pMethod.getCheckedExceptions();
+ int checkedLength = checkedExceptions.length;
+ if (checkedLength > 0) {
+ int codeEndIndex = contentsOffset - codeStartOffset;
+ writeUnsignedByte(OPC_athrow); // rethrow the caught exception
+
+ genStoreArg(maxLocals);
+ writeUnsignedByte(OPC_new);
+ writeUnsignedShort(constantPool
+ .typeIndex("java/lang/reflect/UndeclaredThrowableException"));
+ writeUnsignedByte(OPC_dup);
+ genLoadArg(maxLocals);
+ maxLocals++; // now expecting the exception
+ writeUnsignedByte(OPC_invokespecial);
+ if (UndeclaredThrowableExceptionConstructor == null) {
+ try {
+ UndeclaredThrowableExceptionConstructor = UndeclaredThrowableException.class
+ .getConstructor(new Class[] { Throwable.class });
+ } catch (NoSuchMethodException e) {
+ throw new InternalError();
+ }
+ }
+ writeUnsignedShort(constantPool
+ .literalIndex(UndeclaredThrowableExceptionConstructor));
+ writeUnsignedByte(OPC_athrow);
+
+ codeLength = contentsOffset - codeStartOffset;
+
+ // write the exception table
+ writeUnsignedShort(checkedLength + 1);
+ for (int i = 0; i < checkedLength; i++) {
+ writeUnsignedShort(0);
+ writeUnsignedShort(codeEndIndex);
+ writeUnsignedShort(codeEndIndex);
+ writeUnsignedShort(constantPool.typeIndex(checkedExceptions[i]
+ .getName()));
+ }
+ writeUnsignedShort(0);
+ writeUnsignedShort(codeEndIndex);
+ writeUnsignedShort(codeEndIndex + 1); // starts after the first
+ // throw
+ writeUnsignedShort(constantPool.typeIndex("java/lang/Throwable"));
+ } else {
+ writeUnsignedShort(0); // no exceptions table
+ }
+
+ writeUnsignedShort(0); // there are no attributes for the code
+ // attribute
+
+ // Complete the creation of the code attribute by setting the
+ // attribute_length, max_stack
+ // max_locals, code_length & exception table
+ // codeAttributeOffset is the position inside contents byte array before
+ // we started to write
+ // That means that to write the attribute_length you need to offset by 2
+ // the value of codeAttributeOffset
+ // to get the right position, 6 for the max_stack etc...
+ int codeAttributeLength = contentsOffset - (codeAttributeOffset + 6);
+ contents[codeAttributeOffset + 2] = (byte) (codeAttributeLength >> 24);
+ contents[codeAttributeOffset + 3] = (byte) (codeAttributeLength >> 16);
+ contents[codeAttributeOffset + 4] = (byte) (codeAttributeLength >> 8);
+ contents[codeAttributeOffset + 5] = (byte) codeAttributeLength;
+
+ int maxStack = maxLocals + 10; // larger than the exact amount
+ contents[codeAttributeOffset + 6] = (byte) (maxStack >> 8);
+ contents[codeAttributeOffset + 7] = (byte) maxStack;
+ contents[codeAttributeOffset + 8] = (byte) (maxLocals >> 8);
+ contents[codeAttributeOffset + 9] = (byte) maxLocals;
+ contents[codeAttributeOffset + 10] = (byte) (codeLength >> 24);
+ contents[codeAttributeOffset + 11] = (byte) (codeLength >> 16);
+ contents[codeAttributeOffset + 12] = (byte) (codeLength >> 8);
+ contents[codeAttributeOffset + 13] = (byte) codeLength;
+ }
+
+ /*
+ * Perform call to Class.getMethod(String, Class[]) receiver 13 ldc 37
+ * (java.lang.String) "java.lang.Object" 15 invokestatic 43
+ * java.lang.Class.forName(Ljava.lang.String;)Ljava.lang.Class; selector 37
+ * ldc 55 (java.lang.String) "equals" plus method args 39 iconst0 40
+ * anewarray 39 java.lang.Class or 39 iconst1 40 anewarray 39
+ * java.lang.Class 43 dup 44 iconst0 53 ldc 37 (java.lang.String)
+ * "java.lang.Object" 55 invokestatic 43
+ * java.lang.Class.forName(Ljava.lang.String;)Ljava.lang.Class; 77 aastore
+ * or 39 iconst2 40 anewarray 39 java.lang.Class 43 dup 44 iconst0 45
+ * getstatic 102 java.lang.Integer.TYPE Ljava.lang.Class; 48 aastore 49 dup
+ * 50 iconst1 51 getstatic 104 java.lang.Boolean.TYPE Ljava.lang.Class; 54
+ * aastore then 78 invokevirtual 59
+ * java.lang.Class.getMethod(Ljava.lang.String;[Ljava.lang.Class;)Ljava.lang.reflect.Method;
+ */
+ private void genCallGetMethod(Class receiverType, String selector,
+ Class[] argTypes) {
+ genCallClassForName(receiverType.getName());
+ writeLdc(selector);
+ int length = argTypes.length;
+ writeIntConstant(length);
+ writeUnsignedByte(OPC_anewarray);
+ writeUnsignedShort(constantPool.typeIndex("java/lang/Class"));
+ for (int i = 0; i < length; i++) {
+ writeUnsignedByte(OPC_dup);
+ writeIntConstant(i);
+ Class type = argTypes[i];
+ if (type.isPrimitive()) {
+ writeUnsignedByte(OPC_getstatic);
+ writeUnsignedShort(constantPool.literalIndex(typeField(type)));
+ } else {
+ genCallClassForName(type.getName());
+ }
+ writeUnsignedByte(OPC_aastore);
+ }
+ writeUnsignedByte(OPC_invokevirtual);
+ if (ClassGetMethod == null) {
+ try {
+ ClassGetMethod = Class.class.getMethod("getMethod",
+ new Class[] { String.class, Class[].class });
+ } catch (NoSuchMethodException e) {
+ throw new InternalError();
+ }
+ }
+ writeUnsignedShort(constantPool.literalIndex(ClassGetMethod));
+ }
+
+ /*
+ * Add argument array for call to InvocationHandler.invoke
+ *
+ * 46 aconstnull or 81 iconst1 82 anewarray 61 java.lang.Object 85 dup 86
+ * iconst0 87 aload1 88 aastore or 58 iconst2 59 anewarray 61
+ * java.lang.Object 62 dup 63 iconst0 64 new 84 java.lang.Integer 67 dup 68
+ * iload1 69 invokespecial 107 java.lang.Integer.<init>(I)V 72 aastore 73
+ * dup 74 iconst1 75 new 69 java.lang.Boolean 78 dup 79 iload2 80
+ * invokespecial 110 java.lang.Boolean.<init>(Z)V 83 aastore
+ */
+ private int genInvokeArgs(Class[] argTypes) {
+ int argByteOffset = 1; // remember h is at position 0
+ int length = argTypes.length;
+ if (length == 0) {
+ writeUnsignedByte(OPC_aconst_null);
+ } else {
+ writeIntConstant(length);
+ writeUnsignedByte(OPC_anewarray);
+ writeUnsignedShort(constantPool.typeIndex("java/lang/Object"));
+ for (int i = 0; i < length; i++) {
+ writeUnsignedByte(OPC_dup);
+ writeIntConstant(i);
+ argByteOffset = genInvokeArg(argTypes[i], argByteOffset);
+ writeUnsignedByte(OPC_aastore);
+ }
+ }
+ return argByteOffset;
+ }
+
+ private int genInvokeArg(Class type, int argByteOffset) {
+ // offset represents maxLocals in bytes
+ if (type.isPrimitive()) {
+ writeUnsignedByte(OPC_new);
+ writeUnsignedShort(constantPool.typeIndex(typeWrapperName(type)));
+ writeUnsignedByte(OPC_dup);
+ if (argByteOffset > 255)
+ writeUnsignedByte(OPC_wide);
+ if (type == long.class) {
+ switch (argByteOffset) {
+ case 0:
+ writeUnsignedByte(OPC_lload_0);
+ break;
+ case 1:
+ writeUnsignedByte(OPC_lload_1);
+ break;
+ case 2:
+ writeUnsignedByte(OPC_lload_2);
+ break;
+ case 3:
+ writeUnsignedByte(OPC_lload_3);
+ break;
+ default:
+ writeUnsignedByte(OPC_lload);
+ if (argByteOffset > 255)
+ writeUnsignedShort(argByteOffset);
+ else
+ writeUnsignedByte(argByteOffset);
+ }
+ argByteOffset += 2;
+ } else if (type == float.class) {
+ switch (argByteOffset) {
+ case 0:
+ writeUnsignedByte(OPC_fload_0);
+ break;
+ case 1:
+ writeUnsignedByte(OPC_fload_1);
+ break;
+ case 2:
+ writeUnsignedByte(OPC_fload_2);
+ break;
+ case 3:
+ writeUnsignedByte(OPC_fload_3);
+ break;
+ default:
+ writeUnsignedByte(OPC_fload);
+ if (argByteOffset > 255)
+ writeUnsignedShort(argByteOffset);
+ else
+ writeUnsignedByte(argByteOffset);
+ }
+ argByteOffset++;
+ } else if (type == double.class) {
+ switch (argByteOffset) {
+ case 0:
+ writeUnsignedByte(OPC_dload_0);
+ break;
+ case 1:
+ writeUnsignedByte(OPC_dload_1);
+ break;
+ case 2:
+ writeUnsignedByte(OPC_dload_2);
+ break;
+ case 3:
+ writeUnsignedByte(OPC_dload_3);
+ break;
+ default:
+ writeUnsignedByte(OPC_dload);
+ if (argByteOffset > 255)
+ writeUnsignedShort(argByteOffset);
+ else
+ writeUnsignedByte(argByteOffset);
+ }
+ argByteOffset += 2;
+ } else { // handles int, short, byte, boolean & char
+ switch (argByteOffset) {
+ case 0:
+ writeUnsignedByte(OPC_iload_0);
+ break;
+ case 1:
+ writeUnsignedByte(OPC_iload_1);
+ break;
+ case 2:
+ writeUnsignedByte(OPC_iload_2);
+ break;
+ case 3:
+ writeUnsignedByte(OPC_iload_3);
+ break;
+ default:
+ writeUnsignedByte(OPC_iload);
+ if (argByteOffset > 255)
+ writeUnsignedShort(argByteOffset);
+ else
+ writeUnsignedByte(argByteOffset);
+ }
+ argByteOffset++;
+ }
+ writeUnsignedByte(OPC_invokespecial);
+ writeUnsignedShort(constantPool.literalIndex(typeInitMethod(type)));
+ } else {
+ genLoadArg(argByteOffset);
+ argByteOffset++;
+ }
+ return argByteOffset;
+ }
+
+ /*
+ * 94 checkcast 69 java.lang.Boolean 97 invokevirtual 73
+ * java.lang.Boolean.booleanValue()Z 100 ireturn or 52 checkcast 91
+ * java.lang.String 55 areturn
+ */
+ private void genCastReturnType(Class type) {
+ if (type.isPrimitive()) {
+ if (type == void.class) {
+ writeUnsignedByte(OPC_pop);
+ writeUnsignedByte(OPC_return);
+ } else {
+ writeUnsignedByte(OPC_checkcast);
+ writeUnsignedShort(constantPool
+ .typeIndex(typeWrapperName(type)));
+ writeUnsignedByte(OPC_invokevirtual);
+ writeUnsignedShort(constantPool
+ .literalIndex(typeAccessMethod(type)));
+ if (type == long.class) {
+ writeUnsignedByte(OPC_lreturn);
+ } else if (type == float.class) {
+ writeUnsignedByte(OPC_freturn);
+ } else if (type == double.class) {
+ writeUnsignedByte(OPC_dreturn);
+ } else { // handles int, short, byte, boolean & char
+ writeUnsignedByte(OPC_ireturn);
+ }
+ }
+ } else {
+ writeUnsignedByte(OPC_checkcast);
+ writeUnsignedShort(constantPool.typeIndex(type.getName()));
+ writeUnsignedByte(OPC_areturn);
+ }
+ }
+
+ private void genCallClassForName(String typeName) {
+ writeLdc(typeName);
+ writeUnsignedByte(OPC_invokestatic);
+ if (ClassForNameMethod == null) {
+ try {
+ ClassForNameMethod = Class.class.getMethod("forName",
+ new Class[] { String.class });
+ } catch (NoSuchMethodException e) {
+ throw new InternalError();
+ }
+ }
+ writeUnsignedShort(constantPool.literalIndex(ClassForNameMethod));
+ }
+
+ private void genLoadArg(int argByteOffset) {
+ if (argByteOffset > 255) {
+ writeUnsignedByte(OPC_wide);
+ writeUnsignedByte(OPC_aload);
+ writeUnsignedShort(argByteOffset);
+ } else {
+ switch (argByteOffset) {
+ case 0:
+ writeUnsignedByte(OPC_aload_0);
+ break;
+ case 1:
+ writeUnsignedByte(OPC_aload_1);
+ break;
+ case 2:
+ writeUnsignedByte(OPC_aload_2);
+ break;
+ case 3:
+ writeUnsignedByte(OPC_aload_3);
+ break;
+ default:
+ writeUnsignedByte(OPC_aload);
+ writeUnsignedByte(argByteOffset);
+ }
+ }
+ }
+
+ private void genStoreArg(int argByteOffset) {
+ if (argByteOffset > 255) {
+ writeUnsignedByte(OPC_wide);
+ writeUnsignedByte(OPC_astore);
+ writeUnsignedShort(argByteOffset);
+ } else {
+ switch (argByteOffset) {
+ case 0:
+ writeUnsignedByte(OPC_astore_0);
+ break;
+ case 1:
+ writeUnsignedByte(OPC_astore_1);
+ break;
+ case 2:
+ writeUnsignedByte(OPC_astore_2);
+ break;
+ case 3:
+ writeUnsignedByte(OPC_astore_3);
+ break;
+ default:
+ writeUnsignedByte(OPC_astore);
+ writeUnsignedByte(argByteOffset);
+ }
+ }
+ }
+
+ private byte[] getBytes() {
+ byte[] fullContents = new byte[headerOffset + contentsOffset];
+ System.arraycopy(header, 0, fullContents, 0, headerOffset);
+ System.arraycopy(contents, 0, fullContents, headerOffset,
+ contentsOffset);
+ return fullContents;
+ }
+
+ private Method typeAccessMethod(Class baseType) {
+ try {
+ if (baseType == int.class)
+ return Integer.class.getMethod("intValue", null);
+ if (baseType == short.class)
+ return Short.class.getMethod("shortValue", null);
+ if (baseType == byte.class)
+ return Byte.class.getMethod("byteValue", null);
+ if (baseType == boolean.class)
+ return Boolean.class.getMethod("booleanValue", null);
+ if (baseType == char.class)
+ return Character.class.getMethod("charValue", null);
+ if (baseType == long.class)
+ return Long.class.getMethod("longValue", null);
+ if (baseType == float.class)
+ return Float.class.getMethod("floatValue", null);
+ if (baseType == double.class)
+ return Double.class.getMethod("doubleValue", null);
+ } catch (NoSuchMethodException e) {
+ throw new InternalError();
+ }
+ return null;
+ }
+
+ private Field typeField(Class baseType) {
+ try {
+ if (baseType == int.class)
+ return Integer.class.getField("TYPE");
+ if (baseType == short.class)
+ return Short.class.getField("TYPE");
+ if (baseType == byte.class)
+ return Byte.class.getField("TYPE");
+ if (baseType == boolean.class)
+ return Boolean.class.getField("TYPE");
+ if (baseType == char.class)
+ return Character.class.getField("TYPE");
+ if (baseType == long.class)
+ return Long.class.getField("TYPE");
+ if (baseType == float.class)
+ return Float.class.getField("TYPE");
+ if (baseType == double.class)
+ return Double.class.getField("TYPE");
+ } catch (NoSuchFieldException e) {
+ throw new InternalError();
+ }
+ return null;
+ }
+
+ private Constructor typeInitMethod(Class baseType) {
+ try {
+ if (baseType == int.class)
+ return Integer.class.getConstructor(new Class[] { int.class });
+ if (baseType == short.class)
+ return Short.class.getConstructor(new Class[] { short.class });
+ if (baseType == byte.class)
+ return Byte.class.getConstructor(new Class[] { byte.class });
+ if (baseType == boolean.class)
+ return Boolean.class
+ .getConstructor(new Class[] { boolean.class });
+ if (baseType == char.class)
+ return Character.class
+ .getConstructor(new Class[] { char.class });
+ if (baseType == long.class)
+ return Long.class.getConstructor(new Class[] { long.class });
+ if (baseType == float.class)
+ return Float.class.getConstructor(new Class[] { float.class });
+ if (baseType == double.class)
+ return Double.class
+ .getConstructor(new Class[] { double.class });
+ } catch (NoSuchMethodException e) {
+ throw new InternalError();
+ }
+ return null;
+ }
+
+ private String typeWrapperName(Class baseType) {
+ if (baseType == int.class)
+ return "java/lang/Integer";
+ if (baseType == short.class)
+ return "java/lang/Short";
+ if (baseType == byte.class)
+ return "java/lang/Byte";
+ if (baseType == boolean.class)
+ return "java/lang/Boolean";
+ if (baseType == char.class)
+ return "java/lang/Character";
+ if (baseType == long.class)
+ return "java/lang/Long";
+ if (baseType == float.class)
+ return "java/lang/Float";
+ if (baseType == double.class)
+ return "java/lang/Double";
+ return null;
+ }
+
+ private void writeIntConstant(int b) {
+ switch (b) {
+ case 0:
+ writeUnsignedByte(OPC_iconst_0);
+ break;
+ case 1:
+ writeUnsignedByte(OPC_iconst_1);
+ break;
+ case 2:
+ writeUnsignedByte(OPC_iconst_2);
+ break;
+ case 3:
+ writeUnsignedByte(OPC_iconst_3);
+ break;
+ case 4:
+ writeUnsignedByte(OPC_iconst_4);
+ break;
+ case 5:
+ writeUnsignedByte(OPC_iconst_5);
+ break;
+ default:
+ writeUnsignedByte(OPC_bipush);
+ writeUnsignedByte(b);
+ }
+ }
+
+ private void writeLdc(String constant) {
+ int index = constantPool.literalIndexForLdc(constant.toCharArray());
+ if (index <= 0)
+ throw new InternalError();
+ if (index > 255) {
+ writeUnsignedByte(OPC_ldc_w);
+ writeUnsignedShort(index);
+ } else {
+ writeUnsignedByte(OPC_ldc);
+ writeUnsignedByte(index);
+ }
+ }
+
+ private void writeUnsignedByte(int b) {
+ try {
+ contents[contentsOffset++] = (byte) b;
+ } catch (IndexOutOfBoundsException e) {
+ int actualLength = contents.length;
+ System.arraycopy(contents, 0, (contents = new byte[actualLength
+ + INCREMENT_SIZE]), 0, actualLength);
+ contents[contentsOffset - 1] = (byte) b;
+ }
+ }
+
+ private void writeUnsignedShort(int b) {
+ writeUnsignedByte(b >>> 8);
+ writeUnsignedByte(b);
+ }
+
+ private void writeUnsignedWord(int b) {
+ writeUnsignedByte(b >>> 24);
+ writeUnsignedByte(b >>> 16);
+ writeUnsignedByte(b >>> 8);
+ writeUnsignedByte(b);
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyConstantPool.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyConstantPool.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyConstantPool.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyConstantPool.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,310 @@
+/* Copyright 2001, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.oti.lang.reflect;
+
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+class ProxyConstantPool implements ProxyConstants {
+ public static final int UTF8_INITIAL_SIZE = 50;
+
+ public static final int STRING_INITIAL_SIZE = 21;
+
+ public static final int FIELD_INITIAL_SIZE = 7;
+
+ public static final int METHOD_INITIAL_SIZE = 21;
+
+ public static final int INTERFACE_INITIAL_SIZE = 21;
+
+ public static final int CLASS_INITIAL_SIZE = 21;
+
+ public static final int NAMEANDTYPE_INITIAL_SIZE = 21;
+
+ public static final int CONSTANTPOOL_INITIAL_SIZE = 500;
+
+ public static final int CONSTANTPOOL_GROW_SIZE = 1000;
+
+ public ProxyCharArrayCache UTF8Cache;
+
+ ProxyCharArrayCache stringCache;
+
+ ProxyCharArrayCache classNameCache;
+
+ ProxyObjectCache fieldCache;
+
+ ProxyObjectCache methodCache;
+
+ ProxyObjectCache interfaceMethodCache;
+
+ ProxyNameAndTypeCache nameAndTypeCache;
+
+ public byte[] poolContent;
+
+ public int currentIndex;
+
+ public int currentOffset;
+
+ ProxyConstantPool(ProxyClassFile classFile) {
+ UTF8Cache = new ProxyCharArrayCache(UTF8_INITIAL_SIZE);
+ stringCache = new ProxyCharArrayCache(STRING_INITIAL_SIZE);
+ classNameCache = new ProxyCharArrayCache(CLASS_INITIAL_SIZE);
+ fieldCache = new ProxyObjectCache(FIELD_INITIAL_SIZE);
+ methodCache = new ProxyObjectCache(METHOD_INITIAL_SIZE);
+ interfaceMethodCache = new ProxyObjectCache(INTERFACE_INITIAL_SIZE);
+ nameAndTypeCache = new ProxyNameAndTypeCache(NAMEANDTYPE_INITIAL_SIZE);
+ poolContent = classFile.header;
+ currentOffset = classFile.headerOffset;
+ currentIndex = 1;
+ }
+
+ int literalIndex(char[] utf8Constant) {
+ int index;
+ if ((index = UTF8Cache.get(utf8Constant)) < 0) {
+ writeU1(Utf8Tag);
+ int savedCurrentOffset = currentOffset;
+ if (currentOffset + 2 >= poolContent.length) {
+ int length = poolContent.length;
+ System.arraycopy(poolContent, 0, (poolContent = new byte[length
+ + CONSTANTPOOL_GROW_SIZE]), 0, length);
+ }
+ currentOffset += 2;
+ int length = 0;
+ for (int i = 0; i < utf8Constant.length; i++) {
+ char current = utf8Constant[i];
+ if ((current >= 0x0001) && (current <= 0x007F)) {
+ // we only need one byte: ASCII table
+ writeU1(current);
+ length++;
+ } else if (current > 0x07FF) {
+ // we need 3 bytes
+ length += 3;
+ writeU1(0xE0 | ((current >> 12) & 0x0F)); // 0xE0 = 1110
+ // 0000
+ writeU1(0x80 | ((current >> 6) & 0x3F)); // 0x80 = 1000
+ // 0000
+ writeU1(0x80 | (current & 0x3F)); // 0x80 = 1000 0000
+ } else {
+ // we can be 0 or between 0x0080 and 0x07FF
+ // In that case we only need 2 bytes
+ length += 2;
+ writeU1(0xC0 | ((current >> 6) & 0x1F)); // 0xC0 = 1100
+ // 0000
+ writeU1(0x80 | (current & 0x3F)); // 0x80 = 1000 0000
+ }
+ }
+ if (length >= 65535) {
+ currentOffset = savedCurrentOffset - 1;
+ return -1;
+ }
+ index = UTF8Cache.put(utf8Constant, currentIndex++);
+ // Now we know the length that we have to write in the constant pool
+ // we use savedCurrentOffset to do that
+ poolContent[savedCurrentOffset] = (byte) (length >> 8);
+ poolContent[savedCurrentOffset + 1] = (byte) length;
+ }
+ return index;
+ }
+
+ int literalIndex(Field aField) {
+ int index;
+ if ((index = fieldCache.get(aField)) < 0) {
+ int classIndex = typeIndex(aField.getDeclaringClass().getName());
+ int nameAndTypeIndex = literalIndexForNameAndType(
+ literalIndex(aField.getName().toCharArray()),
+ literalIndex(ProxyClassFile.getConstantPoolName(aField
+ .getType())));
+ index = fieldCache.put(aField, currentIndex++);
+ writeU1(FieldRefTag);
+ writeU2(classIndex);
+ writeU2(nameAndTypeIndex);
+ }
+ return index;
+ }
+
+ int literalIndex(Constructor aMethod) {
+ int index;
+ if ((index = methodCache.get(aMethod)) < 0) {
+ int classIndex = typeIndex(aMethod.getDeclaringClass().getName());
+ int nameAndTypeIndex = literalIndexForNameAndType(
+ literalIndex(Init), literalIndex(ProxyClassFile
+ .getConstantPoolName(aMethod)));
+ index = methodCache.put(aMethod, currentIndex++);
+ writeU1(MethodRefTag);
+ writeU2(classIndex);
+ writeU2(nameAndTypeIndex);
+ }
+ return index;
+ }
+
+ int literalIndex(Method aMethod) {
+ int index;
+ if (aMethod.getDeclaringClass().isInterface()) {
+ if ((index = interfaceMethodCache.get(aMethod)) < 0) {
+ int classIndex = typeIndex(aMethod.getDeclaringClass()
+ .getName());
+ int nameAndTypeIndex = literalIndexForNameAndType(
+ literalIndex(aMethod.getName().toCharArray()),
+ literalIndex(ProxyClassFile
+ .getConstantPoolName(aMethod)));
+ index = interfaceMethodCache.put(aMethod, currentIndex++);
+ writeU1(InterfaceMethodRefTag);
+ writeU2(classIndex);
+ writeU2(nameAndTypeIndex);
+ }
+ } else if ((index = methodCache.get(aMethod)) < 0) {
+ int classIndex = typeIndex(aMethod.getDeclaringClass().getName());
+ int nameAndTypeIndex = literalIndexForNameAndType(
+ literalIndex(aMethod.getName().toCharArray()),
+ literalIndex(ProxyClassFile.getConstantPoolName(aMethod)));
+ index = methodCache.put(aMethod, currentIndex++);
+ writeU1(MethodRefTag);
+ writeU2(classIndex);
+ writeU2(nameAndTypeIndex);
+ }
+ return index;
+ }
+
+ int literalIndex(String stringConstant) {
+ int index;
+ char[] stringCharArray = stringConstant.toCharArray();
+ if ((index = stringCache.get(stringCharArray)) < 0) {
+ int stringIndex = literalIndex(stringCharArray);
+ index = stringCache.put(stringCharArray, currentIndex++);
+ writeU1(StringTag);
+ writeU2(stringIndex);
+ }
+ return index;
+ }
+
+ int literalIndexForLdc(char[] stringCharArray) {
+ int index;
+ if ((index = stringCache.get(stringCharArray)) < 0) {
+ int stringIndex;
+ if ((stringIndex = UTF8Cache.get(stringCharArray)) < 0) {
+ writeU1(Utf8Tag);
+ int savedCurrentOffset = currentOffset;
+ if (currentOffset + 2 >= poolContent.length) {
+ int length = poolContent.length;
+ System.arraycopy(poolContent, 0,
+ (poolContent = new byte[length
+ + CONSTANTPOOL_GROW_SIZE]), 0, length);
+ }
+ currentOffset += 2;
+ int length = 0;
+ for (int i = 0; i < stringCharArray.length; i++) {
+ char current = stringCharArray[i];
+ if ((current >= 0x0001) && (current <= 0x007F)) {
+ // we only need one byte: ASCII table
+ writeU1(current);
+ length++;
+ } else if (current > 0x07FF) {
+ // we need 3 bytes
+ length += 3;
+ writeU1(0xE0 | ((current >> 12) & 0x0F)); // 0xE0 =
+ // 1110 0000
+ writeU1(0x80 | ((current >> 6) & 0x3F)); // 0x80 =
+ // 1000 0000
+ writeU1(0x80 | (current & 0x3F)); // 0x80 = 1000 0000
+ } else {
+ // we can be 0 or between 0x0080 and 0x07FF
+ // In that case we only need 2 bytes
+ length += 2;
+ writeU1(0xC0 | ((current >> 6) & 0x1F)); // 0xC0 =
+ // 1100 0000
+ writeU1(0x80 | (current & 0x3F)); // 0x80 = 1000 0000
+ }
+ }
+ if (length >= 65535) {
+ currentOffset = savedCurrentOffset - 1;
+ return -1;
+ }
+ stringIndex = UTF8Cache.put(stringCharArray, currentIndex++);
+ // Now we know the length that we have to write in the constant
+ // pool
+ // we use savedCurrentOffset to do that
+ if (length > 65535)
+ return 0;
+ poolContent[savedCurrentOffset] = (byte) (length >> 8);
+ poolContent[savedCurrentOffset + 1] = (byte) length;
+ }
+ index = stringCache.put(stringCharArray, currentIndex++);
+ writeU1(StringTag);
+ writeU2(stringIndex);
+ }
+ return index;
+ }
+
+ private int literalIndexForNameAndType(int nameIndex, int typeIndex) {
+ int index;
+ int[] key = new int[] { nameIndex, typeIndex };
+ if ((index = nameAndTypeCache.get(key)) == -1) {
+ index = nameAndTypeCache.put(key, currentIndex++);
+ writeU1(NameAndTypeTag);
+ writeU2(nameIndex);
+ writeU2(typeIndex);
+ }
+ return index;
+ }
+
+ int typeIndex(String typeName) {
+ int index;
+ if (typeName.indexOf('.') != -1)
+ typeName = typeName.replace('.', '/');
+ char[] charArray = typeName.toCharArray();
+ if ((index = classNameCache.get(charArray)) < 0) {
+ int nameIndex = literalIndex(charArray);
+ index = classNameCache.put(charArray, currentIndex++);
+ writeU1(ClassTag);
+ writeU2(nameIndex);
+ }
+ return index;
+ }
+
+ private final void writeU1(int value) {
+ try {
+ poolContent[currentOffset++] = (byte) value;
+ } catch (IndexOutOfBoundsException e) {
+ // currentOffset has been ++ already (see the -1)
+ int length = poolContent.length;
+ System.arraycopy(poolContent, 0, (poolContent = new byte[length
+ + CONSTANTPOOL_GROW_SIZE]), 0, length);
+ poolContent[currentOffset - 1] = (byte) value;
+ }
+ }
+
+ private final void writeU2(int value) {
+ try {
+ poolContent[currentOffset++] = (byte) (value >> 8);
+ } catch (IndexOutOfBoundsException e) {
+ // currentOffset has been ++ already (see the -1)
+ int length = poolContent.length;
+ System.arraycopy(poolContent, 0, (poolContent = new byte[length
+ + CONSTANTPOOL_GROW_SIZE]), 0, length);
+ poolContent[currentOffset - 1] = (byte) (value >> 8);
+ }
+ try {
+ poolContent[currentOffset++] = (byte) value;
+ } catch (IndexOutOfBoundsException e) {
+ // currentOffset has been ++ already (see the -1)
+ int length = poolContent.length;
+ System.arraycopy(poolContent, 0, (poolContent = new byte[length
+ + CONSTANTPOOL_GROW_SIZE]), 0, length);
+ poolContent[currentOffset - 1] = (byte) value;
+ }
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyConstants.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyConstants.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyConstants.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyConstants.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,462 @@
+/* Copyright 2001, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.oti.lang.reflect;
+
+
+interface ProxyConstants {
+ final char[] CodeName = new char[] { 'C', 'o', 'd', 'e' };
+
+ final char[] ExceptionsName = new char[] { 'E', 'x', 'c', 'e', 'p', 't',
+ 'i', 'o', 'n', 's' };
+
+ final char[] Init = new char[] { '<', 'i', 'n', 'i', 't', '>' };
+
+ final int AccPublic = 0x0001;
+
+ final int AccPrivate = 0x0002;
+
+ final int AccProtected = 0x0004;
+
+ final int AccStatic = 0x0008;
+
+ final int AccFinal = 0x0010;
+
+ final int AccSuper = 0x0020;
+
+ final int Utf8Tag = 1;
+
+ final int IntegerTag = 3;
+
+ final int FloatTag = 4;
+
+ final int LongTag = 5;
+
+ final int DoubleTag = 6;
+
+ final int ClassTag = 7;
+
+ final int StringTag = 8;
+
+ final int FieldRefTag = 9;
+
+ final int MethodRefTag = 10;
+
+ final int InterfaceMethodRefTag = 11;
+
+ final int NameAndTypeTag = 12;
+
+ final int OPC_nop = 0;
+
+ final int OPC_aconst_null = 1;
+
+ final int OPC_iconst_m1 = 2;
+
+ final int OPC_iconst_0 = 3;
+
+ final int OPC_iconst_1 = 4;
+
+ final int OPC_iconst_2 = 5;
+
+ final int OPC_iconst_3 = 6;
+
+ final int OPC_iconst_4 = 7;
+
+ final int OPC_iconst_5 = 8;
+
+ final int OPC_lconst_0 = 9;
+
+ final int OPC_lconst_1 = 10;
+
+ final int OPC_fconst_0 = 11;
+
+ final int OPC_fconst_1 = 12;
+
+ final int OPC_fconst_2 = 13;
+
+ final int OPC_dconst_0 = 14;
+
+ final int OPC_dconst_1 = 15;
+
+ final int OPC_bipush = 16;
+
+ final int OPC_sipush = 17;
+
+ final int OPC_ldc = 18;
+
+ final int OPC_ldc_w = 19;
+
+ final int OPC_ldc2_w = 20;
+
+ final int OPC_iload = 21;
+
+ final int OPC_lload = 22;
+
+ final int OPC_fload = 23;
+
+ final int OPC_dload = 24;
+
+ final int OPC_aload = 25;
+
+ final int OPC_iload_0 = 26;
+
+ final int OPC_iload_1 = 27;
+
+ final int OPC_iload_2 = 28;
+
+ final int OPC_iload_3 = 29;
+
+ final int OPC_lload_0 = 30;
+
+ final int OPC_lload_1 = 31;
+
+ final int OPC_lload_2 = 32;
+
+ final int OPC_lload_3 = 33;
+
+ final int OPC_fload_0 = 34;
+
+ final int OPC_fload_1 = 35;
+
+ final int OPC_fload_2 = 36;
+
+ final int OPC_fload_3 = 37;
+
+ final int OPC_dload_0 = 38;
+
+ final int OPC_dload_1 = 39;
+
+ final int OPC_dload_2 = 40;
+
+ final int OPC_dload_3 = 41;
+
+ final int OPC_aload_0 = 42;
+
+ final int OPC_aload_1 = 43;
+
+ final int OPC_aload_2 = 44;
+
+ final int OPC_aload_3 = 45;
+
+ final int OPC_iaload = 46;
+
+ final int OPC_laload = 47;
+
+ final int OPC_faload = 48;
+
+ final int OPC_daload = 49;
+
+ final int OPC_aaload = 50;
+
+ final int OPC_baload = 51;
+
+ final int OPC_caload = 52;
+
+ final int OPC_saload = 53;
+
+ final int OPC_istore = 54;
+
+ final int OPC_lstore = 55;
+
+ final int OPC_fstore = 56;
+
+ final int OPC_dstore = 57;
+
+ final int OPC_astore = 58;
+
+ final int OPC_istore_0 = 59;
+
+ final int OPC_istore_1 = 60;
+
+ final int OPC_istore_2 = 61;
+
+ final int OPC_istore_3 = 62;
+
+ final int OPC_lstore_0 = 63;
+
+ final int OPC_lstore_1 = 64;
+
+ final int OPC_lstore_2 = 65;
+
+ final int OPC_lstore_3 = 66;
+
+ final int OPC_fstore_0 = 67;
+
+ final int OPC_fstore_1 = 68;
+
+ final int OPC_fstore_2 = 69;
+
+ final int OPC_fstore_3 = 70;
+
+ final int OPC_dstore_0 = 71;
+
+ final int OPC_dstore_1 = 72;
+
+ final int OPC_dstore_2 = 73;
+
+ final int OPC_dstore_3 = 74;
+
+ final int OPC_astore_0 = 75;
+
+ final int OPC_astore_1 = 76;
+
+ final int OPC_astore_2 = 77;
+
+ final int OPC_astore_3 = 78;
+
+ final int OPC_iastore = 79;
+
+ final int OPC_lastore = 80;
+
+ final int OPC_fastore = 81;
+
+ final int OPC_dastore = 82;
+
+ final int OPC_aastore = 83;
+
+ final int OPC_bastore = 84;
+
+ final int OPC_castore = 85;
+
+ final int OPC_sastore = 86;
+
+ final int OPC_pop = 87;
+
+ final int OPC_pop2 = 88;
+
+ final int OPC_dup = 89;
+
+ final int OPC_dup_x1 = 90;
+
+ final int OPC_dup_x2 = 91;
+
+ final int OPC_dup2 = 92;
+
+ final int OPC_dup2_x1 = 93;
+
+ final int OPC_dup2_x2 = 94;
+
+ final int OPC_swap = 95;
+
+ final int OPC_iadd = 96;
+
+ final int OPC_ladd = 97;
+
+ final int OPC_fadd = 98;
+
+ final int OPC_dadd = 99;
+
+ final int OPC_isub = 100;
+
+ final int OPC_lsub = 101;
+
+ final int OPC_fsub = 102;
+
+ final int OPC_dsub = 103;
+
+ final int OPC_imul = 104;
+
+ final int OPC_lmul = 105;
+
+ final int OPC_fmul = 106;
+
+ final int OPC_dmul = 107;
+
+ final int OPC_idiv = 108;
+
+ final int OPC_ldiv = 109;
+
+ final int OPC_fdiv = 110;
+
+ final int OPC_ddiv = 111;
+
+ final int OPC_irem = 112;
+
+ final int OPC_lrem = 113;
+
+ final int OPC_frem = 114;
+
+ final int OPC_drem = 115;
+
+ final int OPC_ineg = 116;
+
+ final int OPC_lneg = 117;
+
+ final int OPC_fneg = 118;
+
+ final int OPC_dneg = 119;
+
+ final int OPC_ishl = 120;
+
+ final int OPC_lshl = 121;
+
+ final int OPC_ishr = 122;
+
+ final int OPC_lshr = 123;
+
+ final int OPC_iushr = 124;
+
+ final int OPC_lushr = 125;
+
+ final int OPC_iand = 126;
+
+ final int OPC_land = 127;
+
+ final int OPC_ior = 128;
+
+ final int OPC_lor = 129;
+
+ final int OPC_ixor = 130;
+
+ final int OPC_lxor = 131;
+
+ final int OPC_iinc = 132;
+
+ final int OPC_i2l = 133;
+
+ final int OPC_i2f = 134;
+
+ final int OPC_i2d = 135;
+
+ final int OPC_l2i = 136;
+
+ final int OPC_l2f = 137;
+
+ final int OPC_l2d = 138;
+
+ final int OPC_f2i = 139;
+
+ final int OPC_f2l = 140;
+
+ final int OPC_f2d = 141;
+
+ final int OPC_d2i = 142;
+
+ final int OPC_d2l = 143;
+
+ final int OPC_d2f = 144;
+
+ final int OPC_i2b = 145;
+
+ final int OPC_i2c = 146;
+
+ final int OPC_i2s = 147;
+
+ final int OPC_lcmp = 148;
+
+ final int OPC_fcmpl = 149;
+
+ final int OPC_fcmpg = 150;
+
+ final int OPC_dcmpl = 151;
+
+ final int OPC_dcmpg = 152;
+
+ final int OPC_ifeq = 153;
+
+ final int OPC_ifne = 154;
+
+ final int OPC_iflt = 155;
+
+ final int OPC_ifge = 156;
+
+ final int OPC_ifgt = 157;
+
+ final int OPC_ifle = 158;
+
+ final int OPC_if_icmpeq = 159;
+
+ final int OPC_if_icmpne = 160;
+
+ final int OPC_if_icmplt = 161;
+
+ final int OPC_if_icmpge = 162;
+
+ final int OPC_if_icmpgt = 163;
+
+ final int OPC_if_icmple = 164;
+
+ final int OPC_if_acmpeq = 165;
+
+ final int OPC_if_acmpne = 166;
+
+ final int OPC_goto = 167;
+
+ final int OPC_jsr = 168;
+
+ final int OPC_ret = 169;
+
+ final int OPC_tableswitch = 170;
+
+ final int OPC_lookupswitch = 171;
+
+ final int OPC_ireturn = 172;
+
+ final int OPC_lreturn = 173;
+
+ final int OPC_freturn = 174;
+
+ final int OPC_dreturn = 175;
+
+ final int OPC_areturn = 176;
+
+ final int OPC_return = 177;
+
+ final int OPC_getstatic = 178;
+
+ final int OPC_putstatic = 179;
+
+ final int OPC_getfield = 180;
+
+ final int OPC_putfield = 181;
+
+ final int OPC_invokevirtual = 182;
+
+ final int OPC_invokespecial = 183;
+
+ final int OPC_invokestatic = 184;
+
+ final int OPC_invokeinterface = 185;
+
+ final int OPC_new = 187;
+
+ final int OPC_newarray = 188;
+
+ final int OPC_anewarray = 189;
+
+ final int OPC_arraylength = 190;
+
+ final int OPC_athrow = 191;
+
+ final int OPC_checkcast = 192;
+
+ final int OPC_instanceof = 193;
+
+ final int OPC_monitorenter = 194;
+
+ final int OPC_monitorexit = 195;
+
+ final int OPC_wide = 196;
+
+ final int OPC_multianewarray = 197;
+
+ final int OPC_ifnull = 198;
+
+ final int OPC_ifnonnull = 199;
+
+ final int OPC_goto_w = 200;
+
+ final int OPC_jsr_w = 201;
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyMethod.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyMethod.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyMethod.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyMethod.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,112 @@
+/* Copyright 2001, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.oti.lang.reflect;
+
+
+import java.lang.reflect.Method;
+
+class ProxyMethod {
+ Method method;
+
+ Class[] commonExceptions;
+
+ ProxyMethod(Method method) {
+ this.method = method;
+ this.commonExceptions = method.getExceptionTypes();
+ }
+
+ Class[] getCheckedExceptions() {
+ Class[] newExceptions = (Class[]) commonExceptions.clone();
+ int cLength = newExceptions.length;
+ for (int c = 0, cL = cLength; c < cL; c++) {
+ Class ex = newExceptions[c];
+ if (Throwable.class == ex)
+ return new Class[0]; // if Throwable is included then treat
+ // as if no exceptions are checked
+ if (Error.class.isAssignableFrom(ex)
+ || RuntimeException.class.isAssignableFrom(ex)) {
+ newExceptions[c] = null;
+ cLength--;
+ }
+ }
+
+ // All errors & runtime exceptions are passed back without being
+ // wrappered
+ Class[] result = new Class[cLength + 2];
+ int index = 0;
+ result[index++] = Error.class;
+ result[index++] = RuntimeException.class;
+ for (int i = 0, length = newExceptions.length; i < length; i++) {
+ Class ex = newExceptions[i];
+ if (ex != null)
+ result[index++] = ex;
+ }
+ return result;
+ }
+
+ boolean matchMethod(Method otherMethod) {
+ if (!method.getName().equals(otherMethod.getName()))
+ return false;
+
+ Class[] params1 = method.getParameterTypes();
+ Class[] params2 = otherMethod.getParameterTypes();
+ int p = params1.length;
+ if (p != params2.length)
+ return false;
+ while (--p >= 0)
+ if (params1[p] != params2[p])
+ return false;
+
+ if (method.getReturnType() != otherMethod.getReturnType())
+ throw new IllegalArgumentException(com.ibm.oti.util.Msg.getString(
+ "K00f2", method.getName()));
+ if (commonExceptions.length != 0) {
+ Class[] otherExceptions = otherMethod.getExceptionTypes();
+ if (otherExceptions.length == 0) {
+ commonExceptions = otherExceptions;
+ } else {
+ int cLength = commonExceptions.length;
+ nextException: for (int c = 0, cL = cLength, oL = otherExceptions.length; c < cL; c++) {
+ Class cException = commonExceptions[c];
+ for (int o = 0; o < oL; o++) {
+ Class oException = otherExceptions[o];
+ if (cException == oException)
+ continue nextException;
+ if (oException.isAssignableFrom(cException))
+ continue nextException; // cException is a subclass
+ if (cException.isAssignableFrom(oException)) {
+ // oException is a subclass, keep it instead
+ commonExceptions[c] = cException = oException;
+ continue nextException;
+ }
+ }
+ commonExceptions[c] = null;
+ cLength--;
+ }
+ if (cLength != commonExceptions.length) {
+ Class[] newExceptions = new Class[cLength];
+ for (int i = 0, j = 0, length = commonExceptions.length; i < length; i++) {
+ Class ex = commonExceptions[i];
+ if (ex != null)
+ newExceptions[j++] = ex;
+ }
+ commonExceptions = newExceptions;
+ }
+ }
+ }
+ return true;
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyNameAndTypeCache.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyNameAndTypeCache.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyNameAndTypeCache.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyNameAndTypeCache.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,96 @@
+/* Copyright 2001, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.oti.lang.reflect;
+
+
+class ProxyNameAndTypeCache {
+ int[][] keyTable;
+
+ int[] valueTable;
+
+ int elementSize;
+
+ int threshold;
+
+ ProxyNameAndTypeCache(int initialCapacity) {
+ if (initialCapacity < 13)
+ initialCapacity = 13;
+ this.elementSize = 0;
+ this.threshold = (int) (initialCapacity * 0.66f);
+ this.keyTable = new int[initialCapacity][];
+ this.valueTable = new int[initialCapacity];
+ }
+
+ int get(int[] key) {
+ int index = hashCode(key);
+ while (keyTable[index] != null) {
+ if (keyTable[index][0] == key[0] && keyTable[index][1] == key[1])
+ return valueTable[index];
+ index = (index + 1) % keyTable.length;
+ }
+ return -1;
+ }
+
+ int hashCode(int[] key) {
+ return (key[0] + key[1]) % keyTable.length;
+ }
+
+ int put(int[] key, int value) {
+ int index = hashCode(key);
+ while (keyTable[index] != null) {
+ if (keyTable[index][0] == key[0] && keyTable[index][1] == key[1])
+ return valueTable[index] = value;
+ index = (index + 1) % keyTable.length;
+ }
+ keyTable[index] = key;
+ valueTable[index] = value;
+
+ // assumes the threshold is never equal to the size of the table
+ if (++elementSize > threshold)
+ rehash();
+ return value;
+ }
+
+ private void rehash() {
+ ProxyNameAndTypeCache newHashtable = new ProxyNameAndTypeCache(
+ keyTable.length * 2);
+ for (int i = keyTable.length; --i >= 0;)
+ if (keyTable[i] != null)
+ newHashtable.put(keyTable[i], valueTable[i]);
+
+ this.keyTable = newHashtable.keyTable;
+ this.valueTable = newHashtable.valueTable;
+ this.threshold = newHashtable.threshold;
+ }
+
+ int size() {
+ return elementSize;
+ }
+
+ public String toString() {
+ int max = size();
+ StringBuffer buf = new StringBuffer();
+ buf.append("{");
+ for (int i = 0; i < max; ++i) {
+ if (keyTable[i] != null)
+ buf.append(keyTable[i]).append("->").append(valueTable[i]);
+ if (i < max)
+ buf.append(", ");
+ }
+ buf.append("}");
+ return buf.toString();
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyObjectCache.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyObjectCache.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyObjectCache.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/lang/reflect/ProxyObjectCache.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,96 @@
+/* Copyright 2001, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.oti.lang.reflect;
+
+
+class ProxyObjectCache {
+ Object keyTable[];
+
+ int valueTable[];
+
+ int elementSize;
+
+ int threshold;
+
+ ProxyObjectCache(int initialCapacity) {
+ if (initialCapacity < 13)
+ initialCapacity = 13;
+ this.elementSize = 0;
+ this.threshold = (int) (initialCapacity * 0.66f);
+ this.keyTable = new Object[initialCapacity];
+ this.valueTable = new int[initialCapacity];
+ }
+
+ int get(Object key) {
+ int index = hashCode(key);
+ while (keyTable[index] != null) {
+ if (keyTable[index].equals(key))
+ return valueTable[index];
+ index = (index + 1) % keyTable.length;
+ }
+ return -1;
+ }
+
+ int hashCode(Object key) {
+ return (key.hashCode() & 0x7FFFFFFF) % keyTable.length;
+ }
+
+ int put(Object key, int value) {
+ int index = hashCode(key);
+ while (keyTable[index] != null) {
+ if (keyTable[index].equals(key))
+ return valueTable[index] = value;
+ index = (index + 1) % keyTable.length;
+ }
+ keyTable[index] = key;
+ valueTable[index] = value;
+
+ // assumes the threshold is never equal to the size of the table
+ if (++elementSize > threshold)
+ rehash();
+ return value;
+ }
+
+ private void rehash() {
+ ProxyObjectCache newHashtable = new ProxyObjectCache(
+ keyTable.length * 2);
+ for (int i = keyTable.length; --i >= 0;)
+ if (keyTable[i] != null)
+ newHashtable.put(keyTable[i], valueTable[i]);
+
+ this.keyTable = newHashtable.keyTable;
+ this.valueTable = newHashtable.valueTable;
+ this.threshold = newHashtable.threshold;
+ }
+
+ int size() {
+ return elementSize;
+ }
+
+ public String toString() {
+ int max = size();
+ StringBuffer buf = new StringBuffer();
+ buf.append("{");
+ for (int i = 0; i < max; ++i) {
+ if (keyTable[i] != null)
+ buf.append(keyTable[i]).append("->").append(valueTable[i]);
+ if (i < max)
+ buf.append(", ");
+ }
+ buf.append("}");
+ return buf.toString();
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/locale/Country.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/locale/Country.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/locale/Country.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/locale/Country.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,267 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+
+package com.ibm.oti.locale;
+
+public class Country extends java.util.ListResourceBundle {
+
+protected Object[][] getContents() {
+ Object [][] contents = {
+ {"AF", "Afghanistan"},
+ {"AL", "Albania"},
+ {"DZ", "Algeria"},
+ {"AS", "American Samoa"},
+ {"AD", "Andorra"},
+ {"AO", "Angola"},
+ {"AI", "Anguilla"},
+ {"AQ", "Antarctica"},
+ {"AG", "Antigua and Barbuda"},
+ {"AR", "Argentina"},
+ {"AM", "Armenia"},
+ {"AW", "Aruba"},
+ {"AU", "Australia"},
+ {"AT", "Austria"},
+ {"AZ", "Azerbaijan"},
+ {"BS", "Bahamas"},
+ {"BH", "Bahrain"},
+ {"BD", "Bangladesh"},
+ {"BB", "Barbados"},
+ {"BY", "Belarus"},
+ {"BE", "Belgium"},
+ {"BZ", "Belize"},
+ {"BJ", "Benin"},
+ {"BM", "Bermuda"},
+ {"BT", "Bhutan"},
+ {"BO", "Bolivia"},
+ {"BA", "Bosnia and Herzegovina"},
+ {"BW", "Botswana"},
+ {"BV", "Bouvet Island"},
+ {"BR", "Brazil"},
+ {"IO", "British Indian Ocean Territory"},
+ {"BN", "Brunei"},
+ {"BG", "Bulgaria"},
+ {"BF", "Burkina Faso"},
+ {"BI", "Burundi"},
+ {"KH", "Cambodia"},
+ {"CM", "Cameroon"},
+ {"CA", "Canada"},
+ {"CV", "Cape Verde"},
+ {"KY", "Cayman Islands"},
+ {"CF", "Central African Republic"},
+ {"TD", "Chad"},
+ {"CL", "Chile"},
+ {"CN", "China"},
+ {"CX", "Christmas Island"},
+ {"CC", "Cocos (Keeling) Islands"},
+ {"CO", "Colombia"},
+ {"KM", "Comoros"},
+ {"CG", "Congo"},
+ {"CK", "Cook Islands"},
+ {"CR", "Costa Rica"},
+ {"CS", "Serbia and Montenegro",},
+ {"CI", "C\u00f4te d'Ivoire"},
+ {"HR", "Croatia"},
+ {"CU", "Cuba"},
+ {"CY", "Cyprus"},
+ {"CZ", "Czech Republic"},
+ {"DK", "Denmark"},
+ {"DJ", "Djibouti"},
+ {"DM", "Dominica"},
+ {"DO", "Dominican Republic"},
+ {"TP", "East Timor"},
+ {"EC", "Ecuador"},
+ {"EG", "Egypt"},
+ {"SV", "El Salvador"},
+ {"GQ", "Equatorial Guinea"},
+ {"ER", "Eritrea"},
+ {"EE", "Estonia"},
+ {"ET", "Ethiopia"},
+ {"FK", "Falkland Islands (Malvinas)"},
+ {"FO", "Faroe Islands"},
+ {"FJ", "Fiji"},
+ {"FI", "Finland"},
+ {"FR", "France"},
+ {"FX", "France, Metropolitan"},
+ {"GF", "French Guiana"},
+ {"PF", "French Polynesia"},
+ {"TF", "French Southern Territories"},
+ {"GA", "Gabon"},
+ {"GM", "Gambia"},
+ {"GE", "Georgia"},
+ {"DE", "Germany"},
+ {"GH", "Ghana"},
+ {"GI", "Gibraltar"},
+ {"GR", "Greece"},
+ {"GL", "Greenland"},
+ {"GD", "Grenada"},
+ {"GP", "Guadeloupe"},
+ {"GU", "Guam"},
+ {"GT", "Guatemala"},
+ {"GN", "Guinea"},
+ {"GW", "Guinea-Bissau"},
+ {"GY", "Guyana"},
+ {"HT", "Haiti"},
+ {"HM", "Heard and Mc Donald Islands"},
+ {"HN", "Honduras"},
+ {"HK", "Hong Kong S.A.R."},
+ {"HU", "Hungary"},
+ {"IS", "Iceland"},
+ {"IN", "India"},
+ {"ID", "Indonesia"},
+ {"IR", "Iran"},
+ {"IQ", "Iraq"},
+ {"IE", "Ireland"},
+ {"IL", "Israel"},
+ {"IT", "Italy"},
+ {"JM", "Jamaica"},
+ {"JP", "Japan"},
+ {"JO", "Jordan"},
+ {"KZ", "Kazakhstan"},
+ {"KE", "Kenya"},
+ {"KI", "Kiribati"},
+ {"KP", "North Korea"},
+ {"KR", "South Korea"},
+ {"KW", "Kuwait"},
+ {"KG", "Kyrgyzstan"},
+ {"LA", "Laos"},
+ {"LV", "Latvia"},
+ {"LB", "Lebanon"},
+ {"LS", "Lesotho"},
+ {"LR", "Liberia"},
+ {"LY", "Libya"},
+ {"LI", "Liechtenstein"},
+ {"LT", "Lithuania"},
+ {"LU", "Luxembourg"},
+ {"MO", "Macao S.A.R."},
+ {"MK", "Macedonia"},
+ {"MG", "Madagascar"},
+ {"MW", "Malawi"},
+ {"MY", "Malaysia"},
+ {"MV", "Maldives"},
+ {"ML", "Mali"},
+ {"MT", "Malta"},
+ {"MH", "Marshall Islands"},
+ {"MQ", "Martinique"},
+ {"MR", "Mauritania"},
+ {"MU", "Mauritius"},
+ {"YT", "Mayotte"},
+ {"MX", "Mexico"},
+ {"FM", "Micronesia"},
+ {"MD", "Moldova"},
+ {"MC", "Monaco"},
+ {"MN", "Mongolia"},
+ {"MS", "Montserrat"},
+ {"MA", "Morocco"},
+ {"MZ", "Mozambique"},
+ {"MM", "Myanmar"},
+ {"NA", "Namibia"},
+ {"NR", "Nauru"},
+ {"NP", "Nepal"},
+ {"NL", "Netherlands"},
+ {"AN", "Netherlands Antilles"},
+ {"NC", "New Caledonia"},
+ {"NZ", "New Zealand"},
+ {"NI", "Nicaragua"},
+ {"NE", "Niger"},
+ {"NG", "Nigeria"},
+ {"NU", "Niue"},
+ {"NF", "Norfolk Island"},
+ {"MP", "Northern Mariana Islands"},
+ {"NO", "Norway"},
+ {"OM", "Oman"},
+ {"PK", "Pakistan"},
+ {"PW", "Palau"},
+ {"PA", "Panama"},
+ {"PG", "Papua New Guinea"},
+ {"PY", "Paraguay"},
+ {"PE", "Peru"},
+ {"PH", "Philippines"},
+ {"PN", "Pitcairn"},
+ {"PL", "Poland"},
+ {"PT", "Portugal"},
+ {"PR", "Puerto Rico"},
+ {"QA", "Qatar"},
+ {"RE", "Reunion"},
+ {"RO", "Romania"},
+ {"RU", "Russia"},
+ {"RW", "Rwanda"},
+ {"KN", "Saint Kitts and Nevis"},
+ {"LC", "Saint Lucia"},
+ {"VC", "Saint Vincent and The Grenadines"},
+ {"WS", "Samoa"},
+ {"SM", "San Marino"},
+ {"ST", "Sao Tome and Principe"},
+ {"SA", "Saudi Arabia"},
+ {"SN", "Senegal"},
+ {"SC", "Seychelles"},
+ {"SL", "Sierra Leone"},
+ {"SG", "Singapore"},
+ {"SK", "Slovakia"},
+ {"SI", "Slovenia"},
+ {"SB", "Solomon Islands"},
+ {"SO", "Somalia"},
+ {"ZA", "South Africa"},
+ {"GS", "South Georgia and The South Sandwich Islands"},
+ {"ES", "Spain"},
+ {"LK", "Sri Lanka"},
+ {"SH", "St. Helena"},
+ {"PM", "St. Pierre and Miquelon"},
+ {"SD", "Sudan"},
+ {"SR", "Suriname"},
+ {"SJ", "Svalbard and Jan Mayen Islands"},
+ {"SZ", "Swaziland"},
+ {"SE", "Sweden"},
+ {"CH", "Switzerland"},
+ {"SY", "Syria"},
+ {"TW", "Taiwan"},
+ {"TJ", "Tajikistan"},
+ {"TZ", "Tanzania"},
+ {"TH", "Thailand"},
+ {"TG", "Togo"},
+ {"TK", "Tokelau"},
+ {"TO", "Tonga"},
+ {"TT", "Trinidad and Tobago"},
+ {"TN", "Tunisia"},
+ {"TR", "Turkey"},
+ {"TM", "Turkmenistan"},
+ {"TC", "Turks and Caicos Islands"},
+ {"TV", "Tuvalu"},
+ {"UG", "Uganda"},
+ {"UA", "Ukraine"},
+ {"AE", "United Arab Emirates"},
+ {"GB", "United Kingdom"},
+ {"US", "United States"},
+ {"UM", "United States Minor Outlying Islands"},
+ {"UY", "Uruguay"},
+ {"UZ", "Uzbekistan"},
+ {"VU", "Vanuatu"},
+ {"VA", "Vatican"},
+ {"VE", "Venezuela"},
+ {"VN", "Vietnam"},
+ {"VG", "British Virgin Islands"},
+ {"VI", "U.S. Virgin Islands"},
+ {"WF", "Wallis and Futuna Islands"},
+ {"EH", "Western Sahara"},
+ {"YE", "Yemen"},
+ {"YU", "Yugoslavia"},
+ {"ZR", "Zaire"},
+ {"ZM", "Zambia"},
+ {"ZW", "Zimbabwe"},
+ };
+ return contents;
+}
+}