src/classes/Makefile.
* m4/classpath.m4 (AC_CHECK_WITH_CLASSPATH_CLASSES): Fixed
BOOTCLASSPATH.
* src/Makefile.am (DIST_SUBDIRS): Removed lib, added classes.
(SUBDIRS): Likewise.
* src/classes/Makefile.am,
src/classes/cldc1.1/com/sun/cldchi/jvm/FileDescriptor.java,
src/classes/gnu/gnu/classpath/VMStackWalker.java,
src/classes/gnu/gnu/classpath/VMSystemProperties.java,
src/classes/gnu/gnu/java/lang/management/VMMemoryMXBeanImpl.java,
src/classes/gnu/gnu/java/lang/management/VMRuntimeMXBeanImpl.java,
src/classes/gnu/java/lang/VMClassLoader.java,
src/classes/gnu/java/lang/VMString.java,
src/classes/gnu/java/lang/VMThread.java,
src/classes/gnu/java/lang/reflect/Constructor.java,
src/classes/gnu/java/lang/reflect/Field.java,
src/classes/gnu/java/lang/reflect/Method.java,
src/classes/gnu/java/security/VMAccessController.java,
src/classes/gnu/sun/misc/Unsafe.java,
src/classes/gnu/sun/reflect/ConstantPool.java,
src/classes/gnu/sun/reflect/annotation/AnnotationParser.java,
src/classes/gnu/sun/reflect/annotation/AnnotationType.java,
src/classes/gnu/sun/reflect/annotation/AnnotationTypeMismatchExceptionProxy.java,
src/classes/gnu/sun/reflect/annotation/EnumConstantNotPresentExceptionProxy.java,
src/classes/gnu/sun/reflect/annotation/ExceptionProxy.java,
src/classes/gnu/sun/reflect/annotation/TypeNotPresentExceptionProxy.java,
src/native/include/Makefile.am: Moved from lib.
* src/lib/Makefile.am,
src/lib/cldc1.1/com/sun/cldchi/jvm/FileDescriptor.java,
src/lib/gnu/gnu/classpath/VMStackWalker.java,
src/lib/gnu/gnu/classpath/VMSystemProperties.java,
src/lib/gnu/gnu/java/lang/management/VMMemoryMXBeanImpl.java,
src/lib/gnu/gnu/java/lang/management/VMRuntimeMXBeanImpl.java,
src/lib/gnu/java/lang/VMClassLoader.java,
src/lib/gnu/java/lang/VMString.java,
src/lib/gnu/java/lang/VMThread.java,
src/lib/gnu/java/lang/reflect/Constructor.java,
src/lib/gnu/java/lang/reflect/Field.java,
src/lib/gnu/java/lang/reflect/Method.java,
src/lib/gnu/java/security/VMAccessController.java,
src/lib/gnu/sun/misc/Unsafe.java,
src/lib/gnu/sun/reflect/ConstantPool.java,
src/lib/gnu/sun/reflect/annotation/AnnotationParser.java,
src/lib/gnu/sun/reflect/annotation/AnnotationType.java,
src/lib/gnu/sun/reflect/annotation/AnnotationTypeMismatchExceptionProxy.java,
src/lib/gnu/sun/reflect/annotation/EnumConstantNotPresentExceptionProxy.java,
src/lib/gnu/sun/reflect/annotation/ExceptionProxy.java,
src/lib/gnu/sun/reflect/annotation/TypeNotPresentExceptionProxy.java:
Moved to lib.
--HG--
rename : src/lib/Makefile.am => src/classes/Makefile.am
rename : src/lib/cldc1.1/com/sun/cldchi/jvm/FileDescriptor.java => src/classes/cldc1.1/com/sun/cldchi/jvm/FileDescriptor.java
rename : src/lib/gnu/gnu/classpath/VMStackWalker.java => src/classes/gnu/gnu/classpath/VMStackWalker.java
rename : src/lib/gnu/gnu/classpath/VMSystemProperties.java => src/classes/gnu/gnu/classpath/VMSystemProperties.java
rename : src/lib/gnu/gnu/java/lang/management/VMMemoryMXBeanImpl.java => src/classes/gnu/gnu/java/lang/management/VMMemoryMXBeanImpl.java
rename : src/lib/gnu/gnu/java/lang/management/VMRuntimeMXBeanImpl.java => src/classes/gnu/gnu/java/lang/management/VMRuntimeMXBeanImpl.java
rename : src/lib/gnu/java/lang/VMClassLoader.java => src/classes/gnu/java/lang/VMClassLoader.java
rename : src/lib/gnu/java/lang/VMString.java => src/classes/gnu/java/lang/VMString.java
rename : src/lib/gnu/java/lang/VMThread.java => src/classes/gnu/java/lang/VMThread.java
rename : src/lib/gnu/java/lang/reflect/Constructor.java => src/classes/gnu/java/lang/reflect/Constructor.java
rename : src/lib/gnu/java/lang/reflect/Field.java => src/classes/gnu/java/lang/reflect/Field.java
rename : src/lib/gnu/java/lang/reflect/Method.java => src/classes/gnu/java/lang/reflect/Method.java
rename : src/lib/gnu/java/security/VMAccessController.java => src/classes/gnu/java/security/VMAccessController.java
rename : src/lib/gnu/sun/misc/Unsafe.java => src/classes/gnu/sun/misc/Unsafe.java
rename : src/lib/gnu/sun/reflect/ConstantPool.java => src/classes/gnu/sun/reflect/ConstantPool.java
rename : src/lib/gnu/sun/reflect/annotation/AnnotationParser.java => src/classes/gnu/sun/reflect/annotation/AnnotationParser.java
rename : src/lib/gnu/sun/reflect/annotation/AnnotationType.java => src/classes/gnu/sun/reflect/annotation/AnnotationType.java
rename : src/lib/gnu/sun/reflect/annotation/AnnotationTypeMismatchExceptionProxy.java => src/classes/gnu/sun/reflect/annotation/AnnotationTypeMismatchExceptionProxy.java
rename : src/lib/gnu/sun/reflect/annotation/EnumConstantNotPresentExceptionProxy.java => src/classes/gnu/sun/reflect/annotation/EnumConstantNotPresentExceptionProxy.java
rename : src/lib/gnu/sun/reflect/annotation/ExceptionProxy.java => src/classes/gnu/sun/reflect/annotation/ExceptionProxy.java
rename : src/lib/gnu/sun/reflect/annotation/TypeNotPresentExceptionProxy.java => src/classes/gnu/sun/reflect/annotation/TypeNotPresentExceptionProxy.java
[src/Makefile]
[src/cacao/Makefile]
[src/cacaoh/Makefile]
+ [src/classes/Makefile]
[src/fdlibm/Makefile]
- [src/lib/Makefile]
[src/mm/Makefile]
[src/mm/cacao-gc/Makefile]
[src/native/Makefile]
dnl define BOOTCLASSPATH for Makefiles
case "${WITH_CLASSPATH}" in
cldc1.1 | gnu)
- BOOTCLASSPATH="\$(top_builddir)/src/lib/classes:\$(CLASSPATH_CLASSES)"
+ BOOTCLASSPATH="\$(top_builddir)/src/classes/classes:\$(CLASSPATH_CLASSES)"
;;
*)
BOOTCLASSPATH="\$(CLASSPATH_CLASSES)"
DIST_SUBDIRS = \
cacao \
cacaoh \
+ classes \
fdlibm \
- lib \
mm \
native \
scripts \
toolbox \
vmcore \
$(CACAOH_DIR) \
- lib \
+ classes \
native \
fdlibm \
mm \
--- /dev/null
+## src/lib/Makefile.am
+##
+## Copyright (C) 1996-2005, 2006, 2007, 2008
+## CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+##
+## This file is part of CACAO.
+##
+## This program is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 2, or (at
+## your option) any later version.
+##
+## This program is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+## 02110-1301, USA.
+
+
+EXTRA_DIST = \
+ $(VM_JAVA_FILES_GNU) \
+ $(VM_JAVA_FILES_GNU_ANNOTATIONS) \
+ $(VM_JAVA_FILES_CLDC1_1)
+
+CLEANFILES = vm.zip
+
+VM_JAVA_FILES_GNU = \
+ $(top_srcdir)/src/classes/gnu/gnu/classpath/VMStackWalker.java \
+ $(top_srcdir)/src/classes/gnu/gnu/classpath/VMSystemProperties.java \
+ $(top_srcdir)/src/classes/gnu/gnu/java/lang/management/VMMemoryMXBeanImpl.java \
+ $(top_srcdir)/src/classes/gnu/gnu/java/lang/management/VMRuntimeMXBeanImpl.java \
+ $(top_srcdir)/src/classes/gnu/java/lang/VMClassLoader.java \
+ $(top_srcdir)/src/classes/gnu/java/lang/VMString.java \
+ $(top_srcdir)/src/classes/gnu/java/lang/VMThread.java \
+ $(top_srcdir)/src/classes/gnu/java/lang/reflect/Constructor.java \
+ $(top_srcdir)/src/classes/gnu/java/lang/reflect/Field.java \
+ $(top_srcdir)/src/classes/gnu/java/lang/reflect/Method.java \
+ $(top_srcdir)/src/classes/gnu/java/security/VMAccessController.java \
+ $(top_srcdir)/src/classes/gnu/sun/misc/Unsafe.java
+
+VM_JAVA_FILES_GNU_ANNOTATIONS = \
+ $(top_srcdir)/src/classes/gnu/sun/reflect/ConstantPool.java \
+ $(top_srcdir)/src/classes/gnu/sun/reflect/annotation/ExceptionProxy.java \
+ $(top_srcdir)/src/classes/gnu/sun/reflect/annotation/EnumConstantNotPresentExceptionProxy.java \
+ $(top_srcdir)/src/classes/gnu/sun/reflect/annotation/TypeNotPresentExceptionProxy.java \
+ $(top_srcdir)/src/classes/gnu/sun/reflect/annotation/AnnotationTypeMismatchExceptionProxy.java \
+ $(top_srcdir)/src/classes/gnu/sun/reflect/annotation/AnnotationType.java \
+ $(top_srcdir)/src/classes/gnu/sun/reflect/annotation/AnnotationParser.java
+
+VM_JAVA_FILES_CLDC1_1 = \
+ $(top_srcdir)/src/classes/cldc1.1/com/sun/cldchi/jvm/FileDescriptor.java
+
+BOOTCLASSPATH = $(top_builddir)/src/classes/classes:$(CLASSPATH_CLASSES)
+
+if WITH_CLASSPATH_GNU
+VM_JAVA_FILES = \
+ $(VM_JAVA_FILES_GNU)
+
+if ENABLE_ANNOTATIONS
+VM_JAVA_FILES += \
+ $(VM_JAVA_FILES_GNU_ANNOTATIONS)
+endif
+
+if ENABLE_ZLIB
+pkgdata_DATA = vm.zip
+else
+pkgdata_DATA = nozip
+endif
+endif
+
+if WITH_CLASSPATH_CLDC1_1
+VM_JAVA_FILES = \
+ $(VM_JAVA_FILES_CLDC1_1)
+
+if ENABLE_ZLIB
+pkgdata_DATA = vm.zip
+else
+pkgdata_DATA = nozip
+endif
+endif
+
+if ENABLE_ZLIB
+VM_ZIP = ../vm.zip
+
+vm.zip: $(VM_JAVA_FILES)
+ $(mkdir_p) classes
+ $(JAVAC) -bootclasspath $(BOOTCLASSPATH) -source 1.5 -target 1.5 -d classes $(VM_JAVA_FILES)
+ @if test "$(JAR)" = "zip" -o "$(JAR)" = "zip.exe"; then \
+ cd classes && $(JAR) -r -D $(VM_ZIP) .; \
+ else \
+ cd classes && $(JAR) cvf $(VM_ZIP) .; \
+ fi
+else
+nozip: $(VM_JAVA_FILES)
+ $(mkdir_p) classes
+ $(JAVAC) -bootclasspath $(BOOTCLASSPATH) -source 1.5 -target 1.5 -d classes $(VM_JAVA_FILES)
+endif
+
+clean-local:
+ -rm -rf classes
+
+
+## Local variables:
+## mode: Makefile
+## indent-tabs-mode: t
+## c-basic-offset: 4
+## tab-width: 8
+## compile-command: "automake --add-missing"
+## End:
--- /dev/null
+/* src/lib/com/sun/cldchi/jvm/FileDescriptor.java
+
+ Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel, C. Oates,
+ R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
+ C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
+ Institut f. Computersprachen - TU Wien
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+*/
+
+package com.sun.cldchi.jvm;
+
+class FileDescriptor {
+ long pointer;
+ int position;
+ int length;
+}
--- /dev/null
+/* VMStackWalker.java -- Reference implementation of VM hooks for stack access
+ Copyright (C) 2005 Free Software Foundation
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.classpath;
+
+/**
+ * This class provides access to the classes on the Java stack
+ * for reflection and security purposes.
+ *
+ * <p>
+ * This class is only available to privileged code (i.e., code loaded
+ * by the bootstrap loader).
+ *
+ * @author John Keiser
+ * @author Eric Blake <ebb9@email.byu.edu>
+ * @author Archie Cobbs
+ */
+public final class VMStackWalker
+{
+ /**
+ * Get a list of all the classes currently executing methods on the
+ * Java stack. <code>getClassContext()[0]</code> is the class associated
+ * with the currently executing method, i.e., the method that called
+ * <code>VMStackWalker.getClassContext()</code> (possibly through
+ * reflection). So you may need to pop off these stack frames from
+ * the top of the stack:
+ * <ul>
+ * <li><code>VMStackWalker.getClassContext()</code>
+ * <li><code>Method.invoke()</code>
+ * </ul>
+ *
+ * @return an array of the declaring classes of each stack frame
+ */
+ public static native Class[] getClassContext();
+
+ /**
+ * Get the class associated with the method invoking the method
+ * invoking this method, or <code>null</code> if the stack is not
+ * that deep (e.g., invoked via JNI invocation API). This method
+ * is an optimization for the expression <code>getClassContext()[1]</code>
+ * and should return the same result.
+ *
+ * <p>
+ * VM implementers are encouraged to provide a more efficient
+ * version of this method.
+ */
+// public static Class getCallingClass()
+// {
+// Class[] ctx = getClassContext();
+// if (ctx.length < 3)
+// return null;
+// return ctx[2];
+// }
+ public static native Class getCallingClass();
+
+ /**
+ * Get the class loader associated with the Class returned by
+ * <code>getCallingClass()</code>, or <code>null</code> if no such class
+ * exists or it is the boot loader. This method is an optimization for the
+ * expression <code>VMStackWalker.getClassLoader(getClassContext()[1])</code>
+ * and should return the same result.
+ *
+ * <p>
+ * VM implementers are encouraged to provide a more efficient
+ * version of this method.
+ */
+// public static ClassLoader getCallingClassLoader()
+// {
+// Class[] ctx = getClassContext();
+// if (ctx.length < 3)
+// return null;
+// return getClassLoader(ctx[2]);
+// }
+ public static native ClassLoader getCallingClassLoader();
+
+
+ /**
+ * Retrieve the class's ClassLoader, or <code>null</code> if loaded
+ * by the bootstrap loader. I.e., this should return the same thing
+ * as {@link java.lang.VMClass#getClassLoader}. This duplicate version
+ * is here to work around access permissions.
+ */
+// public static native ClassLoader getClassLoader(Class cl);
+
+ /**
+ * Walk up the stack and return the first non-null class loader.
+ * If there aren't any non-null class loaders on the stack, return null.
+ */
+// public static ClassLoader firstNonNullClassLoader()
+// {
+// Class[] stack = getClassContext();
+// for (int i = 0; i < stack.length; i++)
+// {
+// ClassLoader loader = getClassLoader(stack[i]);
+// if (loader != null)
+// return loader;
+// }
+// return null;
+// }
+ public static native ClassLoader firstNonNullClassLoader();
+}
--- /dev/null
+/* VMSystemProperties.java -- Allow the VM to set System properties.
+ Copyright (C) 2004 Free Software Foundation
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.classpath;
+
+import java.util.Properties;
+
+class VMSystemProperties
+{
+ /**
+ * Get the system properties. This is done here, instead of in System,
+ * because of the bootstrap sequence. Note that the native code should
+ * not try to use the Java I/O classes yet, as they rely on the properties
+ * already existing. The only safe method to use to insert these default
+ * system properties is {@link Properties#setProperty(String, String)}.
+ *
+ * <p>These properties MUST include:
+ * <dl>
+ * <dt>java.version <dd>Java version number
+ * <dt>java.vendor <dd>Java vendor specific string
+ * <dt>java.vendor.url <dd>Java vendor URL
+ * <dt>java.home <dd>Java installation directory
+ * <dt>java.vm.specification.version <dd>VM Spec version
+ * <dt>java.vm.specification.vendor <dd>VM Spec vendor
+ * <dt>java.vm.specification.name <dd>VM Spec name
+ * <dt>java.vm.version <dd>VM implementation version
+ * <dt>java.vm.vendor <dd>VM implementation vendor
+ * <dt>java.vm.name <dd>VM implementation name
+ * <dt>java.specification.version <dd>Java Runtime Environment version
+ * <dt>java.specification.vendor <dd>Java Runtime Environment vendor
+ * <dt>java.specification.name <dd>Java Runtime Environment name
+ * <dt>java.class.version <dd>Java class version number
+ * <dt>java.class.path <dd>Java classpath
+ * <dt>java.library.path <dd>Path for finding Java libraries
+ * <dt>java.io.tmpdir <dd>Default temp file path
+ * <dt>java.compiler <dd>Name of JIT to use
+ * <dt>java.ext.dirs <dd>Java extension path
+ * <dt>os.name <dd>Operating System Name
+ * <dt>os.arch <dd>Operating System Architecture
+ * <dt>os.version <dd>Operating System Version
+ * <dt>file.separator <dd>File separator ("/" on Unix)
+ * <dt>path.separator <dd>Path separator (":" on Unix)
+ * <dt>line.separator <dd>Line separator ("\n" on Unix)
+ * <dt>user.name <dd>User account name
+ * <dt>user.home <dd>User home directory
+ * <dt>user.dir <dd>User's current working directory
+ * <dt>gnu.cpu.endian <dd>"big" or "little"
+ * </dl>
+ *
+ * @param properties the Properties object to insert the system properties into
+ */
+ static native void preInit(Properties properties);
+
+ /**
+ * Here you get a chance to overwrite some of the properties set by
+ * the common SystemProperties code. For example, it might be
+ * a good idea to process the properties specified on the command
+ * line here.
+ */
+// static void postInit(Properties properties)
+// {
+// }
+ static native void postInit(Properties properties);
+}
--- /dev/null
+/* VMMemoryMXBeanImpl.java - VM impl. of a memory bean
+ Copyright (C) 2006 Free Software Foundation
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.lang.management;
+
+import java.lang.management.MemoryUsage;
+
+/**
+ * Provides access to information about the memory
+ * management of the current invocation of the virtual
+ * machine. Instances of this bean are obtained by calling
+ * {@link ManagementFactory#getMemoryMXBean()}.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+final class VMMemoryMXBeanImpl
+{
+
+ /**
+ * Returns an instance of {@link java.lang.management.MemoryUsage}
+ * with appropriate initial, used, committed and maximum values
+ * for the heap. By default, this uses the methods of
+ * {@link java.lang.Runtime} to provide some of the values.
+ *
+ * @return an {@link java.lang.management.MemoryUsage} instance
+ * for the heap.
+ */
+// static MemoryUsage getHeapMemoryUsage()
+// {
+// Runtime runtime = Runtime.getRuntime();
+// long totalMem = runtime.totalMemory();
+// return new MemoryUsage(-1, totalMem - runtime.freeMemory(),
+// totalMem, runtime.maxMemory());
+// }
+ static native MemoryUsage getHeapMemoryUsage();
+
+ /**
+ * Returns an instance of {@link java.lang.management.MemoryUsage}
+ * with appropriate initial, used, committed and maximum values
+ * for non-heap memory.
+ *
+ * @return an {@link java.lang.management.MemoryUsage} instance
+ * for non-heap memory.
+ */
+ static native MemoryUsage getNonHeapMemoryUsage();
+
+ /**
+ * Returns the number of objects ready to be garbage collected.
+ *
+ * @return the number of finalizable objects.
+ */
+ static native int getObjectPendingFinalizationCount();
+
+ /**
+ * Returns true if the virtual machine will emit additional
+ * information when memory is allocated and deallocated. The
+ * format of the output is left up to the virtual machine.
+ *
+ * @return true if verbose class loading output is on.
+ */
+ static native boolean isVerbose();
+
+ /**
+ * Turns on or off the emission of additional information
+ * when memory is allocated and deallocated. The format of the
+ * output is left up to the virtual machine. This method
+ * may be called by multiple threads concurrently, but there
+ * is only one global setting of verbosity that is affected.
+ *
+ * @param verbose the new setting for verbose class loading
+ * output.
+ */
+ static native void setVerbose(boolean verbose);
+
+}
--- /dev/null
+/* VMRuntimeMXBeanImpl.java - VM implementation of an runtime bean
+ Copyright (C) 2006 Free Software Foundation
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.lang.management;
+
+import gnu.classpath.SystemProperties;
+
+/**
+ * Provides access to information about the virtual machine.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+final class VMRuntimeMXBeanImpl
+{
+
+ /**
+ * Returns the command-line arguments supplied
+ * to the virtual machine, excluding those supplied
+ * to <code>main()</code>.
+ *
+ * @return the command-line arguments.
+ */
+ static native String[] getInputArguments();
+
+ /**
+ * Returns a developer-chosen name for the virtual
+ * machine, which may differ over different running
+ * instances of the same virtual machine binary.
+ * For example, this may include the particular
+ * process identifier used by this instance or
+ * the host name of the machine on which it is
+ * running. The intention is that this name refers
+ * to the precise entity that the other data supplied
+ * by the bean refers to, rather than the VM in general.
+ *
+ * @return the custom name of the VM.
+ */
+ static String getName()
+ {
+ return SystemProperties.getProperty("java.vm.name") + " " +
+ SystemProperties.getProperty("java.vm.version");
+ }
+
+ /**
+ * The time in milliseconds at which the virtual
+ * machine was started. This method is only executed
+ * once (for efficency), as the value is not expected
+ * to change.
+ *
+ * @return the VM start time.
+ */
+ static native long getStartTime();
+
+}
--- /dev/null
+/* VMClassLoader.java -- Reference implementation of native interface
+ required by ClassLoader
+ Copyright (C) 1998, 2001, 2002, 2004, 2005, 2006 Free Software Foundation
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.lang;
+
+import gnu.classpath.Configuration;
+import gnu.classpath.SystemProperties;
+import gnu.java.lang.InstrumentationImpl;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.lang.instrument.Instrumentation;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.ProtectionDomain;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.Vector;
+import java.util.zip.ZipFile;
+import java.util.Collections;
+import java.lang.Boolean;
+
+/**
+ * java.lang.VMClassLoader is a package-private helper for VMs to implement
+ * on behalf of java.lang.ClassLoader.
+ *
+ * @author John Keiser
+ * @author Mark Wielaard (mark@klomp.org)
+ * @author Eric Blake (ebb9@email.byu.edu)
+ */
+final class VMClassLoader
+{
+
+
+ /** packages loaded by the bootstrap class loader */
+ static final HashMap definedPackages = new HashMap();
+
+ /** jars from property java.boot.class.path */
+ static final HashMap bootjars = new HashMap();
+
+
+ /**
+ * Converts the array string of native package names to
+ * Packages. The packages are then put into the
+ * definedPackages hashMap
+ */
+ static
+ {
+ String[] packages = getBootPackages();
+
+ if( packages != null)
+ {
+ String specName =
+ SystemProperties.getProperty("java.specification.name");
+ String vendor =
+ SystemProperties.getProperty("java.specification.vendor");
+ String version =
+ SystemProperties.getProperty("java.specification.version");
+
+ Package p;
+
+ for(int i = 0; i < packages.length; i++)
+ {
+ p = new Package(packages[i],
+ specName,
+ vendor,
+ version,
+ "GNU Classpath",
+ "GNU",
+ Configuration.CLASSPATH_VERSION,
+ null,
+ null);
+
+ definedPackages.put(packages[i], p);
+ }
+ }
+ }
+
+
+ /**
+ * Helper to define a class using a string of bytes. This assumes that
+ * the security checks have already been performed, if necessary.
+ *
+ * Implementations of this method are advised to consider the
+ * situation where user code modifies the byte array after it has
+ * been passed to defineClass. This can be handled by making a
+ * private copy of the array, or arranging to only read any given
+ * byte a single time.
+ *
+ * @param name the name to give the class, or null if unknown
+ * @param data the data representing the classfile, in classfile format
+ * @param offset the offset into the data where the classfile starts
+ * @param len the length of the classfile data in the array
+ * @param pd the protection domain
+ * @return the class that was defined
+ * @throws ClassFormatError if data is not in proper classfile format
+ */
+ static final native Class defineClass(ClassLoader cl, String name,
+ byte[] data, int offset, int len,
+ ProtectionDomain pd)
+ throws ClassFormatError;
+
+ /**
+ * Helper to resolve all references to other classes from this class.
+ *
+ * @param c the class to resolve
+ */
+ static final native void resolveClass(Class c);
+
+ /**
+ * Helper to load a class from the bootstrap class loader.
+ *
+ * @param name the class name to load
+ * @param resolve whether to resolve it
+ * @return the class, loaded by the bootstrap classloader or null
+ * if the class wasn't found. Returning null is equivalent to throwing
+ * a ClassNotFoundException (but a possible performance optimization).
+ */
+ static final native Class loadClass(String name, boolean resolve)
+ throws ClassNotFoundException;
+
+ /**
+ * Helper to load a resource from the bootstrap class loader.
+ *
+ * @param name the resource to find
+ * @return the URL to the resource
+ */
+ static URL getResource(String name)
+ {
+ Enumeration e = getResources(name);
+ if (e.hasMoreElements())
+ return (URL)e.nextElement();
+ return null;
+ }
+ /**
+ * Helper to get a list of resources from the bootstrap class loader.
+ *
+ * @param name the resource to find
+ * @return an enumeration of resources
+ */
+ static Enumeration getResources(String name)
+ {
+// StringTokenizer st = new StringTokenizer(
+// SystemProperties.getProperty("java.boot.class.path", "."),
+// File.pathSeparator);
+// Vector v = new Vector();
+// while (st.hasMoreTokens())
+// {
+// File file = new File(st.nextToken());
+// if (file.isDirectory())
+// {
+// try
+// {
+// File f = new File(file, name);
+// if (!f.exists()) continue;
+// v.add(new URL("file://" + f.getAbsolutePath()));
+// }
+// catch (MalformedURLException e)
+// {
+// throw new Error(e);
+// }
+// }
+// else if (file.isFile())
+// {
+// ZipFile zip;
+// synchronized(bootjars)
+// {
+// zip = (ZipFile) bootjars.get(file.getName());
+// }
+// if(zip == null)
+// {
+// try
+// {
+// zip = new ZipFile(file);
+// synchronized(bootjars)
+// {
+// bootjars.put(file.getName(), zip);
+// }
+// }
+// catch (IOException e)
+// {
+// continue;
+// }
+// }
+// String zname = name.startsWith("/") ? name.substring(1) : name;
+// if (zip.getEntry(zname) == null)
+// continue;
+// try
+// {
+// v.add(new URL("jar:file://"
+// + file.getAbsolutePath() + "!/" + zname));
+// }
+// catch (MalformedURLException e)
+// {
+// throw new Error(e);
+// }
+// }
+// }
+// return v.elements();
+// }
+ Vector urls = nativeGetResources(name);
+ Vector v = new Vector();
+ for (Enumeration en = urls.elements(); en.hasMoreElements();)
+ {
+ try
+ {
+ v.add(new URL((String) en.nextElement()));
+ }
+ catch (MalformedURLException e)
+ {
+ throw new Error(e);
+ }
+ }
+ return v.elements();
+ }
+
+ private native static final Vector nativeGetResources(String name);
+
+
+ /**
+ * Returns a String[] of native package names. The default
+ * implementation tries to load a list of package from
+ * the META-INF/INDEX.LIST file in the boot jar file.
+ * If not found or if any exception is raised, it returns
+ * an empty array. You may decide this needs native help.
+ */
+ private static String[] getBootPackages()
+ {
+ try
+ {
+ Enumeration indexListEnumeration = getResources("META-INF/INDEX.LIST");
+ Set packageSet = new HashSet();
+
+ while (indexListEnumeration.hasMoreElements())
+ {
+ try
+ {
+ String line;
+ int lineToSkip = 3;
+ BufferedReader reader = new BufferedReader(
+ new InputStreamReader(
+ ((URL) indexListEnumeration.nextElement()).openStream()));
+ while ((line = reader.readLine()) != null)
+ {
+ if (lineToSkip == 0)
+ {
+ if (line.length() == 0)
+ lineToSkip = 1;
+ else
+ packageSet.add(line.replace('/', '.'));
+ }
+ else
+ lineToSkip--;
+ }
+ reader.close();
+ }
+ catch (IOException e)
+ {
+ // Empty catch block on purpose
+ }
+ }
+ return (String[]) packageSet.toArray(new String[packageSet.size()]);
+ }
+ catch (Exception e)
+ {
+ return new String[0];
+ }
+ }
+
+
+ /**
+ * Helper to get a package from the bootstrap class loader.
+ *
+ * @param name the name to find
+ * @return the named package, if it exists
+ */
+ static Package getPackage(String name)
+ {
+ return (Package)definedPackages.get(name);
+ }
+
+
+
+ /**
+ * Helper to get all packages from the bootstrap class loader.
+ *
+ * @return all named packages, if any exist
+ */
+ static Package[] getPackages()
+ {
+ Package[] packages = new Package[definedPackages.size()];
+ definedPackages.values().toArray(packages);
+ return packages;
+ }
+
+ /**
+ * Helper for java.lang.Integer, Byte, etc to get the TYPE class
+ * at initialization time. The type code is one of the chars that
+ * represents the primitive type as in JNI.
+ *
+ * <ul>
+ * <li>'Z' - boolean</li>
+ * <li>'B' - byte</li>
+ * <li>'C' - char</li>
+ * <li>'D' - double</li>
+ * <li>'F' - float</li>
+ * <li>'I' - int</li>
+ * <li>'J' - long</li>
+ * <li>'S' - short</li>
+ * <li>'V' - void</li>
+ * </ul>
+ *
+ * @param type the primitive type
+ * @return a "bogus" class representing the primitive type
+ */
+ static final native Class getPrimitiveClass(char type);
+
+ /**
+ * The system default for assertion status. This is used for all system
+ * classes (those with a null ClassLoader), as well as the initial value for
+ * every ClassLoader's default assertion status.
+ *
+ * @return the system-wide default assertion status
+ */
+ static native final boolean defaultAssertionStatus();
+
+ static native final boolean defaultUserAssertionStatus();
+
+
+ static final Map packageAssertionMap =
+ Collections.unmodifiableMap(packageAssertionStatus0(Boolean.TRUE, Boolean.FALSE));
+
+ static native final Map packageAssertionStatus0(Boolean jtrue, Boolean jfalse);
+ /**
+ * The system default for package assertion status. This is used for all
+ * ClassLoader's packageAssertionStatus defaults. It must be a map of
+ * package names to Boolean.TRUE or Boolean.FALSE, with the unnamed package
+ * represented as a null key.
+ *
+ * @return a (read-only) map for the default packageAssertionStatus
+ */
+
+ static final Map packageAssertionStatus() {
+ return packageAssertionMap;
+ }
+
+ static final Map classAssertionMap =
+ Collections.unmodifiableMap(classAssertionStatus0(Boolean.TRUE, Boolean.FALSE));
+
+ static native final Map classAssertionStatus0(Boolean jtrue, Boolean jfalse);
+
+ /**
+ * The system default for class assertion status. This is used for all
+ * ClassLoader's classAssertionStatus defaults. It must be a map of
+ * class names to Boolean.TRUE or Boolean.FALSE
+ *
+ * @return a (read-only) map for the default classAssertionStatus
+ */
+ static final Map classAssertionStatus() {
+ return classAssertionMap;
+ }
+
+ static ClassLoader getSystemClassLoader()
+ {
+ return ClassLoader.defaultGetSystemClassLoader();
+ }
+
+ /**
+ * Find the class if this class loader previously defined this class
+ * or if this class loader has been recorded as the initiating class loader
+ * for this class.
+ */
+ static native Class findLoadedClass(ClassLoader cl, String name);
+
+ /**
+ * The Instrumentation object created by the vm when agents are defined.
+ */
+ static final Instrumentation instrumenter = null;
+
+ /**
+ * Call the transformers of the possible Instrumentation object. This
+ * implementation assumes the instrumenter is a
+ * <code>InstrumentationImpl</code> object. VM implementors would
+ * have to redefine this method if they provide their own implementation
+ * of the <code>Instrumentation</code> interface.
+ *
+ * @param loader the initiating loader
+ * @param name the name of the class
+ * @param data the data representing the classfile, in classfile format
+ * @param offset the offset into the data where the classfile starts
+ * @param len the length of the classfile data in the array
+ * @param pd the protection domain
+ * @return the new data representing the classfile
+ */
+ static final Class defineClassWithTransformers(ClassLoader loader,
+ String name, byte[] data, int offset, int len, ProtectionDomain pd)
+ {
+
+ if (instrumenter != null)
+ {
+ byte[] modifiedData = new byte[len];
+ System.arraycopy(data, offset, modifiedData, 0, len);
+ modifiedData =
+ ((InstrumentationImpl)instrumenter).callTransformers(loader, name,
+ null, pd, modifiedData);
+
+ return defineClass(loader, name, modifiedData, 0, modifiedData.length,
+ pd);
+ }
+ else
+ {
+ return defineClass(loader, name, data, offset, len, pd);
+ }
+ }
+}
--- /dev/null
+/* VMString.java -- VM Specific String methods
+ Copyright (C) 2003 Free Software Foundation
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.lang;
+
+import java.lang.ref.WeakReference;
+import java.util.WeakHashMap;
+
+/*
+ * This class is a reference version, mainly for compiling a class library
+ * jar. It is likely that VM implementers replace this with their own
+ * version that can communicate effectively with the VM.
+ */
+
+/**
+ * Code relocated from java.lang.String by
+ * @author Dave Grove <groved@us.ibm.com>
+ */
+final class VMString
+{
+
+ /**
+ * Holds the references for each intern()'d String. If all references to
+ * the string disappear, and the VM properly supports weak references,
+ * the String will be GC'd.
+ */
+// private static final WeakHashMap internTable = new WeakHashMap();
+
+ /**
+ * Fetches this String from the intern hashtable. If two Strings are
+ * considered equal, by the equals() method, then intern() will return the
+ * same String instance. ie. if (s1.equals(s2)) then
+ * (s1.intern() == s2.intern()). All string literals and string-valued
+ * constant expressions are already interned.
+ *
+ * @param str the String to intern
+ * @return the interned String
+ */
+// static String intern(String str)
+// {
+// synchronized (internTable)
+// {
+// WeakReference ref = (WeakReference) internTable.get(str);
+// if (ref != null)
+// {
+// String s = (String) ref.get();
+// // If s is null, then no strong references exist to the String;
+// // the weak hash map will soon delete the key.
+// if (s != null)
+// return s;
+// }
+// internTable.put(str, new WeakReference(str));
+// }
+// return str;
+// }
+
+ /**
+ * this one is native in CACAO
+ */
+ static native String intern(String str);
+
+} // class VMString
--- /dev/null
+/* VMThread -- VM interface for Thread of executable code
+ Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.lang;
+
+/**
+ * VM interface for Thread of executable code. Holds VM dependent state.
+ * It is deliberately package local and final and should only be accessed
+ * by the Thread class.
+ * <p>
+ * This is the GNU Classpath reference implementation, it should be adapted
+ * for a specific VM.
+ * <p>
+ * The following methods must be implemented:
+ * <ul>
+ * <li>native void start(long stacksize);
+ * <li>native void interrupt();
+ * <li>native boolean isInterrupted();
+ * <li>native void suspend();
+ * <li>native void resume();
+ * <li>native void nativeSetPriority(int priority);
+ * <li>native void nativeStop(Throwable t);
+ * <li>native static Thread currentThread();
+ * <li>static native void yield();
+ * <li>static native boolean interrupted();
+ * </ul>
+ * All other methods may be implemented to make Thread handling more efficient
+ * or to implement some optional (and sometimes deprecated) behaviour. Default
+ * implementations are provided but it is highly recommended to optimize them
+ * for a specific VM.
+ *
+ * @author Jeroen Frijters (jeroen@frijters.net)
+ * @author Dalibor Topic (robilad@kaffe.org)
+ */
+final class VMThread
+{
+ /**
+ * The Thread object that this VM state belongs to.
+ * Used in currentThread() and start().
+ * Note: when this thread dies, this reference is *not* cleared
+ */
+ volatile Thread thread;
+
+ /**
+ * Flag that is set when the thread runs, used by stop() to protect against
+ * stop's getting lost.
+ */
+ private volatile boolean running;
+
+ /**
+ * VM private data.
+ */
+ private transient Object vmdata;
+
+ /**
+ * Private constructor, create VMThreads with the static create method.
+ *
+ * @param thread The Thread object that was just created.
+ */
+ private VMThread(Thread thread)
+ {
+ this.thread = thread;
+ }
+
+ /**
+ * This method is the initial Java code that gets executed when a native
+ * thread starts. It's job is to coordinate with the rest of the VMThread
+ * logic and to start executing user code and afterwards handle clean up.
+ */
+ private void run()
+ {
+ try
+ {
+ try
+ {
+ running = true;
+ synchronized(thread)
+ {
+ Throwable t = thread.stillborn;
+ if(t != null)
+ {
+ thread.stillborn = null;
+ throw t;
+ }
+ }
+ thread.run();
+ }
+ catch(Throwable t)
+ {
+ try
+ {
+ Thread.UncaughtExceptionHandler handler;
+ handler = thread.getUncaughtExceptionHandler();
+ handler.uncaughtException(thread, t);
+ }
+ catch(Throwable ignore)
+ {
+ }
+ }
+ }
+ finally
+ {
+ // Setting runnable to false is partial protection against stop
+ // being called while we're cleaning up. To be safe all code in
+ // VMThread be unstoppable.
+ running = false;
+ thread.die();
+ synchronized(this)
+ {
+ // release the threads waiting to join us
+ notifyAll();
+ }
+ }
+ }
+
+ /**
+ * Creates a native Thread. This is called from the start method of Thread.
+ * The Thread is started.
+ *
+ * @param thread The newly created Thread object
+ * @param stacksize Indicates the requested stacksize. Normally zero,
+ * non-zero values indicate requested stack size in bytes but it is up
+ * to the specific VM implementation to interpret them and may be ignored.
+ */
+ static void create(Thread thread, long stacksize)
+ {
+ VMThread vmThread = new VMThread(thread);
+ thread.vmThread = vmThread;
+ vmThread.start(stacksize);
+ }
+
+ /**
+ * Gets the name of the thread. Usually this is the name field of the
+ * associated Thread object, but some implementation might choose to
+ * return the name of the underlying platform thread.
+ */
+ String getName()
+ {
+ return thread.name;
+ }
+
+ /**
+ * Set the name of the thread. Usually this sets the name field of the
+ * associated Thread object, but some implementations might choose to
+ * set the name of the underlying platform thread.
+ * @param name The new name
+ */
+ void setName(String name)
+ {
+ thread.name = name;
+ }
+
+ /**
+ * Set the thread priority field in the associated Thread object and
+ * calls the native method to set the priority of the underlying
+ * platform thread.
+ * @param priority The new priority
+ */
+ void setPriority(int priority)
+ {
+ thread.priority = priority;
+ nativeSetPriority(priority);
+ }
+
+ /**
+ * Returns the priority. Usually this is the priority field from the
+ * associated Thread object, but some implementation might choose to
+ * return the priority of the underlying platform thread.
+ * @return this Thread's priority
+ */
+ int getPriority()
+ {
+ return thread.priority;
+ }
+
+ /**
+ * Returns true if the thread is a daemon thread. Usually this is the
+ * daemon field from the associated Thread object, but some
+ * implementation might choose to return the daemon state of the underlying
+ * platform thread.
+ * @return whether this is a daemon Thread or not
+ */
+ boolean isDaemon()
+ {
+ return thread.daemon;
+ }
+
+ /**
+ * Returns the number of stack frames in this Thread.
+ * Will only be called when when a previous call to suspend() returned true.
+ *
+ * @deprecated unsafe operation
+ */
+ native int countStackFrames();
+
+ /**
+ * Wait the specified amount of time for the Thread in question to die.
+ *
+ * <p>Note that 1,000,000 nanoseconds == 1 millisecond, but most VMs do
+ * not offer that fine a grain of timing resolution. Besides, there is
+ * no guarantee that this thread can start up immediately when time expires,
+ * because some other thread may be active. So don't expect real-time
+ * performance.
+ *
+ * @param ms the number of milliseconds to wait, or 0 for forever
+ * @param ns the number of extra nanoseconds to sleep (0-999999)
+ * @throws InterruptedException if the Thread is interrupted; it's
+ * <i>interrupted status</i> will be cleared
+ */
+ synchronized void join(long ms, int ns) throws InterruptedException
+ {
+ // Round up
+ ms += (ns != 0) ? 1 : 0;
+
+ // Compute end time, but don't overflow
+ long now = System.currentTimeMillis();
+ long end = now + ms;
+ if (end < now)
+ end = Long.MAX_VALUE;
+
+ // A VM is allowed to return from wait() without notify() having been
+ // called, so we loop to handle possible spurious wakeups.
+ while(thread.vmThread != null)
+ {
+ // We use the VMThread object to wait on, because this is a private
+ // object, so client code cannot call notify on us.
+ wait(ms);
+ if(ms != 0)
+ {
+ now = System.currentTimeMillis();
+ ms = end - now;
+ if(ms <= 0)
+ {
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * Cause this Thread to stop abnormally and throw the specified exception.
+ * If you stop a Thread that has not yet started, the stop is ignored
+ * (contrary to what the JDK documentation says).
+ * <b>WARNING</b>This bypasses Java security, and can throw a checked
+ * exception which the call stack is unprepared to handle. Do not abuse
+ * this power.
+ *
+ * <p>This is inherently unsafe, as it can interrupt synchronized blocks and
+ * leave data in bad states.
+ *
+ * <p><b>NOTE</b> stop() should take care not to stop a thread if it is
+ * executing code in this class.
+ *
+ * @param t the Throwable to throw when the Thread dies
+ * @deprecated unsafe operation, try not to use
+ */
+ void stop(Throwable t)
+ {
+ // Note: we assume that we own the lock on thread
+ // (i.e. that Thread.stop() is synchronized)
+ if(running)
+ nativeStop(t);
+ else
+ thread.stillborn = t;
+ }
+
+ /**
+ * Create a native thread on the underlying platform and start it executing
+ * on the run method of this object.
+ * @param stacksize the requested size of the native thread stack
+ */
+ native void start(long stacksize);
+
+ /**
+ * Interrupt this thread.
+ */
+ native void interrupt();
+
+ /**
+ * Determine whether this Thread has been interrupted, but leave
+ * the <i>interrupted status</i> alone in the process.
+ *
+ * @return whether the Thread has been interrupted
+ */
+ native boolean isInterrupted();
+
+ /**
+ * Suspend this Thread. It will not come back, ever, unless it is resumed.
+ */
+ native void suspend();
+
+ /**
+ * Resume this Thread. If the thread is not suspended, this method does
+ * nothing.
+ */
+ native void resume();
+
+ /**
+ * Set the priority of the underlying platform thread.
+ *
+ * @param priority the new priority
+ */
+ native void nativeSetPriority(int priority);
+
+ /**
+ * Asynchronously throw the specified throwable in this Thread.
+ *
+ * @param t the exception to throw
+ */
+ native void nativeStop(Throwable t);
+
+ /**
+ * Return the Thread object associated with the currently executing
+ * thread.
+ *
+ * @return the currently executing Thread
+ */
+ static native Thread currentThread();
+
+ /**
+ * Yield to another thread. The Thread will not lose any locks it holds
+ * during this time. There are no guarantees which thread will be
+ * next to run, and it could even be this one, but most VMs will choose
+ * the highest priority thread that has been waiting longest.
+ */
+ static native void yield();
+
+ /**
+ * Suspend the current Thread's execution for the specified amount of
+ * time. The Thread will not lose any locks it has during this time. There
+ * are no guarantees which thread will be next to run, but most VMs will
+ * choose the highest priority thread that has been waiting longest.
+ *
+ * <p>Note that 1,000,000 nanoseconds == 1 millisecond, but most VMs do
+ * not offer that fine a grain of timing resolution. Besides, there is
+ * no guarantee that this thread can start up immediately when time expires,
+ * because some other thread may be active. So don't expect real-time
+ * performance.
+ *
+ * @param ms the number of milliseconds to sleep.
+ * @param ns the number of extra nanoseconds to sleep (0-999999)
+ * @throws InterruptedException if the Thread is (or was) interrupted;
+ * it's <i>interrupted status</i> will be cleared
+ */
+ static void sleep(long ms, int ns) throws InterruptedException
+ {
+ // Note: JDK treats a zero length sleep is like Thread.yield(),
+ // without checking the interrupted status of the thread.
+ // It's unclear if this is a bug in the implementation or the spec.
+ // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213203
+ if (ms == 0 && ns == 0)
+ {
+ if (Thread.interrupted())
+ throw new InterruptedException();
+ return;
+ }
+
+ // Compute end time, but don't overflow
+ long now = System.currentTimeMillis();
+ long end = now + ms;
+ if (end < now)
+ end = Long.MAX_VALUE;
+
+ // A VM is allowed to return from wait() without notify() having been
+ // called, so we loop to handle possible spurious wakeups.
+ VMThread vt = Thread.currentThread().vmThread;
+ synchronized (vt)
+ {
+ while (true)
+ {
+ vt.wait(ms, ns);
+ now = System.currentTimeMillis();
+ if (now >= end)
+ break;
+ ms = end - now;
+ ns = 0;
+ }
+ }
+ }
+
+ /**
+ * Determine whether the current Thread has been interrupted, and clear
+ * the <i>interrupted status</i> in the process.
+ *
+ * @return whether the current Thread has been interrupted
+ */
+ static native boolean interrupted();
+
+ /**
+ * Checks whether the current thread holds the monitor on a given object.
+ * This allows you to do <code>assert Thread.holdsLock(obj)</code>.
+ *
+ * @param obj the object to check
+ * @return true if the current thread is currently synchronized on obj
+ * @throws NullPointerException if obj is null
+ */
+// static boolean holdsLock(Object obj)
+// {
+// /* Use obj.notify to check if the current thread holds
+// * the monitor of the object.
+// * If it doesn't, notify will throw an exception.
+// */
+// try
+// {
+// obj.notify();
+// // okay, current thread holds lock
+// return true;
+// }
+// catch (IllegalMonitorStateException e)
+// {
+// // it doesn't hold the lock
+// return false;
+// }
+// }
+ static native boolean holdsLock(Object obj);
+
+ /**
+ * Returns the current state of the thread.
+ * The value must be one of "BLOCKED", "NEW",
+ * "RUNNABLE", "TERMINATED", "TIMED_WAITING" or
+ * "WAITING".
+ *
+ * @return a string corresponding to one of the
+ * thread enumeration states specified above.
+ */
+ native String getState();
+
+}
--- /dev/null
+/* java.lang.reflect.Constructor - reflection of Java constructors
+ Copyright (C) 1998, 2001, 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.lang.reflect;
+
+import gnu.java.lang.ClassHelper;
+
+import gnu.java.lang.reflect.MethodSignatureParser;
+
+import java.lang.annotation.Annotation;
+import java.util.Map;
+import java.util.Arrays;
+
+/**
+ * The Constructor class represents a constructor of a class. It also allows
+ * dynamic creation of an object, via reflection. Invocation on Constructor
+ * objects knows how to do widening conversions, but throws
+ * {@link IllegalArgumentException} if a narrowing conversion would be
+ * necessary. You can query for information on this Constructor regardless
+ * of location, but construction access may be limited by Java language
+ * access controls. If you can't do it in the compiler, you can't normally
+ * do it here either.<p>
+ *
+ * <B>Note:</B> This class returns and accepts types as Classes, even
+ * primitive types; there are Class types defined that represent each
+ * different primitive type. They are <code>java.lang.Boolean.TYPE,
+ * java.lang.Byte.TYPE,</code>, also available as <code>boolean.class,
+ * byte.class</code>, etc. These are not to be confused with the
+ * classes <code>java.lang.Boolean, java.lang.Byte</code>, etc., which are
+ * real classes.<p>
+ *
+ * Also note that this is not a serializable class. It is entirely feasible
+ * to make it serializable using the Externalizable interface, but this is
+ * on Sun, not me.
+ *
+ * @author John Keiser
+ * @author Eric Blake <ebb9@email.byu.edu>
+ * @see Member
+ * @see Class
+ * @see java.lang.Class#getConstructor(Class[])
+ * @see java.lang.Class#getDeclaredConstructor(Class[])
+ * @see java.lang.Class#getConstructors()
+ * @see java.lang.Class#getDeclaredConstructors()
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public final class Constructor<T>
+ extends AccessibleObject
+ implements GenericDeclaration, Member
+{
+ private Class<T> clazz;
+ private int slot;
+
+ /**
+ * Unparsed annotations.
+ */
+ private byte[] annotations = null;
+
+ /**
+ * Unparsed parameter annotations.
+ */
+ private byte[] parameterAnnotations = null;
+
+ /**
+ * Annotations get parsed the first time they are
+ * accessed and are then cached it this map.
+ */
+ private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations = null;
+
+ private static final int CONSTRUCTOR_MODIFIERS
+ = Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC;
+
+ /**
+ * Helper array for creating a new array from a java.util.Container.
+ */
+ private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY =
+ new Annotation[0];
+
+ /**
+ * This class is uninstantiable except from native code.
+ */
+ private Constructor(Class declaringClass,int slot)
+ {
+ this.clazz = declaringClass;
+ this.slot = slot;
+ }
+
+ private Constructor()
+ {
+ }
+
+ /**
+ * Gets the class that declared this constructor.
+ * @return the class that declared this member
+ */
+ public Class<T> getDeclaringClass()
+ {
+ return clazz;
+ }
+
+ /**
+ * Gets the name of this constructor (the non-qualified name of the class
+ * it was declared in).
+ * @return the name of this constructor
+ */
+ public String getName()
+ {
+ return getDeclaringClass().getName();
+ }
+
+ /**
+ * Return the raw modifiers for this constructor. In particular
+ * this will include the synthetic and varargs bits.
+ * @return the constructor's modifiers
+ */
+ private native int getModifiersInternal();
+
+ /**
+ * Gets the modifiers this constructor uses. Use the <code>Modifier</code>
+ * class to interpret the values. A constructor can only have a subset of the
+ * following modifiers: public, private, protected.
+ *
+ * @return an integer representing the modifiers to this Member
+ * @see Modifier
+ */
+ public int getModifiers()
+ {
+ return getModifiersInternal() & CONSTRUCTOR_MODIFIERS;
+ }
+
+ /**
+ * Return true if this constructor is synthetic, false otherwise.
+ * A synthetic member is one which is created by the compiler,
+ * and which does not appear in the user's source code.
+ * @since 1.5
+ */
+ public boolean isSynthetic()
+ {
+ return (getModifiersInternal() & Modifier.SYNTHETIC) != 0;
+ }
+
+ /**
+ * Return true if this is a varargs constructor, that is if
+ * the constructor takes a variable number of arguments.
+ * @since 1.5
+ */
+ public boolean isVarArgs()
+ {
+ return (getModifiersInternal() & Modifier.VARARGS) != 0;
+ }
+
+ /**
+ * Get the parameter list for this constructor, in declaration order. If the
+ * constructor takes no parameters, returns a 0-length array (not null).
+ *
+ * @return a list of the types of the constructor's parameters
+ */
+ public native Class<?>[] getParameterTypes();
+
+ /**
+ * Get the exception types this constructor says it throws, in no particular
+ * order. If the constructor has no throws clause, returns a 0-length array
+ * (not null).
+ *
+ * @return a list of the types in the constructor's throws clause
+ */
+ public native Class<?>[] getExceptionTypes();
+
+ /**
+ * Compare two objects to see if they are semantically equivalent.
+ * Two Constructors are semantically equivalent if they have the same
+ * declaring class and the same parameter list. This ignores different
+ * exception clauses, but since you can't create a Method except through the
+ * VM, this is just the == relation.
+ *
+ * @param o the object to compare to
+ * @return <code>true</code> if they are equal; <code>false</code> if not.
+ */
+ public boolean equals(Object o)
+ {
+ if (!(o instanceof Constructor))
+ return false;
+ Constructor that = (Constructor)o;
+ if (this.getDeclaringClass() != that.getDeclaringClass())
+ return false;
+ if (!Arrays.equals(this.getParameterTypes(), that.getParameterTypes()))
+ return false;
+ return true;
+ }
+
+ /**
+ * Get the hash code for the Constructor. The Constructor hash code is the
+ * hash code of the declaring class's name.
+ *
+ * @return the hash code for the object
+ */
+ public int hashCode()
+ {
+ return getDeclaringClass().getName().hashCode();
+ }
+
+ /**
+ * Get a String representation of the Constructor. A Constructor's String
+ * representation is "<modifier> <classname>(<paramtypes>)
+ * throws <exceptions>", where everything after ')' is omitted if
+ * there are no exceptions.<br> Example:
+ * <code>public java.io.FileInputStream(java.lang.Runnable)
+ * throws java.io.FileNotFoundException</code>
+ *
+ * @return the String representation of the Constructor
+ */
+ public String toString()
+ {
+ // 128 is a reasonable buffer initial size for constructor
+ StringBuilder sb = new StringBuilder(128);
+ Modifier.toString(getModifiers(), sb).append(' ');
+ sb.append(getDeclaringClass().getName()).append('(');
+ Class[] c = getParameterTypes();
+ if (c.length > 0)
+ {
+ sb.append(ClassHelper.getUserName(c[0]));
+ for (int i = 1; i < c.length; i++)
+ sb.append(',').append(ClassHelper.getUserName(c[i]));
+ }
+ sb.append(')');
+ c = getExceptionTypes();
+ if (c.length > 0)
+ {
+ sb.append(" throws ").append(c[0].getName());
+ for (int i = 1; i < c.length; i++)
+ sb.append(',').append(c[i].getName());
+ }
+ return sb.toString();
+ }
+
+ static <X extends GenericDeclaration>
+ void addTypeParameters(StringBuilder sb, TypeVariable<X>[] typeArgs)
+ {
+ if (typeArgs.length == 0)
+ return;
+ sb.append('<');
+ for (int i = 0; i < typeArgs.length; ++i)
+ {
+ if (i > 0)
+ sb.append(',');
+ sb.append(typeArgs[i]);
+ }
+ sb.append("> ");
+ }
+
+ public String toGenericString()
+ {
+ StringBuilder sb = new StringBuilder(128);
+ Modifier.toString(getModifiers(), sb).append(' ');
+ addTypeParameters(sb, getTypeParameters());
+ sb.append(getDeclaringClass().getName()).append('(');
+ Type[] types = getGenericParameterTypes();
+ if (types.length > 0)
+ {
+ sb.append(types[0]);
+ for (int i = 1; i < types.length; ++i)
+ sb.append(',').append(types[i]);
+ }
+ sb.append(')');
+ types = getGenericExceptionTypes();
+ if (types.length > 0)
+ {
+ sb.append(" throws ").append(types[0]);
+ for (int i = 1; i < types.length; i++)
+ sb.append(',').append(types[i]);
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Create a new instance by invoking the constructor. Arguments are
+ * automatically unwrapped and widened, if needed.<p>
+ *
+ * If this class is abstract, you will get an
+ * <code>InstantiationException</code>. If the constructor takes 0
+ * arguments, you may use null or a 0-length array for <code>args</code>.<p>
+ *
+ * If this Constructor enforces access control, your runtime context is
+ * evaluated, and you may have an <code>IllegalAccessException</code> if
+ * you could not create this object in similar compiled code. If the class
+ * is uninitialized, you trigger class initialization, which may end in a
+ * <code>ExceptionInInitializerError</code>.<p>
+ *
+ * Then, the constructor is invoked. If it completes normally, the return
+ * value will be the new object. If it completes abruptly, the exception is
+ * wrapped in an <code>InvocationTargetException</code>.
+ *
+ * @param args the arguments to the constructor
+ * @return the newly created object
+ * @throws IllegalAccessException if the constructor could not normally be
+ * called by the Java code (i.e. it is not public)
+ * @throws IllegalArgumentException if the number of arguments is incorrect;
+ * or if the arguments types are wrong even with a widening
+ * conversion
+ * @throws InstantiationException if the class is abstract
+ * @throws InvocationTargetException if the constructor throws an exception
+ * @throws ExceptionInInitializerError if construction triggered class
+ * initialization, which then failed
+ */
+ public T newInstance(Object... args)
+ throws InstantiationException, IllegalAccessException,
+ InvocationTargetException
+ {
+ return constructNative(args, clazz, slot);
+ }
+
+ private native T constructNative(Object[] args, Class declaringClass,
+ int slot)
+ throws InstantiationException, IllegalAccessException,
+ InvocationTargetException;
+
+ /**
+ * Returns an array of <code>TypeVariable</code> objects that represents
+ * the type variables declared by this constructor, in declaration order.
+ * An array of size zero is returned if this constructor has no type
+ * variables.
+ *
+ * @return the type variables associated with this constructor.
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ public TypeVariable<Constructor<T>>[] getTypeParameters()
+ {
+ String sig = getSignature();
+ if (sig == null)
+ return new TypeVariable[0];
+ MethodSignatureParser p = new MethodSignatureParser(this, sig);
+ return p.getTypeParameters();
+ }
+
+ /**
+ * Return the String in the Signature attribute for this constructor. If there
+ * is no Signature attribute, return null.
+ */
+ private native String getSignature();
+
+ /**
+ * Returns an array of <code>Type</code> objects that represents
+ * the exception types declared by this constructor, in declaration order.
+ * An array of size zero is returned if this constructor declares no
+ * exceptions.
+ *
+ * @return the exception types declared by this constructor.
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ public Type[] getGenericExceptionTypes()
+ {
+ String sig = getSignature();
+ if (sig == null)
+ return getExceptionTypes();
+ MethodSignatureParser p = new MethodSignatureParser(this, sig);
+ return p.getGenericExceptionTypes();
+ }
+
+ /**
+ * Returns an array of <code>Type</code> objects that represents
+ * the parameter list for this constructor, in declaration order.
+ * An array of size zero is returned if this constructor takes no
+ * parameters.
+ *
+ * @return a list of the types of the constructor's parameters
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ public Type[] getGenericParameterTypes()
+ {
+ String sig = getSignature();
+ if (sig == null)
+ return getParameterTypes();
+ MethodSignatureParser p = new MethodSignatureParser(this, sig);
+ return p.getGenericParameterTypes();
+ }
+
+ /**
+ * @throws NullPointerException {@inheritDoc}
+ * @since 1.5
+ */
+ public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
+ if (annotationClass == null)
+ throw new NullPointerException();
+
+ return (T)declaredAnnotations().get(annotationClass);
+ }
+
+ /**
+ * @since 1.5
+ */
+ public Annotation[] getDeclaredAnnotations() {
+ return declaredAnnotations().values().toArray(EMPTY_ANNOTATIONS_ARRAY);
+ }
+
+ /**
+ * Parses the annotations if they aren't parsed yet and stores them into
+ * the declaredAnnotations map and return this map.
+ */
+ private synchronized native Map<Class<? extends Annotation>, Annotation> declaredAnnotations();
+
+ /**
+ * Returns an array of arrays that represent the annotations on the formal
+ * parameters, in declaration order, of the method represented by
+ * this <tt>Method</tt> object. (Returns an array of length zero if the
+ * underlying method is parameterless. If the method has one or more
+ * parameters, a nested array of length zero is returned for each parameter
+ * with no annotations.) The annotation objects contained in the returned
+ * arrays are serializable. The caller of this method is free to modify
+ * the returned arrays; it will have no effect on the arrays returned to
+ * other callers.
+ *
+ * @return an array of arrays that represent the annotations on the formal
+ * parameters, in declaration order, of the method represented by this
+ * Method object
+ * @since 1.5
+ */
+ public native Annotation[][] getParameterAnnotations();
+}
--- /dev/null
+/* java.lang.reflect.Field - reflection of Java fields
+ Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.lang.reflect;
+
+import gnu.java.lang.ClassHelper;
+
+import gnu.java.lang.reflect.FieldSignatureParser;
+
+import java.lang.annotation.Annotation;
+import java.util.Map;
+
+
+/**
+ * The Field class represents a member variable of a class. It also allows
+ * dynamic access to a member, via reflection. This works for both
+ * static and instance fields. Operations on Field objects know how to
+ * do widening conversions, but throw {@link IllegalArgumentException} if
+ * a narrowing conversion would be necessary. You can query for information
+ * on this Field regardless of location, but get and set access may be limited
+ * by Java language access controls. If you can't do it in the compiler, you
+ * can't normally do it here either.<p>
+ *
+ * <B>Note:</B> This class returns and accepts types as Classes, even
+ * primitive types; there are Class types defined that represent each
+ * different primitive type. They are <code>java.lang.Boolean.TYPE,
+ * java.lang.Byte.TYPE,</code>, also available as <code>boolean.class,
+ * byte.class</code>, etc. These are not to be confused with the
+ * classes <code>java.lang.Boolean, java.lang.Byte</code>, etc., which are
+ * real classes.<p>
+ *
+ * Also note that this is not a serializable class. It is entirely feasible
+ * to make it serializable using the Externalizable interface, but this is
+ * on Sun, not me.
+ *
+ * @author John Keiser
+ * @author Eric Blake <ebb9@email.byu.edu>
+ * @see Member
+ * @see Class
+ * @see Class#getField(String)
+ * @see Class#getDeclaredField(String)
+ * @see Class#getFields()
+ * @see Class#getDeclaredFields()
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public final class Field
+extends AccessibleObject implements Member
+{
+ private Class clazz;
+ private String name;
+ private int slot;
+
+ /**
+ * Unparsed annotations.
+ */
+ private byte[] annotations = null;
+
+ /**
+ * Annotations get parsed the first time they are
+ * accessed and are then cached it this map.
+ */
+ private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations = null;
+
+ private static final int FIELD_MODIFIERS
+ = Modifier.FINAL | Modifier.PRIVATE | Modifier.PROTECTED
+ | Modifier.PUBLIC | Modifier.STATIC | Modifier.TRANSIENT
+ | Modifier.VOLATILE;
+
+ /**
+ * Helper array for creating a new array from a java.util.Container.
+ */
+ private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY =
+ new Annotation[0];
+
+ /**
+ * This class is uninstantiable except natively.
+ */
+ private Field(Class declaringClass, String name, int slot)
+ {
+ this.clazz = declaringClass;
+ this.name = name;
+ this.slot = slot;
+ }
+
+ /**
+ * Gets the class that declared this field, or the class where this field
+ * is a non-inherited member.
+ * @return the class that declared this member
+ */
+ public Class<?> getDeclaringClass()
+ {
+ return clazz;
+ }
+
+ /**
+ * Gets the name of this field.
+ * @return the name of this field
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Return the raw modifiers for this field.
+ * @return the field's modifiers
+ */
+ private native int getModifiersInternal();
+
+ /**
+ * Gets the modifiers this field uses. Use the <code>Modifier</code>
+ * class to interpret the values. A field can only have a subset of the
+ * following modifiers: public, private, protected, static, final,
+ * transient, and volatile.
+ *
+ * @return an integer representing the modifiers to this Member
+ * @see Modifier
+ */
+ public int getModifiers()
+ {
+ return getModifiersInternal() & FIELD_MODIFIERS;
+ }
+
+ /**
+ * Return true if this field is synthetic, false otherwise.
+ * @since 1.5
+ */
+ public boolean isSynthetic()
+ {
+ return (getModifiersInternal() & Modifier.SYNTHETIC) != 0;
+ }
+
+ /**
+ * Return true if this field represents an enum constant,
+ * false otherwise.
+ * @since 1.5
+ */
+ public boolean isEnumConstant()
+ {
+ return (getModifiersInternal() & Modifier.ENUM) != 0;
+ }
+
+ /**
+ * Gets the type of this field.
+ * @return the type of this field
+ */
+ public native Class<?> getType();
+
+ /**
+ * Compare two objects to see if they are semantically equivalent.
+ * Two Fields are semantically equivalent if they have the same declaring
+ * class, name, and type. Since you can't creat a Field except through
+ * the VM, this is just the == relation.
+ *
+ * @param o the object to compare to
+ * @return <code>true</code> if they are equal; <code>false</code> if not
+ */
+ public boolean equals(Object o)
+ {
+ if (!(o instanceof Field))
+ return false;
+ Field that = (Field)o;
+ if (this.getDeclaringClass() != that.getDeclaringClass())
+ return false;
+ if (!this.getName().equals(that.getName()))
+ return false;
+ if (this.getType() != that.getType())
+ return false;
+ return true;
+ }
+
+ /**
+ * Get the hash code for the Field. The Field hash code is the hash code
+ * of its name XOR'd with the hash code of its class name.
+ *
+ * @return the hash code for the object.
+ */
+ public int hashCode()
+ {
+ return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
+ }
+
+ /**
+ * Get a String representation of the Field. A Field's String
+ * representation is "<modifiers> <type>
+ * <class>.<fieldname>".<br> Example:
+ * <code>public transient boolean gnu.parse.Parser.parseComplete</code>
+ *
+ * @return the String representation of the Field
+ */
+ public String toString()
+ {
+ // 64 is a reasonable buffer initial size for field
+ StringBuilder sb = new StringBuilder(64);
+ Modifier.toString(getModifiers(), sb).append(' ');
+ sb.append(ClassHelper.getUserName(getType())).append(' ');
+ sb.append(getDeclaringClass().getName()).append('.');
+ sb.append(getName());
+ return sb.toString();
+ }
+
+ public String toGenericString()
+ {
+ StringBuilder sb = new StringBuilder(64);
+ Modifier.toString(getModifiers(), sb).append(' ');
+ sb.append(getGenericType()).append(' ');
+ sb.append(getDeclaringClass().getName()).append('.');
+ sb.append(getName());
+ return sb.toString();
+ }
+
+ /**
+ * Get the value of this Field. If it is primitive, it will be wrapped
+ * in the appropriate wrapper type (boolean = java.lang.Boolean).<p>
+ *
+ * If the field is static, <code>o</code> will be ignored. Otherwise, if
+ * <code>o</code> is null, you get a <code>NullPointerException</code>,
+ * and if it is incompatible with the declaring class of the field, you
+ * get an <code>IllegalArgumentException</code>.<p>
+ *
+ * Next, if this Field enforces access control, your runtime context is
+ * evaluated, and you may have an <code>IllegalAccessException</code> if
+ * you could not access this field in similar compiled code. If the field
+ * is static, and its class is uninitialized, you trigger class
+ * initialization, which may end in a
+ * <code>ExceptionInInitializerError</code>.<p>
+ *
+ * Finally, the field is accessed, and primitives are wrapped (but not
+ * necessarily in new objects). This method accesses the field of the
+ * declaring class, even if the instance passed in belongs to a subclass
+ * which declares another field to hide this one.
+ *
+ * @param o the object to get the value of this Field from
+ * @return the value of the Field
+ * @throws IllegalAccessException if you could not normally access this field
+ * (i.e. it is not public)
+ * @throws IllegalArgumentException if <code>o</code> is not an instance of
+ * the class or interface declaring this field
+ * @throws NullPointerException if <code>o</code> is null and this field
+ * requires an instance
+ * @throws ExceptionInInitializerError if accessing a static field triggered
+ * class initialization, which then failed
+ * @see #getBoolean(Object)
+ * @see #getByte(Object)
+ * @see #getChar(Object)
+ * @see #getShort(Object)
+ * @see #getInt(Object)
+ * @see #getLong(Object)
+ * @see #getFloat(Object)
+ * @see #getDouble(Object)
+ */
+ public native Object get(Object o)
+ throws IllegalAccessException;
+
+ /**
+ * Get the value of this boolean Field. If the field is static,
+ * <code>o</code> will be ignored.
+ *
+ * @param o the object to get the value of this Field from
+ * @return the value of the Field
+ * @throws IllegalAccessException if you could not normally access this field
+ * (i.e. it is not public)
+ * @throws IllegalArgumentException if this is not a boolean field of
+ * <code>o</code>, or if <code>o</code> is not an instance of the
+ * declaring class of this field
+ * @throws NullPointerException if <code>o</code> is null and this field
+ * requires an instance
+ * @throws ExceptionInInitializerError if accessing a static field triggered
+ * class initialization, which then failed
+ * @see #get(Object)
+ */
+ public native boolean getBoolean(Object o)
+ throws IllegalAccessException;
+
+ /**
+ * Get the value of this byte Field. If the field is static,
+ * <code>o</code> will be ignored.
+ *
+ * @param o the object to get the value of this Field from
+ * @return the value of the Field
+ * @throws IllegalAccessException if you could not normally access this field
+ * (i.e. it is not public)
+ * @throws IllegalArgumentException if this is not a byte field of
+ * <code>o</code>, or if <code>o</code> is not an instance of the
+ * declaring class of this field
+ * @throws NullPointerException if <code>o</code> is null and this field
+ * requires an instance
+ * @throws ExceptionInInitializerError if accessing a static field triggered
+ * class initialization, which then failed
+ * @see #get(Object)
+ */
+ public native byte getByte(Object o)
+ throws IllegalAccessException;
+
+ /**
+ * Get the value of this Field as a char. If the field is static,
+ * <code>o</code> will be ignored.
+ *
+ * @throws IllegalAccessException if you could not normally access this field
+ * (i.e. it is not public)
+ * @throws IllegalArgumentException if this is not a char field of
+ * <code>o</code>, or if <code>o</code> is not an instance
+ * of the declaring class of this field
+ * @throws NullPointerException if <code>o</code> is null and this field
+ * requires an instance
+ * @throws ExceptionInInitializerError if accessing a static field triggered
+ * class initialization, which then failed
+ * @see #get(Object)
+ */
+ public native char getChar(Object o)
+ throws IllegalAccessException;
+
+ /**
+ * Get the value of this Field as a short. If the field is static,
+ * <code>o</code> will be ignored.
+ *
+ * @param o the object to get the value of this Field from
+ * @return the value of the Field
+ * @throws IllegalAccessException if you could not normally access this field
+ * (i.e. it is not public)
+ * @throws IllegalArgumentException if this is not a byte or short
+ * field of <code>o</code>, or if <code>o</code> is not an instance
+ * of the declaring class of this field
+ * @throws NullPointerException if <code>o</code> is null and this field
+ * requires an instance
+ * @throws ExceptionInInitializerError if accessing a static field triggered
+ * class initialization, which then failed
+ * @see #get(Object)
+ */
+ public native short getShort(Object o)
+ throws IllegalAccessException;
+
+ /**
+ * Get the value of this Field as an int. If the field is static,
+ * <code>o</code> will be ignored.
+ *
+ * @param o the object to get the value of this Field from
+ * @return the value of the Field
+ * @throws IllegalAccessException if you could not normally access this field
+ * (i.e. it is not public)
+ * @throws IllegalArgumentException if this is not a byte, short, char, or
+ * int field of <code>o</code>, or if <code>o</code> is not an
+ * instance of the declaring class of this field
+ * @throws NullPointerException if <code>o</code> is null and this field
+ * requires an instance
+ * @throws ExceptionInInitializerError if accessing a static field triggered
+ * class initialization, which then failed
+ * @see #get(Object)
+ */
+ public native int getInt(Object o)
+ throws IllegalAccessException;
+
+ /**
+ * Get the value of this Field as a long. If the field is static,
+ * <code>o</code> will be ignored.
+ *
+ * @param o the object to get the value of this Field from
+ * @return the value of the Field
+ * @throws IllegalAccessException if you could not normally access this field
+ * (i.e. it is not public)
+ * @throws IllegalArgumentException if this is not a byte, short, char, int,
+ * or long field of <code>o</code>, or if <code>o</code> is not an
+ * instance of the declaring class of this field
+ * @throws NullPointerException if <code>o</code> is null and this field
+ * requires an instance
+ * @throws ExceptionInInitializerError if accessing a static field triggered
+ * class initialization, which then failed
+ * @see #get(Object)
+ */
+ public native long getLong(Object o)
+ throws IllegalAccessException;
+
+ /**
+ * Get the value of this Field as a float. If the field is static,
+ * <code>o</code> will be ignored.
+ *
+ * @param o the object to get the value of this Field from
+ * @return the value of the Field
+ * @throws IllegalAccessException if you could not normally access this field
+ * (i.e. it is not public)
+ * @throws IllegalArgumentException if this is not a byte, short, char, int,
+ * long, or float field of <code>o</code>, or if <code>o</code> is
+ * not an instance of the declaring class of this field
+ * @throws NullPointerException if <code>o</code> is null and this field
+ * requires an instance
+ * @throws ExceptionInInitializerError if accessing a static field triggered
+ * class initialization, which then failed
+ * @see #get(Object)
+ */
+ public native float getFloat(Object o)
+ throws IllegalAccessException;
+
+ /**
+ * Get the value of this Field as a double. If the field is static,
+ * <code>o</code> will be ignored.
+ *
+ * @param o the object to get the value of this Field from
+ * @return the value of the Field
+ * @throws IllegalAccessException if you could not normally access this field
+ * (i.e. it is not public)
+ * @throws IllegalArgumentException if this is not a byte, short, char, int,
+ * long, float, or double field of <code>o</code>, or if
+ * <code>o</code> is not an instance of the declaring class of this
+ * field
+ * @throws NullPointerException if <code>o</code> is null and this field
+ * requires an instance
+ * @throws ExceptionInInitializerError if accessing a static field triggered
+ * class initialization, which then failed
+ * @see #get(Object)
+ */
+ public native double getDouble(Object o)
+ throws IllegalAccessException;
+
+ /**
+ * Set the value of this Field. If it is a primitive field, the value
+ * will be unwrapped from the passed object (boolean = java.lang.Boolean).<p>
+ *
+ * If the field is static, <code>o</code> will be ignored. Otherwise, if
+ * <code>o</code> is null, you get a <code>NullPointerException</code>,
+ * and if it is incompatible with the declaring class of the field, you
+ * get an <code>IllegalArgumentException</code>.<p>
+ *
+ * Next, if this Field enforces access control, your runtime context is
+ * evaluated, and you may have an <code>IllegalAccessException</code> if
+ * you could not access this field in similar compiled code. This also
+ * occurs whether or not there is access control if the field is final.
+ * If the field is primitive, and unwrapping your argument fails, you will
+ * get an <code>IllegalArgumentException</code>; likewise, this error
+ * happens if <code>value</code> cannot be cast to the correct object type.
+ * If the field is static, and its class is uninitialized, you trigger class
+ * initialization, which may end in a
+ * <code>ExceptionInInitializerError</code>.<p>
+ *
+ * Finally, the field is set with the widened value. This method accesses
+ * the field of the declaring class, even if the instance passed in belongs
+ * to a subclass which declares another field to hide this one.
+ *
+ * @param o the object to set this Field on
+ * @param value the value to set this Field to
+ * @throws IllegalAccessException if you could not normally access this field
+ * (i.e. it is not public)
+ * @throws IllegalArgumentException if <code>value</code> cannot be
+ * converted by a widening conversion to the underlying type of
+ * the Field, or if <code>o</code> is not an instance of the class
+ * declaring this field
+ * @throws NullPointerException if <code>o</code> is null and this field
+ * requires an instance
+ * @throws ExceptionInInitializerError if accessing a static field triggered
+ * class initialization, which then failed
+ * @see #setBoolean(Object, boolean)
+ * @see #setByte(Object, byte)
+ * @see #setChar(Object, char)
+ * @see #setShort(Object, short)
+ * @see #setInt(Object, int)
+ * @see #setLong(Object, long)
+ * @see #setFloat(Object, float)
+ * @see #setDouble(Object, double)
+ */
+ public native void set(Object o, Object value)
+ throws IllegalAccessException;
+
+ /**
+ * Set this boolean Field. If the field is static, <code>o</code> will be
+ * ignored.
+ *
+ * @param o the object to set this Field on
+ * @param value the value to set this Field to
+ * @throws IllegalAccessException if you could not normally access this field
+ * (i.e. it is not public)
+ * @throws IllegalArgumentException if this is not a boolean field, or if
+ * <code>o</code> is not an instance of the class declaring this
+ * field
+ * @throws NullPointerException if <code>o</code> is null and this field
+ * requires an instance
+ * @throws ExceptionInInitializerError if accessing a static field triggered
+ * class initialization, which then failed
+ * @see #set(Object, Object)
+ */
+ public native void setBoolean(Object o, boolean value)
+ throws IllegalAccessException;
+
+ /**
+ * Set this byte Field. If the field is static, <code>o</code> will be
+ * ignored.
+ *
+ * @param o the object to set this Field on
+ * @param value the value to set this Field to
+ * @throws IllegalAccessException if you could not normally access this field
+ * (i.e. it is not public)
+ * @throws IllegalArgumentException if this is not a byte, short, int, long,
+ * float, or double field, or if <code>o</code> is not an instance
+ * of the class declaring this field
+ * @throws NullPointerException if <code>o</code> is null and this field
+ * requires an instance
+ * @throws ExceptionInInitializerError if accessing a static field triggered
+ * class initialization, which then failed
+ * @see #set(Object, Object)
+ */
+ public native void setByte(Object o, byte value)
+ throws IllegalAccessException;
+
+ /**
+ * Set this char Field. If the field is static, <code>o</code> will be
+ * ignored.
+ *
+ * @param o the object to set this Field on
+ * @param value the value to set this Field to
+ * @throws IllegalAccessException if you could not normally access this field
+ * (i.e. it is not public)
+ * @throws IllegalArgumentException if this is not a char, int, long,
+ * float, or double field, or if <code>o</code> is not an instance
+ * of the class declaring this field
+ * @throws NullPointerException if <code>o</code> is null and this field
+ * requires an instance
+ * @throws ExceptionInInitializerError if accessing a static field triggered
+ * class initialization, which then failed
+ * @see #set(Object, Object)
+ */
+ public native void setChar(Object o, char value)
+ throws IllegalAccessException;
+
+ /**
+ * Set this short Field. If the field is static, <code>o</code> will be
+ * ignored.
+ *
+ * @param o the object to set this Field on
+ * @param value the value to set this Field to
+ * @throws IllegalAccessException if you could not normally access this field
+ * (i.e. it is not public)
+ * @throws IllegalArgumentException if this is not a short, int, long,
+ * float, or double field, or if <code>o</code> is not an instance
+ * of the class declaring this field
+ * @throws NullPointerException if <code>o</code> is null and this field
+ * requires an instance
+ * @throws ExceptionInInitializerError if accessing a static field triggered
+ * class initialization, which then failed
+ * @see #set(Object, Object)
+ */
+ public native void setShort(Object o, short value)
+ throws IllegalAccessException;
+
+ /**
+ * Set this int Field. If the field is static, <code>o</code> will be
+ * ignored.
+ *
+ * @param o the object to set this Field on
+ * @param value the value to set this Field to
+ * @throws IllegalAccessException if you could not normally access this field
+ * (i.e. it is not public)
+ * @throws IllegalArgumentException if this is not an int, long, float, or
+ * double field, or if <code>o</code> is not an instance of the
+ * class declaring this field
+ * @throws NullPointerException if <code>o</code> is null and this field
+ * requires an instance
+ * @throws ExceptionInInitializerError if accessing a static field triggered
+ * class initialization, which then failed
+ * @see #set(Object, Object)
+ */
+ public native void setInt(Object o, int value)
+ throws IllegalAccessException;
+
+ /**
+ * Set this long Field. If the field is static, <code>o</code> will be
+ * ignored.
+ *
+ * @param o the object to set this Field on
+ * @param value the value to set this Field to
+ * @throws IllegalAccessException if you could not normally access this field
+ * (i.e. it is not public)
+ * @throws IllegalArgumentException if this is not a long, float, or double
+ * field, or if <code>o</code> is not an instance of the class
+ * declaring this field
+ * @throws NullPointerException if <code>o</code> is null and this field
+ * requires an instance
+ * @throws ExceptionInInitializerError if accessing a static field triggered
+ * class initialization, which then failed
+ * @see #set(Object, Object)
+ */
+ public native void setLong(Object o, long value)
+ throws IllegalAccessException;
+
+ /**
+ * Set this float Field. If the field is static, <code>o</code> will be
+ * ignored.
+ *
+ * @param o the object to set this Field on
+ * @param value the value to set this Field to
+ * @throws IllegalAccessException if you could not normally access this field
+ * (i.e. it is not public)
+ * @throws IllegalArgumentException if this is not a float or long field, or
+ * if <code>o</code> is not an instance of the class declaring this
+ * field
+ * @throws NullPointerException if <code>o</code> is null and this field
+ * requires an instance
+ * @throws ExceptionInInitializerError if accessing a static field triggered
+ * class initialization, which then failed
+ * @see #set(Object, Object)
+ */
+ public native void setFloat(Object o, float value)
+ throws IllegalAccessException;
+
+ /**
+ * Set this double Field. If the field is static, <code>o</code> will be
+ * ignored.
+ *
+ * @param o the object to set this Field on
+ * @param value the value to set this Field to
+ * @throws IllegalAccessException if you could not normally access this field
+ * (i.e. it is not public)
+ * @throws IllegalArgumentException if this is not a double field, or if
+ * <code>o</code> is not an instance of the class declaring this
+ * field
+ * @throws NullPointerException if <code>o</code> is null and this field
+ * requires an instance
+ * @throws ExceptionInInitializerError if accessing a static field triggered
+ * class initialization, which then failed
+ * @see #set(Object, Object)
+ */
+ public native void setDouble(Object o, double value)
+ throws IllegalAccessException;
+
+ /**
+ * Return the generic type of the field. If the field type is not a generic
+ * type, the method returns the same as <code>getType()</code>.
+ *
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ public Type getGenericType()
+ {
+ String signature = getSignature();
+ if (signature == null)
+ return getType();
+ FieldSignatureParser p = new FieldSignatureParser(getDeclaringClass(),
+ signature);
+ return p.getFieldType();
+ }
+
+ /**
+ * Return the String in the Signature attribute for this field. If there
+ * is no Signature attribute, return null.
+ */
+ private native String getSignature();
+
+ /**
+ * @throws NullPointerException {@inheritDoc}
+ * @since 1.5
+ */
+ public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
+ if (annotationClass == null)
+ throw new NullPointerException();
+
+ return (T)declaredAnnotations().get(annotationClass);
+ }
+
+ /**
+ * @since 1.5
+ */
+ public Annotation[] getDeclaredAnnotations() {
+ return declaredAnnotations().values().toArray(EMPTY_ANNOTATIONS_ARRAY);
+ }
+
+ /**
+ * Parses the annotations if they aren't parsed yet and stores them into
+ * the declaredAnnotations map and return this map.
+ */
+ private synchronized native Map<Class<? extends Annotation>, Annotation> declaredAnnotations();
+}
--- /dev/null
+/* java.lang.reflect.Method - reflection of Java methods
+ Copyright (C) 1998, 2001, 2002, 2005, 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.lang.reflect;
+
+import gnu.java.lang.ClassHelper;
+
+import gnu.java.lang.reflect.MethodSignatureParser;
+
+import java.lang.annotation.Annotation;
+import java.util.Map;
+import java.util.Arrays;
+
+/**
+ * The Method class represents a member method of a class. It also allows
+ * dynamic invocation, via reflection. This works for both static and
+ * instance methods. Invocation on Method objects knows how to do
+ * widening conversions, but throws {@link IllegalArgumentException} if
+ * a narrowing conversion would be necessary. You can query for information
+ * on this Method regardless of location, but invocation access may be limited
+ * by Java language access controls. If you can't do it in the compiler, you
+ * can't normally do it here either.<p>
+ *
+ * <B>Note:</B> This class returns and accepts types as Classes, even
+ * primitive types; there are Class types defined that represent each
+ * different primitive type. They are <code>java.lang.Boolean.TYPE,
+ * java.lang.Byte.TYPE,</code>, also available as <code>boolean.class,
+ * byte.class</code>, etc. These are not to be confused with the
+ * classes <code>java.lang.Boolean, java.lang.Byte</code>, etc., which are
+ * real classes.<p>
+ *
+ * Also note that this is not a serializable class. It is entirely feasible
+ * to make it serializable using the Externalizable interface, but this is
+ * on Sun, not me.
+ *
+ * @author John Keiser
+ * @author Eric Blake <ebb9@email.byu.edu>
+ * @see Member
+ * @see Class
+ * @see java.lang.Class#getMethod(String,Class[])
+ * @see java.lang.Class#getDeclaredMethod(String,Class[])
+ * @see java.lang.Class#getMethods()
+ * @see java.lang.Class#getDeclaredMethods()
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public final class Method
+extends AccessibleObject implements Member, GenericDeclaration
+{
+ Class clazz;
+ String name;
+ int slot;
+
+ /**
+ * Unparsed annotations.
+ */
+ private byte[] annotations = null;
+
+ /**
+ * Unparsed parameter annotations.
+ */
+ private byte[] parameterAnnotations = null;
+
+ /**
+ * Unparsed annotation default value.
+ */
+ private byte[] annotationDefault = null;
+
+ /**
+ * Annotations get parsed the first time they are
+ * accessed and are then cached it this map.
+ */
+ private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations = null;
+
+ private static final int METHOD_MODIFIERS
+ = Modifier.ABSTRACT | Modifier.FINAL | Modifier.NATIVE
+ | Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC
+ | Modifier.STATIC | Modifier.STRICT | Modifier.SYNCHRONIZED;
+
+ /**
+ * Helper array for creating a new array from a java.util.Container.
+ */
+ private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY =
+ new Annotation[0];
+
+ /**
+ * This class is uninstantiable.
+ */
+ private Method(Class declaringClass, String name, int slot)
+ {
+ this.clazz = declaringClass;
+ this.name = name;
+ this.slot = slot;
+ }
+
+ /**
+ * Gets the class that declared this method, or the class where this method
+ * is a non-inherited member.
+ * @return the class that declared this member
+ */
+ public Class<?> getDeclaringClass()
+ {
+ return clazz;
+ }
+
+ /**
+ * Gets the name of this method.
+ * @return the name of this method
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Return the raw modifiers for this method.
+ * @return the method's modifiers
+ */
+ private native int getModifiersInternal();
+
+ /**
+ * Gets the modifiers this method uses. Use the <code>Modifier</code>
+ * class to interpret the values. A method can only have a subset of the
+ * following modifiers: public, private, protected, abstract, static,
+ * final, synchronized, native, and strictfp.
+ *
+ * @return an integer representing the modifiers to this Member
+ * @see Modifier
+ */
+ public int getModifiers()
+ {
+ return getModifiersInternal() & METHOD_MODIFIERS;
+ }
+
+ /**
+ * Return true if this method is a bridge method. A bridge method
+ * is generated by the compiler in some situations involving
+ * generics and inheritance.
+ * @since 1.5
+ */
+ public boolean isBridge()
+ {
+ return (getModifiersInternal() & Modifier.BRIDGE) != 0;
+ }
+
+ /**
+ * Return true if this method is synthetic, false otherwise.
+ * @since 1.5
+ */
+ public boolean isSynthetic()
+ {
+ return (getModifiersInternal() & Modifier.SYNTHETIC) != 0;
+ }
+
+ /**
+ * Return true if this is a varargs method, that is if
+ * the method takes a variable number of arguments.
+ * @since 1.5
+ */
+ public boolean isVarArgs()
+ {
+ return (getModifiersInternal() & Modifier.VARARGS) != 0;
+ }
+
+ /**
+ * Gets the return type of this method.
+ * @return the type of this method
+ */
+ public native Class<?> getReturnType();
+
+ /**
+ * Get the parameter list for this method, in declaration order. If the
+ * method takes no parameters, returns a 0-length array (not null).
+ *
+ * @return a list of the types of the method's parameters
+ */
+ public native Class<?>[] getParameterTypes();
+
+ /**
+ * Get the exception types this method says it throws, in no particular
+ * order. If the method has no throws clause, returns a 0-length array
+ * (not null).
+ *
+ * @return a list of the types in the method's throws clause
+ */
+ public native Class<?>[] getExceptionTypes();
+
+ /**
+ * Compare two objects to see if they are semantically equivalent.
+ * Two Methods are semantically equivalent if they have the same declaring
+ * class, name, parameter list, and return type.
+ *
+ * @param o the object to compare to
+ * @return <code>true</code> if they are equal; <code>false</code> if not
+ */
+ public boolean equals(Object o)
+ {
+ // Implementation note:
+ // The following is a correct but possibly slow implementation.
+ //
+ // This class has a private field 'slot' that could be used by
+ // the VM implementation to "link" a particular method to a Class.
+ // In that case equals could be simply implemented as:
+ //
+ // if (o instanceof Method)
+ // {
+ // Method m = (Method)o;
+ // return m.clazz == this.clazz
+ // && m.slot == this.slot;
+ // }
+ // return false;
+ //
+ // If a VM uses the Method class as their native/internal representation
+ // then just using the following would be optimal:
+ //
+ // return this == o;
+ //
+ if (!(o instanceof Method))
+ return false;
+ Method that = (Method)o;
+ if (this.getDeclaringClass() != that.getDeclaringClass())
+ return false;
+ if (!this.getName().equals(that.getName()))
+ return false;
+ if (this.getReturnType() != that.getReturnType())
+ return false;
+ if (!Arrays.equals(this.getParameterTypes(), that.getParameterTypes()))
+ return false;
+ return true;
+ }
+
+ /**
+ * Get the hash code for the Method. The Method hash code is the hash code
+ * of its name XOR'd with the hash code of its class name.
+ *
+ * @return the hash code for the object
+ */
+ public int hashCode()
+ {
+ return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
+ }
+
+ /**
+ * Get a String representation of the Method. A Method's String
+ * representation is "<modifiers> <returntype>
+ * <methodname>(<paramtypes>) throws <exceptions>", where
+ * everything after ')' is omitted if there are no exceptions.<br> Example:
+ * <code>public static int run(java.lang.Runnable,int)</code>
+ *
+ * @return the String representation of the Method
+ */
+ public String toString()
+ {
+ // 128 is a reasonable buffer initial size for constructor
+ StringBuilder sb = new StringBuilder(128);
+ Modifier.toString(getModifiers(), sb).append(' ');
+ sb.append(ClassHelper.getUserName(getReturnType())).append(' ');
+ sb.append(getDeclaringClass().getName()).append('.');
+ sb.append(getName()).append('(');
+ Class[] c = getParameterTypes();
+ if (c.length > 0)
+ {
+ sb.append(ClassHelper.getUserName(c[0]));
+ for (int i = 1; i < c.length; i++)
+ sb.append(',').append(ClassHelper.getUserName(c[i]));
+ }
+ sb.append(')');
+ c = getExceptionTypes();
+ if (c.length > 0)
+ {
+ sb.append(" throws ").append(c[0].getName());
+ for (int i = 1; i < c.length; i++)
+ sb.append(',').append(c[i].getName());
+ }
+ return sb.toString();
+ }
+
+ public String toGenericString()
+ {
+ // 128 is a reasonable buffer initial size for constructor
+ StringBuilder sb = new StringBuilder(128);
+ Modifier.toString(getModifiers(), sb).append(' ');
+ Constructor.addTypeParameters(sb, getTypeParameters());
+ sb.append(getGenericReturnType()).append(' ');
+ sb.append(getDeclaringClass().getName()).append('.');
+ sb.append(getName()).append('(');
+ Type[] types = getGenericParameterTypes();
+ if (types.length > 0)
+ {
+ sb.append(types[0]);
+ for (int i = 1; i < types.length; i++)
+ sb.append(',').append(types[i]);
+ }
+ sb.append(')');
+ types = getGenericExceptionTypes();
+ if (types.length > 0)
+ {
+ sb.append(" throws ").append(types[0]);
+ for (int i = 1; i < types.length; i++)
+ sb.append(',').append(types[i]);
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Invoke the method. Arguments are automatically unwrapped and widened,
+ * and the result is automatically wrapped, if needed.<p>
+ *
+ * If the method is static, <code>o</code> will be ignored. Otherwise,
+ * the method uses dynamic lookup as described in JLS 15.12.4.4. You cannot
+ * mimic the behavior of nonvirtual lookup (as in super.foo()). This means
+ * you will get a <code>NullPointerException</code> if <code>o</code> is
+ * null, and an <code>IllegalArgumentException</code> if it is incompatible
+ * with the declaring class of the method. If the method takes 0 arguments,
+ * you may use null or a 0-length array for <code>args</code>.<p>
+ *
+ * Next, if this Method enforces access control, your runtime context is
+ * evaluated, and you may have an <code>IllegalAccessException</code> if
+ * you could not acces this method in similar compiled code. If the method
+ * is static, and its class is uninitialized, you trigger class
+ * initialization, which may end in a
+ * <code>ExceptionInInitializerError</code>.<p>
+ *
+ * Finally, the method is invoked. If it completes normally, the return value
+ * will be null for a void method, a wrapped object for a primitive return
+ * method, or the actual return of an Object method. If it completes
+ * abruptly, the exception is wrapped in an
+ * <code>InvocationTargetException</code>.
+ *
+ * @param o the object to invoke the method on
+ * @param args the arguments to the method
+ * @return the return value of the method, wrapped in the appropriate
+ * wrapper if it is primitive
+ * @throws IllegalAccessException if the method could not normally be called
+ * by the Java code (i.e. it is not public)
+ * @throws IllegalArgumentException if the number of arguments is incorrect;
+ * if the arguments types are wrong even with a widening conversion;
+ * or if <code>o</code> is not an instance of the class or interface
+ * declaring this method
+ * @throws InvocationTargetException if the method throws an exception
+ * @throws NullPointerException if <code>o</code> is null and this field
+ * requires an instance
+ * @throws ExceptionInInitializerError if accessing a static method triggered
+ * class initialization, which then failed
+ */
+ public Object invoke(Object o, Object... args)
+ throws IllegalAccessException, InvocationTargetException
+ {
+ return invokeNative(o, args, clazz, slot);
+ }
+
+ /*
+ * NATIVE HELPERS
+ */
+
+ private native Object invokeNative(Object o, Object[] args,
+ Class declaringClass, int slot)
+ throws IllegalAccessException, InvocationTargetException;
+
+ /**
+ * Returns an array of <code>TypeVariable</code> objects that represents
+ * the type variables declared by this constructor, in declaration order.
+ * An array of size zero is returned if this class has no type
+ * variables.
+ *
+ * @return the type variables associated with this class.
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ public TypeVariable<Method>[] getTypeParameters()
+ {
+ String sig = getSignature();
+ if (sig == null)
+ return new TypeVariable[0];
+ MethodSignatureParser p = new MethodSignatureParser(this, sig);
+ return p.getTypeParameters();
+ }
+
+ /**
+ * Return the String in the Signature attribute for this method. If there
+ * is no Signature attribute, return null.
+ */
+ private native String getSignature();
+
+ /**
+ * Returns an array of <code>Type</code> objects that represents
+ * the exception types declared by this method, in declaration order.
+ * An array of size zero is returned if this method declares no
+ * exceptions.
+ *
+ * @return the exception types declared by this method.
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ public Type[] getGenericExceptionTypes()
+ {
+ String sig = getSignature();
+ if (sig == null)
+ return getExceptionTypes();
+ MethodSignatureParser p = new MethodSignatureParser(this, sig);
+ return p.getGenericExceptionTypes();
+ }
+
+ /**
+ * Returns an array of <code>Type</code> objects that represents
+ * the parameter list for this method, in declaration order.
+ * An array of size zero is returned if this method takes no
+ * parameters.
+ *
+ * @return a list of the types of the method's parameters
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ public Type[] getGenericParameterTypes()
+ {
+ String sig = getSignature();
+ if (sig == null)
+ return getParameterTypes();
+ MethodSignatureParser p = new MethodSignatureParser(this, sig);
+ return p.getGenericParameterTypes();
+ }
+
+ /**
+ * Returns the return type of this method.
+ *
+ * @return the return type of this method
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ public Type getGenericReturnType()
+ {
+ String sig = getSignature();
+ if (sig == null)
+ return getReturnType();
+ MethodSignatureParser p = new MethodSignatureParser(this, sig);
+ return p.getGenericReturnType();
+ }
+
+ /**
+ * If this method is an annotation method, returns the default
+ * value for the method. If there is no default value, or if the
+ * method is not a member of an annotation type, returns null.
+ * Primitive types are wrapped.
+ *
+ * @throws TypeNotPresentException if the method returns a Class,
+ * and the class cannot be found
+ *
+ * @since 1.5
+ */
+ public native Object getDefaultValue();
+
+ /**
+ * @throws NullPointerException {@inheritDoc}
+ * @since 1.5
+ */
+ public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
+ if (annotationClass == null)
+ throw new NullPointerException();
+
+ return (T)declaredAnnotations().get(annotationClass);
+ }
+
+ /**
+ * @since 1.5
+ */
+ public Annotation[] getDeclaredAnnotations() {
+ return declaredAnnotations().values().toArray(EMPTY_ANNOTATIONS_ARRAY);
+ }
+
+ /**
+ * Parses the annotations if they aren't parsed yet and stores them into
+ * the declaredAnnotations map and return this map.
+ */
+ private synchronized native Map<Class<? extends Annotation>, Annotation> declaredAnnotations();
+
+ /**
+ * Returns an array of arrays that represent the annotations on the formal
+ * parameters, in declaration order, of the method represented by
+ * this <tt>Method</tt> object. (Returns an array of length zero if the
+ * underlying method is parameterless. If the method has one or more
+ * parameters, a nested array of length zero is returned for each parameter
+ * with no annotations.) The annotation objects contained in the returned
+ * arrays are serializable. The caller of this method is free to modify
+ * the returned arrays; it will have no effect on the arrays returned to
+ * other callers.
+ *
+ * @return an array of arrays that represent the annotations on the formal
+ * parameters, in declaration order, of the method represented by this
+ * Method object
+ * @since 1.5
+ */
+ public native Annotation[][] getParameterAnnotations();
+}
--- /dev/null
+/* VMAccessController.java -- VM-specific access controller methods.
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.security;
+
+import java.util.HashSet;
+import java.util.LinkedList;
+
+final class VMAccessController
+{
+
+ // Fields.
+ // -------------------------------------------------------------------------
+
+ /**
+ * This is a per-thread stack of AccessControlContext objects (which can
+ * be null) for each call to AccessController.doPrivileged in each thread's
+ * call stack. We use this to remember which context object corresponds to
+ * which call.
+ */
+ private static final ThreadLocal contexts = new ThreadLocal();
+
+ /**
+ * This is a Boolean that, if set, tells getContext that it has already
+ * been called once, allowing us to handle recursive permission checks
+ * caused by methods getContext calls.
+ */
+ private static final ThreadLocal inGetContext = new ThreadLocal();
+
+ /**
+ * And we return this all-permissive context to ensure that privileged
+ * methods called from getContext succeed.
+ */
+ private static final AccessControlContext DEFAULT_CONTEXT;
+ static
+ {
+ CodeSource source = new CodeSource(null, null);
+ Permissions permissions = new Permissions();
+ permissions.add(new AllPermission());
+ ProtectionDomain[] domain = new ProtectionDomain[] {
+ new ProtectionDomain(source, permissions)
+ };
+ DEFAULT_CONTEXT = new AccessControlContext(domain);
+ }
+
+ private static final boolean DEBUG = gnu.classpath.Configuration.DEBUG;
+ private static void debug(String msg)
+ {
+ System.err.print(">>> VMAccessController: ");
+ System.err.println(msg);
+ }
+
+ // Constructors.
+ // -------------------------------------------------------------------------
+
+ private VMAccessController() { }
+
+ // Class methods.
+ // -------------------------------------------------------------------------
+
+ /**
+ * Relate a class (which should be an instance of {@link PrivilegedAction}
+ * with an access control context. This method is used by {@link
+ * AccessController#doPrivileged(java.security.PrivilegedAction,java.security.AccessControlContext)}
+ * to set up the context that will be returned by {@link #getContext()}.
+ * This method relates the class to the current thread, so contexts
+ * pushed from one thread will not be available to another.
+ *
+ * @param acc The access control context.
+ */
+ static void pushContext (AccessControlContext acc)
+ {
+ if (DEBUG)
+ debug("pushing " + acc);
+ LinkedList stack = (LinkedList) contexts.get();
+ if (stack == null)
+ {
+ if (DEBUG)
+ debug("no stack... creating ");
+ stack = new LinkedList();
+ contexts.set(stack);
+ }
+ stack.addFirst(acc);
+ }
+
+ /**
+ * Removes the relation of a class to an {@link AccessControlContext}.
+ * This method is used by {@link AccessController} when exiting from a
+ * call to {@link
+ * AccessController#doPrivileged(java.security.PrivilegedAction,java.security.AccessControlContext)}.
+ */
+ static void popContext()
+ {
+ if (DEBUG)
+ debug("popping context");
+
+ // Stack should never be null, nor should it be empty, if this method
+ // and its counterpart has been called properly.
+ LinkedList stack = (LinkedList) contexts.get();
+ if (stack != null)
+ {
+ stack.removeFirst();
+ if (stack.isEmpty())
+ contexts.set(null);
+ }
+ else if (DEBUG)
+ {
+ debug("no stack during pop?????");
+ }
+ }
+
+ /**
+ * Examine the method stack of the currently running thread, and create
+ * an {@link AccessControlContext} filled in with the appropriate {@link
+ * ProtectionDomain} objects given this stack.
+ *
+ * @return The context.
+ */
+ static AccessControlContext getContext()
+ {
+ // If we are already in getContext, but called a method that needs
+ // a permission check, return the all-permissive context so methods
+ // called from here succeed.
+ //
+ // XXX is this necessary? We should verify if there are any calls in
+ // the stack below this method that require permission checks.
+ Boolean inCall = (Boolean) inGetContext.get();
+ if (inCall != null && inCall.booleanValue())
+ {
+ if (DEBUG)
+ debug("already in getContext");
+ return DEFAULT_CONTEXT;
+ }
+
+ inGetContext.set(Boolean.TRUE);
+
+ Object[][] stack = getStack();
+ Class[] classes = (Class[]) stack[0];
+ String[] methods = (String[]) stack[1];
+
+ if (DEBUG)
+ debug("got trace of length " + classes.length);
+
+ HashSet domains = new HashSet();
+ HashSet seenDomains = new HashSet();
+ AccessControlContext context = null;
+ int privileged = 0;
+
+ // We walk down the stack, adding each ProtectionDomain for each
+ // class in the call stack. If we reach a call to doPrivileged,
+ // we don't add any more stack frames. We skip the first three stack
+ // frames, since they comprise the calls to getStack, getContext,
+ // and AccessController.getContext.
+ for (int i = 3; i < classes.length && privileged < 2; i++)
+ {
+ Class clazz = classes[i];
+ String method = methods[i];
+
+ if (DEBUG)
+ {
+ debug("checking " + clazz + "." + method);
+ // subject to getClassLoader RuntimePermission
+ debug("loader = " + clazz.getClassLoader());
+ }
+
+ // If the previous frame was a call to doPrivileged, then this is
+ // the last frame we look at.
+ if (privileged == 1)
+ privileged = 2;
+
+ if (clazz.equals (AccessController.class)
+ && method.equals ("doPrivileged"))
+ {
+ // If there was a call to doPrivileged with a supplied context,
+ // return that context. If using JAAS doAs*, it should be
+ // a context with a SubjectDomainCombiner
+ LinkedList l = (LinkedList) contexts.get();
+ if (l != null)
+ context = (AccessControlContext) l.getFirst();
+ privileged = 1;
+ }
+
+ // subject to getProtectionDomain RuntimePermission
+ ProtectionDomain domain = clazz.getProtectionDomain();
+
+ if (domain == null)
+ continue;
+ if (seenDomains.contains(domain))
+ continue;
+ seenDomains.add(domain);
+
+ // Create a static snapshot of this domain, which may change over time
+ // if the current policy changes.
+ domains.add(new ProtectionDomain(domain.getCodeSource(),
+ domain.getPermissions()));
+ }
+
+ if (DEBUG)
+ debug("created domains: " + domains);
+
+ ProtectionDomain[] result = (ProtectionDomain[])
+ domains.toArray(new ProtectionDomain[domains.size()]);
+
+ if (context != null)
+ {
+ DomainCombiner dc = context.getDomainCombiner ();
+ // If the supplied context had no explicit DomainCombiner, use
+ // our private version, which computes the intersection of the
+ // context's domains with the derived set.
+ if (dc == null)
+ context = new AccessControlContext
+ (IntersectingDomainCombiner.SINGLETON.combine
+ (result, context.getProtectionDomains ()));
+ // Use the supplied DomainCombiner. This should be secure,
+ // because only trusted code may create an
+ // AccessControlContext with a custom DomainCombiner.
+ else
+ context = new AccessControlContext (result, context, dc);
+ }
+ // No context was supplied. Return the derived one.
+ else
+ context = new AccessControlContext (result);
+
+ inGetContext.set(Boolean.FALSE);
+ return context;
+ }
+
+ /**
+ * Returns a snapshot of the current call stack as a pair of arrays:
+ * the first an array of classes in the call stack, the second an array
+ * of strings containing the method names in the call stack. The two
+ * arrays match up, meaning that method <i>i</i> is declared in class
+ * <i>i</i>. The arrays are clean; it will only contain Java methods,
+ * and no element of the list should be null.
+ *
+ * <p>The default implementation returns an empty stack, which will be
+ * interpreted as having no permissions whatsoever.
+ *
+ * @return A pair of arrays describing the current call stack. The first
+ * element is an array of Class objects, and the second is an array
+ * of Strings comprising the method names.
+ */
+// private static Object[][] getStack()
+// {
+// return new Object[][] { new Class[0], new String[0] };
+// }
+ private native static Object[][] getStack();
+}
--- /dev/null
+/*
+ * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.misc;
+
+import java.security.*;
+import java.lang.reflect.*;
+
+
+/**
+ * A collection of methods for performing low-level, unsafe operations.
+ * Although the class and all methods are public, use of this class is
+ * limited because only trusted code can obtain instances of it.
+ *
+ * @author John R. Rose
+ * @version 1.28, 07/06/04
+ * @see #getUnsafe
+ */
+
+public final class Unsafe {
+
+ private static native void registerNatives();
+ static {
+ registerNatives();
+// sun.reflect.Reflection.registerMethodsToFilter(Unsafe.class, "getUnsafe");
+ }
+
+ private Unsafe() {}
+
+ private static final Unsafe theUnsafe = new Unsafe();
+
+ /**
+ * Provides the caller with the capability of performing unsafe
+ * operations.
+ *
+ * <p> The returned <code>Unsafe</code> object should be carefully guarded
+ * by the caller, since it can be used to read and write data at arbitrary
+ * memory addresses. It must never be passed to untrusted code.
+ *
+ * <p> Most methods in this class are very low-level, and correspond to a
+ * small number of hardware instructions (on typical machines). Compilers
+ * are encouraged to optimize these methods accordingly.
+ *
+ * <p> Here is a suggested idiom for using unsafe operations:
+ *
+ * <blockquote><pre>
+ * class MyTrustedClass {
+ * private static final Unsafe unsafe = Unsafe.getUnsafe();
+ * ...
+ * private long myCountAddress = ...;
+ * public int getCount() { return unsafe.getByte(myCountAddress); }
+ * }
+ * </pre></blockquote>
+ *
+ * (It may assist compilers to make the local variable be
+ * <code>final</code>.)
+ *
+ * @exception SecurityException if a security manager exists and its
+ * <code>checkPropertiesAccess</code> method doesn't allow
+ * access to the system properties.
+ */
+ public static Unsafe getUnsafe() {
+ Class cc = sun.reflect.Reflection.getCallerClass(2);
+ if (cc.getClassLoader() != null)
+ throw new SecurityException("Unsafe");
+ return theUnsafe;
+ }
+
+ /// peek and poke operations
+ /// (compilers should optimize these to memory ops)
+
+ // These work on object fields in the Java heap.
+ // They will not work on elements of packed arrays.
+
+ /**
+ * Fetches a value from a given Java variable.
+ * More specifically, fetches a field or array element within the given
+ * object <code>o</code> at the given offset, or (if <code>o</code> is
+ * null) from the memory address whose numerical value is the given
+ * offset.
+ * <p>
+ * The results are undefined unless one of the following cases is true:
+ * <ul>
+ * <li>The offset was obtained from {@link #objectFieldOffset} on
+ * the {@link java.lang.reflect.Field} of some Java field and the object
+ * referred to by <code>o</code> is of a class compatible with that
+ * field's class.
+ *
+ * <li>The offset and object reference <code>o</code> (either null or
+ * non-null) were both obtained via {@link #staticFieldOffset}
+ * and {@link #staticFieldBase} (respectively) from the
+ * reflective {@link Field} representation of some Java field.
+ *
+ * <li>The object referred to by <code>o</code> is an array, and the offset
+ * is an integer of the form <code>B+N*S</code>, where <code>N</code> is
+ * a valid index into the array, and <code>B</code> and <code>S</code> are
+ * the values obtained by {@link #arrayBaseOffset} and {@link
+ * #arrayIndexScale} (respectively) from the array's class. The value
+ * referred to is the <code>N</code><em>th</em> element of the array.
+ *
+ * </ul>
+ * <p>
+ * If one of the above cases is true, the call references a specific Java
+ * variable (field or array element). However, the results are undefined
+ * if that variable is not in fact of the type returned by this method.
+ * <p>
+ * This method refers to a variable by means of two parameters, and so
+ * it provides (in effect) a <em>double-register</em> addressing mode
+ * for Java variables. When the object reference is null, this method
+ * uses its offset as an absolute address. This is similar in operation
+ * to methods such as {@link #getInt(long)}, which provide (in effect) a
+ * <em>single-register</em> addressing mode for non-Java variables.
+ * However, because Java variables may have a different layout in memory
+ * from non-Java variables, programmers should not assume that these
+ * two addressing modes are ever equivalent. Also, programmers should
+ * remember that offsets from the double-register addressing mode cannot
+ * be portably confused with longs used in the single-register addressing
+ * mode.
+ *
+ * @param o Java heap object in which the variable resides, if any, else
+ * null
+ * @param offset indication of where the variable resides in a Java heap
+ * object, if any, else a memory address locating the variable
+ * statically
+ * @return the value fetched from the indicated Java variable
+ * @throws RuntimeException No defined exceptions are thrown, not even
+ * {@link NullPointerException}
+ */
+ public native int getInt(Object o, long offset);
+
+ /**
+ * Stores a value into a given Java variable.
+ * <p>
+ * The first two parameters are interpreted exactly as with
+ * {@link #getInt(Object, long)} to refer to a specific
+ * Java variable (field or array element). The given value
+ * is stored into that variable.
+ * <p>
+ * The variable must be of the same type as the method
+ * parameter <code>x</code>.
+ *
+ * @param o Java heap object in which the variable resides, if any, else
+ * null
+ * @param offset indication of where the variable resides in a Java heap
+ * object, if any, else a memory address locating the variable
+ * statically
+ * @param x the value to store into the indicated Java variable
+ * @throws RuntimeException No defined exceptions are thrown, not even
+ * {@link NullPointerException}
+ */
+ public native void putInt(Object o, long offset, int x);
+
+ /**
+ * Fetches a reference value from a given Java variable.
+ * @see #getInt(Object, long)
+ */
+ public native Object getObject(Object o, long offset);
+
+ /**
+ * Stores a reference value into a given Java variable.
+ * <p>
+ * Unless the reference <code>x</code> being stored is either null
+ * or matches the field type, the results are undefined.
+ * If the reference <code>o</code> is non-null, car marks or
+ * other store barriers for that object (if the VM requires them)
+ * are updated.
+ * @see #putInt(Object, int, int)
+ */
+ public native void putObject(Object o, long offset, Object x);
+
+ /** @see #getInt(Object, long) */
+ public native boolean getBoolean(Object o, long offset);
+ /** @see #putInt(Object, int, int) */
+ public native void putBoolean(Object o, long offset, boolean x);
+ /** @see #getInt(Object, long) */
+ public native byte getByte(Object o, long offset);
+ /** @see #putInt(Object, int, int) */
+ public native void putByte(Object o, long offset, byte x);
+ /** @see #getInt(Object, long) */
+ public native short getShort(Object o, long offset);
+ /** @see #putInt(Object, int, int) */
+ public native void putShort(Object o, long offset, short x);
+ /** @see #getInt(Object, long) */
+ public native char getChar(Object o, long offset);
+ /** @see #putInt(Object, int, int) */
+ public native void putChar(Object o, long offset, char x);
+ /** @see #getInt(Object, long) */
+ public native long getLong(Object o, long offset);
+ /** @see #putInt(Object, int, int) */
+ public native void putLong(Object o, long offset, long x);
+ /** @see #getInt(Object, long) */
+ public native float getFloat(Object o, long offset);
+ /** @see #putInt(Object, int, int) */
+ public native void putFloat(Object o, long offset, float x);
+ /** @see #getInt(Object, long) */
+ public native double getDouble(Object o, long offset);
+ /** @see #putInt(Object, int, int) */
+ public native void putDouble(Object o, long offset, double x);
+
+ /**
+ * This method, like all others with 32-bit offsets, was native
+ * in a previous release but is now a wrapper which simply casts
+ * the offset to a long value. It provides backward compatibility
+ * with bytecodes compiled against 1.4.
+ * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
+ * See {@link #staticFieldOffset}.
+ */
+ @Deprecated
+ public int getInt(Object o, int offset) {
+ return getInt(o, (long)offset);
+ }
+
+ /**
+ * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
+ * See {@link #staticFieldOffset}.
+ */
+ @Deprecated
+ public void putInt(Object o, int offset, int x) {
+ putInt(o, (long)offset, x);
+ }
+
+ /**
+ * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
+ * See {@link #staticFieldOffset}.
+ */
+ @Deprecated
+ public Object getObject(Object o, int offset) {
+ return getObject(o, (long)offset);
+ }
+
+ /**
+ * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
+ * See {@link #staticFieldOffset}.
+ */
+ @Deprecated
+ public void putObject(Object o, int offset, Object x) {
+ putObject(o, (long)offset, x);
+ }
+
+ /**
+ * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
+ * See {@link #staticFieldOffset}.
+ */
+ @Deprecated
+ public boolean getBoolean(Object o, int offset) {
+ return getBoolean(o, (long)offset);
+ }
+
+ /**
+ * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
+ * See {@link #staticFieldOffset}.
+ */
+ @Deprecated
+ public void putBoolean(Object o, int offset, boolean x) {
+ putBoolean(o, (long)offset, x);
+ }
+
+ /**
+ * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
+ * See {@link #staticFieldOffset}.
+ */
+ @Deprecated
+ public byte getByte(Object o, int offset) {
+ return getByte(o, (long)offset);
+ }
+
+ /**
+ * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
+ * See {@link #staticFieldOffset}.
+ */
+ @Deprecated
+ public void putByte(Object o, int offset, byte x) {
+ putByte(o, (long)offset, x);
+ }
+
+ /**
+ * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
+ * See {@link #staticFieldOffset}.
+ */
+ @Deprecated
+ public short getShort(Object o, int offset) {
+ return getShort(o, (long)offset);
+ }
+
+ /**
+ * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
+ * See {@link #staticFieldOffset}.
+ */
+ @Deprecated
+ public void putShort(Object o, int offset, short x) {
+ putShort(o, (long)offset, x);
+ }
+
+ /**
+ * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
+ * See {@link #staticFieldOffset}.
+ */
+ @Deprecated
+ public char getChar(Object o, int offset) {
+ return getChar(o, (long)offset);
+ }
+
+ /**
+ * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
+ * See {@link #staticFieldOffset}.
+ */
+ @Deprecated
+ public void putChar(Object o, int offset, char x) {
+ putChar(o, (long)offset, x);
+ }
+
+ /**
+ * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
+ * See {@link #staticFieldOffset}.
+ */
+ @Deprecated
+ public long getLong(Object o, int offset) {
+ return getLong(o, (long)offset);
+ }
+
+ /**
+ * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
+ * See {@link #staticFieldOffset}.
+ */
+ @Deprecated
+ public void putLong(Object o, int offset, long x) {
+ putLong(o, (long)offset, x);
+ }
+
+ /**
+ * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
+ * See {@link #staticFieldOffset}.
+ */
+ @Deprecated
+ public float getFloat(Object o, int offset) {
+ return getFloat(o, (long)offset);
+ }
+
+ /**
+ * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
+ * See {@link #staticFieldOffset}.
+ */
+ @Deprecated
+ public void putFloat(Object o, int offset, float x) {
+ putFloat(o, (long)offset, x);
+ }
+
+ /**
+ * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
+ * See {@link #staticFieldOffset}.
+ */
+ @Deprecated
+ public double getDouble(Object o, int offset) {
+ return getDouble(o, (long)offset);
+ }
+
+ /**
+ * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
+ * See {@link #staticFieldOffset}.
+ */
+ @Deprecated
+ public void putDouble(Object o, int offset, double x) {
+ putDouble(o, (long)offset, x);
+ }
+
+ // These work on values in the C heap.
+
+ /**
+ * Fetches a value from a given memory address. If the address is zero, or
+ * does not point into a block obtained from {@link #allocateMemory}, the
+ * results are undefined.
+ *
+ * @see #allocateMemory
+ */
+ public native byte getByte(long address);
+
+ /**
+ * Stores a value into a given memory address. If the address is zero, or
+ * does not point into a block obtained from {@link #allocateMemory}, the
+ * results are undefined.
+ *
+ * @see #getByte(long)
+ */
+ public native void putByte(long address, byte x);
+
+ /** @see #getByte(long) */
+ public native short getShort(long address);
+ /** @see #putByte(long, byte) */
+ public native void putShort(long address, short x);
+ /** @see #getByte(long) */
+ public native char getChar(long address);
+ /** @see #putByte(long, byte) */
+ public native void putChar(long address, char x);
+ /** @see #getByte(long) */
+ public native int getInt(long address);
+ /** @see #putByte(long, byte) */
+ public native void putInt(long address, int x);
+ /** @see #getByte(long) */
+ public native long getLong(long address);
+ /** @see #putByte(long, byte) */
+ public native void putLong(long address, long x);
+ /** @see #getByte(long) */
+ public native float getFloat(long address);
+ /** @see #putByte(long, byte) */
+ public native void putFloat(long address, float x);
+ /** @see #getByte(long) */
+ public native double getDouble(long address);
+ /** @see #putByte(long, byte) */
+ public native void putDouble(long address, double x);
+
+ /**
+ * Fetches a native pointer from a given memory address. If the address is
+ * zero, or does not point into a block obtained from {@link
+ * #allocateMemory}, the results are undefined.
+ *
+ * <p> If the native pointer is less than 64 bits wide, it is extended as
+ * an unsigned number to a Java long. The pointer may be indexed by any
+ * given byte offset, simply by adding that offset (as a simple integer) to
+ * the long representing the pointer. The number of bytes actually read
+ * from the target address maybe determined by consulting {@link
+ * #addressSize}.
+ *
+ * @see #allocateMemory
+ */
+ public native long getAddress(long address);
+
+ /**
+ * Stores a native pointer into a given memory address. If the address is
+ * zero, or does not point into a block obtained from {@link
+ * #allocateMemory}, the results are undefined.
+ *
+ * <p> The number of bytes actually written at the target address maybe
+ * determined by consulting {@link #addressSize}.
+ *
+ * @see #getAddress(long)
+ */
+ public native void putAddress(long address, long x);
+
+ /// wrappers for malloc, realloc, free:
+
+ /**
+ * Allocates a new block of native memory, of the given size in bytes. The
+ * contents of the memory are uninitialized; they will generally be
+ * garbage. The resulting native pointer will never be zero, and will be
+ * aligned for all value types. Dispose of this memory by calling {@link
+ * #freeMemory}, or resize it with {@link #reallocateMemory}.
+ *
+ * @throws IllegalArgumentException if the size is negative or too large
+ * for the native size_t type
+ *
+ * @throws OutOfMemoryError if the allocation is refused by the system
+ *
+ * @see #getByte(long)
+ * @see #putByte(long, byte)
+ */
+ public native long allocateMemory(long bytes);
+
+ /**
+ * Resizes a new block of native memory, to the given size in bytes. The
+ * contents of the new block past the size of the old block are
+ * uninitialized; they will generally be garbage. The resulting native
+ * pointer will be zero if and only if the requested size is zero. The
+ * resulting native pointer will be aligned for all value types. Dispose
+ * of this memory by calling {@link #freeMemory}, or resize it with {@link
+ * #reallocateMemory}. The address passed to this method may be null, in
+ * which case an allocation will be performed.
+ *
+ * @throws IllegalArgumentException if the size is negative or too large
+ * for the native size_t type
+ *
+ * @throws OutOfMemoryError if the allocation is refused by the system
+ *
+ * @see #allocateMemory
+ */
+ public native long reallocateMemory(long address, long bytes);
+
+ /**
+ * Sets all bytes in a given block of memory to a fixed value
+ * (usually zero).
+ *
+ * <p>This method determines a block's base address by means of two parameters,
+ * and so it provides (in effect) a <em>double-register</em> addressing mode,
+ * as discussed in {@link #getInt(Object,long)}. When the object reference is null,
+ * the offset supplies an absolute base address.
+ *
+ * <p>The stores are in coherent (atomic) units of a size determined
+ * by the address and length parameters. If the effective address and
+ * length are all even modulo 8, the stores take place in 'long' units.
+ * If the effective address and length are (resp.) even modulo 4 or 2,
+ * the stores take place in units of 'int' or 'short'.
+ *
+ * @since 1.7
+ */
+ public native void setMemory(Object o, long offset, long bytes, byte value);
+
+ /**
+ * Sets all bytes in a given block of memory to a fixed value
+ * (usually zero). This provides a <em>single-register</em> addressing mode,
+ * as discussed in {@link #getInt(Object,long)}.
+ *
+ * <p>Equivalent to <code>setMemory(null, address, bytes, value)</code>.
+ */
+ public void setMemory(long address, long bytes, byte value) {
+ setMemory(null, address, bytes, value);
+ }
+
+ /**
+ * Sets all bytes in a given block of memory to a copy of another
+ * block.
+ *
+ * <p>This method determines each block's base address by means of two parameters,
+ * and so it provides (in effect) a <em>double-register</em> addressing mode,
+ * as discussed in {@link #getInt(Object,long)}. When the object reference is null,
+ * the offset supplies an absolute base address.
+ *
+ * <p>The transfers are in coherent (atomic) units of a size determined
+ * by the address and length parameters. If the effective addresses and
+ * length are all even modulo 8, the transfer takes place in 'long' units.
+ * If the effective addresses and length are (resp.) even modulo 4 or 2,
+ * the transfer takes place in units of 'int' or 'short'.
+ *
+ * @since 1.7
+ */
+ public native void copyMemory(Object srcBase, long srcOffset,
+ Object destBase, long destOffset,
+ long bytes);
+ /**
+ * Sets all bytes in a given block of memory to a copy of another
+ * block. This provides a <em>single-register</em> addressing mode,
+ * as discussed in {@link #getInt(Object,long)}.
+ *
+ * Equivalent to <code>copyMemory(null, srcAddress, null, destAddress, bytes)</code>.
+ */
+ public void copyMemory(long srcAddress, long destAddress, long bytes) {
+ copyMemory(null, srcAddress, null, destAddress, bytes);
+ }
+
+ /**
+ * Disposes of a block of native memory, as obtained from {@link
+ * #allocateMemory} or {@link #reallocateMemory}. The address passed to
+ * this method may be null, in which case no action is taken.
+ *
+ * @see #allocateMemory
+ */
+ public native void freeMemory(long address);
+
+ /// random queries
+
+ /**
+ * This constant differs from all results that will ever be returned from
+ * {@link #staticFieldOffset}, {@link #objectFieldOffset},
+ * or {@link #arrayBaseOffset}.
+ */
+ public static final int INVALID_FIELD_OFFSET = -1;
+
+ /**
+ * Returns the offset of a field, truncated to 32 bits.
+ * This method is implemented as follows:
+ * <blockquote><pre>
+ * public int fieldOffset(Field f) {
+ * if (Modifier.isStatic(f.getModifiers()))
+ * return (int) staticFieldOffset(f);
+ * else
+ * return (int) objectFieldOffset(f);
+ * }
+ * </pre></blockquote>
+ * @deprecated As of 1.4.1, use {@link #staticFieldOffset} for static
+ * fields and {@link #objectFieldOffset} for non-static fields.
+ */
+ @Deprecated
+ public int fieldOffset(Field f) {
+ if (Modifier.isStatic(f.getModifiers()))
+ return (int) staticFieldOffset(f);
+ else
+ return (int) objectFieldOffset(f);
+ }
+
+ /**
+ * Returns the base address for accessing some static field
+ * in the given class. This method is implemented as follows:
+ * <blockquote><pre>
+ * public Object staticFieldBase(Class c) {
+ * Field[] fields = c.getDeclaredFields();
+ * for (int i = 0; i < fields.length; i++) {
+ * if (Modifier.isStatic(fields[i].getModifiers())) {
+ * return staticFieldBase(fields[i]);
+ * }
+ * }
+ * return null;
+ * }
+ * </pre></blockquote>
+ * @deprecated As of 1.4.1, use {@link #staticFieldBase(Field)}
+ * to obtain the base pertaining to a specific {@link Field}.
+ * This method works only for JVMs which store all statics
+ * for a given class in one place.
+ */
+ @Deprecated
+ public Object staticFieldBase(Class c) {
+ Field[] fields = c.getDeclaredFields();
+ for (int i = 0; i < fields.length; i++) {
+ if (Modifier.isStatic(fields[i].getModifiers())) {
+ return staticFieldBase(fields[i]);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Report the location of a given field in the storage allocation of its
+ * class. Do not expect to perform any sort of arithmetic on this offset;
+ * it is just a cookie which is passed to the unsafe heap memory accessors.
+ *
+ * <p>Any given field will always have the same offset and base, and no
+ * two distinct fields of the same class will ever have the same offset
+ * and base.
+ *
+ * <p>As of 1.4.1, offsets for fields are represented as long values,
+ * although the Sun JVM does not use the most significant 32 bits.
+ * However, JVM implementations which store static fields at absolute
+ * addresses can use long offsets and null base pointers to express
+ * the field locations in a form usable by {@link #getInt(Object,long)}.
+ * Therefore, code which will be ported to such JVMs on 64-bit platforms
+ * must preserve all bits of static field offsets.
+ * @see #getInt(Object, long)
+ */
+ public native long staticFieldOffset(Field f);
+
+ /**
+ * Report the location of a given static field, in conjunction with {@link
+ * #staticFieldBase}.
+ * <p>Do not expect to perform any sort of arithmetic on this offset;
+ * it is just a cookie which is passed to the unsafe heap memory accessors.
+ *
+ * <p>Any given field will always have the same offset, and no two distinct
+ * fields of the same class will ever have the same offset.
+ *
+ * <p>As of 1.4.1, offsets for fields are represented as long values,
+ * although the Sun JVM does not use the most significant 32 bits.
+ * It is hard to imagine a JVM technology which needs more than
+ * a few bits to encode an offset within a non-array object,
+ * However, for consistency with other methods in this class,
+ * this method reports its result as a long value.
+ * @see #getInt(Object, long)
+ */
+ public native long objectFieldOffset(Field f);
+
+ /**
+ * Report the location of a given static field, in conjunction with {@link
+ * #staticFieldOffset}.
+ * <p>Fetch the base "Object", if any, with which static fields of the
+ * given class can be accessed via methods like {@link #getInt(Object,
+ * long)}. This value may be null. This value may refer to an object
+ * which is a "cookie", not guaranteed to be a real Object, and it should
+ * not be used in any way except as argument to the get and put routines in
+ * this class.
+ */
+ public native Object staticFieldBase(Field f);
+
+ /**
+ * Ensure the given class has been initialized. This is often
+ * needed in conjunction with obtaining the static field base of a
+ * class.
+ */
+ public native void ensureClassInitialized(Class c);
+
+ /**
+ * Report the offset of the first element in the storage allocation of a
+ * given array class. If {@link #arrayIndexScale} returns a non-zero value
+ * for the same class, you may use that scale factor, together with this
+ * base offset, to form new offsets to access elements of arrays of the
+ * given class.
+ *
+ * @see #getInt(Object, long)
+ * @see #putInt(Object, long, int)
+ */
+ public native int arrayBaseOffset(Class arrayClass);
+
+ /** The value of {@code arrayBaseOffset(boolean[].class)} */
+ public static final int ARRAY_BOOLEAN_BASE_OFFSET
+ = theUnsafe.arrayBaseOffset(boolean[].class);
+
+ /** The value of {@code arrayBaseOffset(byte[].class)} */
+ public static final int ARRAY_BYTE_BASE_OFFSET
+ = theUnsafe.arrayBaseOffset(byte[].class);
+
+ /** The value of {@code arrayBaseOffset(short[].class)} */
+ public static final int ARRAY_SHORT_BASE_OFFSET
+ = theUnsafe.arrayBaseOffset(short[].class);
+
+ /** The value of {@code arrayBaseOffset(char[].class)} */
+ public static final int ARRAY_CHAR_BASE_OFFSET
+ = theUnsafe.arrayBaseOffset(char[].class);
+
+ /** The value of {@code arrayBaseOffset(int[].class)} */
+ public static final int ARRAY_INT_BASE_OFFSET
+ = theUnsafe.arrayBaseOffset(int[].class);
+
+ /** The value of {@code arrayBaseOffset(long[].class)} */
+ public static final int ARRAY_LONG_BASE_OFFSET
+ = theUnsafe.arrayBaseOffset(long[].class);
+
+ /** The value of {@code arrayBaseOffset(float[].class)} */
+ public static final int ARRAY_FLOAT_BASE_OFFSET
+ = theUnsafe.arrayBaseOffset(float[].class);
+
+ /** The value of {@code arrayBaseOffset(double[].class)} */
+ public static final int ARRAY_DOUBLE_BASE_OFFSET
+ = theUnsafe.arrayBaseOffset(double[].class);
+
+ /** The value of {@code arrayBaseOffset(Object[].class)} */
+ public static final int ARRAY_OBJECT_BASE_OFFSET
+ = theUnsafe.arrayBaseOffset(Object[].class);
+
+ /**
+ * Report the scale factor for addressing elements in the storage
+ * allocation of a given array class. However, arrays of "narrow" types
+ * will generally not work properly with accessors like {@link
+ * #getByte(Object, int)}, so the scale factor for such classes is reported
+ * as zero.
+ *
+ * @see #arrayBaseOffset
+ * @see #getInt(Object, long)
+ * @see #putInt(Object, long, int)
+ */
+ public native int arrayIndexScale(Class arrayClass);
+
+ /** The value of {@code arrayIndexScale(boolean[].class)} */
+ public static final int ARRAY_BOOLEAN_INDEX_SCALE
+ = theUnsafe.arrayIndexScale(boolean[].class);
+
+ /** The value of {@code arrayIndexScale(byte[].class)} */
+ public static final int ARRAY_BYTE_INDEX_SCALE
+ = theUnsafe.arrayIndexScale(byte[].class);
+
+ /** The value of {@code arrayIndexScale(short[].class)} */
+ public static final int ARRAY_SHORT_INDEX_SCALE
+ = theUnsafe.arrayIndexScale(short[].class);
+
+ /** The value of {@code arrayIndexScale(char[].class)} */
+ public static final int ARRAY_CHAR_INDEX_SCALE
+ = theUnsafe.arrayIndexScale(char[].class);
+
+ /** The value of {@code arrayIndexScale(int[].class)} */
+ public static final int ARRAY_INT_INDEX_SCALE
+ = theUnsafe.arrayIndexScale(int[].class);
+
+ /** The value of {@code arrayIndexScale(long[].class)} */
+ public static final int ARRAY_LONG_INDEX_SCALE
+ = theUnsafe.arrayIndexScale(long[].class);
+
+ /** The value of {@code arrayIndexScale(float[].class)} */
+ public static final int ARRAY_FLOAT_INDEX_SCALE
+ = theUnsafe.arrayIndexScale(float[].class);
+
+ /** The value of {@code arrayIndexScale(double[].class)} */
+ public static final int ARRAY_DOUBLE_INDEX_SCALE
+ = theUnsafe.arrayIndexScale(double[].class);
+
+ /** The value of {@code arrayIndexScale(Object[].class)} */
+ public static final int ARRAY_OBJECT_INDEX_SCALE
+ = theUnsafe.arrayIndexScale(Object[].class);
+
+ /**
+ * Report the size in bytes of a native pointer, as stored via {@link
+ * #putAddress}. This value will be either 4 or 8. Note that the sizes of
+ * other primitive types (as stored in native memory blocks) is determined
+ * fully by their information content.
+ */
+ public native int addressSize();
+
+ /** The value of {@code addressSize()} */
+ public static final int ADDRESS_SIZE = theUnsafe.addressSize();
+
+ /**
+ * Report the size in bytes of a native memory page (whatever that is).
+ * This value will always be a power of two.
+ */
+ public native int pageSize();
+
+
+ /// random trusted operations from JNI:
+
+ /**
+ * Tell the VM to define a class, without security checks. By default, the
+ * class loader and protection domain come from the caller's class.
+ */
+ public native Class defineClass(String name, byte[] b, int off, int len,
+ ClassLoader loader,
+ ProtectionDomain protectionDomain);
+
+ public native Class defineClass(String name, byte[] b, int off, int len);
+
+ /** Allocate an instance but do not run any constructor.
+ Initializes the class if it has not yet been. */
+ public native Object allocateInstance(Class cls)
+ throws InstantiationException;
+
+ /** Lock the object. It must get unlocked via {@link #monitorExit}. */
+ public native void monitorEnter(Object o);
+
+ /**
+ * Unlock the object. It must have been locked via {@link
+ * #monitorEnter}.
+ */
+ public native void monitorExit(Object o);
+
+ /**
+ * Tries to lock the object. Returns true or false to indicate
+ * whether the lock succeeded. If it did, the object must be
+ * unlocked via {@link #monitorExit}.
+ */
+ public native boolean tryMonitorEnter(Object o);
+
+ /** Throw the exception without telling the verifier. */
+ public native void throwException(Throwable ee);
+
+
+ /**
+ * Atomically update Java variable to <tt>x</tt> if it is currently
+ * holding <tt>expected</tt>.
+ * @return <tt>true</tt> if successful
+ */
+ public final native boolean compareAndSwapObject(Object o, long offset,
+ Object expected,
+ Object x);
+
+ /**
+ * Atomically update Java variable to <tt>x</tt> if it is currently
+ * holding <tt>expected</tt>.
+ * @return <tt>true</tt> if successful
+ */
+ public final native boolean compareAndSwapInt(Object o, long offset,
+ int expected,
+ int x);
+
+ /**
+ * Atomically update Java variable to <tt>x</tt> if it is currently
+ * holding <tt>expected</tt>.
+ * @return <tt>true</tt> if successful
+ */
+ public final native boolean compareAndSwapLong(Object o, long offset,
+ long expected,
+ long x);
+
+ /**
+ * Fetches a reference value from a given Java variable, with volatile
+ * load semantics. Otherwise identical to {@link #getObject(Object, long)}
+ */
+ public native Object getObjectVolatile(Object o, long offset);
+
+ /**
+ * Stores a reference value into a given Java variable, with
+ * volatile store semantics. Otherwise identical to {@link #putObject(Object, long, Object)}
+ */
+ public native void putObjectVolatile(Object o, long offset, Object x);
+
+ /** Volatile version of {@link #getInt(Object, long)} */
+ public native int getIntVolatile(Object o, long offset);
+
+ /** Volatile version of {@link #putInt(Object, long, int)} */
+ public native void putIntVolatile(Object o, long offset, int x);
+
+ /** Volatile version of {@link #getBoolean(Object, long)} */
+ public native boolean getBooleanVolatile(Object o, long offset);
+
+ /** Volatile version of {@link #putBoolean(Object, long, boolean)} */
+ public native void putBooleanVolatile(Object o, long offset, boolean x);
+
+ /** Volatile version of {@link #getByte(Object, long)} */
+ public native byte getByteVolatile(Object o, long offset);
+
+ /** Volatile version of {@link #putByte(Object, long, byte)} */
+ public native void putByteVolatile(Object o, long offset, byte x);
+
+ /** Volatile version of {@link #getShort(Object, long)} */
+ public native short getShortVolatile(Object o, long offset);
+
+ /** Volatile version of {@link #putShort(Object, long, short)} */
+ public native void putShortVolatile(Object o, long offset, short x);
+
+ /** Volatile version of {@link #getChar(Object, long)} */
+ public native char getCharVolatile(Object o, long offset);
+
+ /** Volatile version of {@link #putChar(Object, long, char)} */
+ public native void putCharVolatile(Object o, long offset, char x);
+
+ /** Volatile version of {@link #getLong(Object, long)} */
+ public native long getLongVolatile(Object o, long offset);
+
+ /** Volatile version of {@link #putLong(Object, long, long)} */
+ public native void putLongVolatile(Object o, long offset, long x);
+
+ /** Volatile version of {@link #getFloat(Object, long)} */
+ public native float getFloatVolatile(Object o, long offset);
+
+ /** Volatile version of {@link #putFloat(Object, long, float)} */
+ public native void putFloatVolatile(Object o, long offset, float x);
+
+ /** Volatile version of {@link #getDouble(Object, long)} */
+ public native double getDoubleVolatile(Object o, long offset);
+
+ /** Volatile version of {@link #putDouble(Object, long, double)} */
+ public native void putDoubleVolatile(Object o, long offset, double x);
+
+ /**
+ * Version of {@link #putObjectVolatile(Object, long, Object)}
+ * that does not guarantee immediate visibility of the store to
+ * other threads. This method is generally only useful if the
+ * underlying field is a Java volatile (or if an array cell, one
+ * that is otherwise only accessed using volatile accesses).
+ */
+ public native void putOrderedObject(Object o, long offset, Object x);
+
+ /** Ordered/Lazy version of {@link #putIntVolatile(Object, long, int)} */
+ public native void putOrderedInt(Object o, long offset, int x);
+
+ /** Ordered/Lazy version of {@link #putLongVolatile(Object, long, long)} */
+ public native void putOrderedLong(Object o, long offset, long x);
+
+ /**
+ * Unblock the given thread blocked on <tt>park</tt>, or, if it is
+ * not blocked, cause the subsequent call to <tt>park</tt> not to
+ * block. Note: this operation is "unsafe" solely because the
+ * caller must somehow ensure that the thread has not been
+ * destroyed. Nothing special is usually required to ensure this
+ * when called from Java (in which there will ordinarily be a live
+ * reference to the thread) but this is not nearly-automatically
+ * so when calling from native code.
+ * @param thread the thread to unpark.
+ *
+ */
+ public native void unpark(Object thread);
+
+ /**
+ * Block current thread, returning when a balancing
+ * <tt>unpark</tt> occurs, or a balancing <tt>unpark</tt> has
+ * already occurred, or the thread is interrupted, or, if not
+ * absolute and time is not zero, the given time nanoseconds have
+ * elapsed, or if absolute, the given deadline in milliseconds
+ * since Epoch has passed, or spuriously (i.e., returning for no
+ * "reason"). Note: This operation is in the Unsafe class only
+ * because <tt>unpark</tt> is, so it would be strange to place it
+ * elsewhere.
+ */
+ public native void park(boolean isAbsolute, long time);
+
+ /**
+ * Gets the load average in the system run queue assigned
+ * to the available processors averaged over various periods of time.
+ * This method retrieves the given <tt>nelem</tt> samples and
+ * assigns to the elements of the given <tt>loadavg</tt> array.
+ * The system imposes a maximum of 3 samples, representing
+ * averages over the last 1, 5, and 15 minutes, respectively.
+ *
+ * @params loadavg an array of double of size nelems
+ * @params nelems the number of samples to be retrieved and
+ * must be 1 to 3.
+ *
+ * @return the number of samples actually retrieved; or -1
+ * if the load average is unobtainable.
+ */
+ public native int getLoadAverage(double[] loadavg, int nelems);
+}
--- /dev/null
+/*
+ * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.reflect;
+
+import java.lang.reflect.*;
+
+/** Provides reflective access to the constant pools of classes.
+ Currently this is needed to provide reflective access to annotations
+ but may be used by other internal subsystems in the future. */
+
+public class ConstantPool {
+ // Number of entries in this constant pool (= maximum valid constant pool index)
+ public int getSize() { return getSize0 (constantPoolOop); }
+ public Class getClassAt (int index) { return getClassAt0 (constantPoolOop, index); }
+ public Class getClassAtIfLoaded (int index) { return getClassAtIfLoaded0 (constantPoolOop, index); }
+ // Returns either a Method or Constructor.
+ // Static initializers are returned as Method objects.
+ public Member getMethodAt (int index) { return getMethodAt0 (constantPoolOop, index); }
+ public Member getMethodAtIfLoaded(int index) { return getMethodAtIfLoaded0(constantPoolOop, index); }
+ public Field getFieldAt (int index) { return getFieldAt0 (constantPoolOop, index); }
+ public Field getFieldAtIfLoaded (int index) { return getFieldAtIfLoaded0 (constantPoolOop, index); }
+ // Fetches the class name, member (field, method or interface
+ // method) name, and type descriptor as an array of three Strings
+ public String[] getMemberRefInfoAt (int index) { return getMemberRefInfoAt0 (constantPoolOop, index); }
+ public int getIntAt (int index) { return getIntAt0 (constantPoolOop, index); }
+ public long getLongAt (int index) { return getLongAt0 (constantPoolOop, index); }
+ public float getFloatAt (int index) { return getFloatAt0 (constantPoolOop, index); }
+ public double getDoubleAt (int index) { return getDoubleAt0 (constantPoolOop, index); }
+ public String getStringAt (int index) { return getStringAt0 (constantPoolOop, index); }
+ public String getUTF8At (int index) { return getUTF8At0 (constantPoolOop, index); }
+
+ //---------------------------------------------------------------------------
+ // Internals only below this point
+ //
+/* This hides this member from being visible through the reflection API in OpenJDK
+ * TODO: find out how to do this with GNU Classpath (if it's realy neccesary).
+
+ static {
+ Reflection.registerFieldsToFilter(ConstantPool.class, new String[] { "constantPoolOop" });
+ }
+*/
+ // HotSpot-internal constant pool object (set by the VM, name known to the VM)
+ private Object constantPoolOop;
+
+ private native int getSize0 (Object constantPoolOop);
+ private native Class getClassAt0 (Object constantPoolOop, int index);
+ private native Class getClassAtIfLoaded0 (Object constantPoolOop, int index);
+ private native Member getMethodAt0 (Object constantPoolOop, int index);
+ private native Member getMethodAtIfLoaded0(Object constantPoolOop, int index);
+ private native Field getFieldAt0 (Object constantPoolOop, int index);
+ private native Field getFieldAtIfLoaded0 (Object constantPoolOop, int index);
+ private native String[] getMemberRefInfoAt0 (Object constantPoolOop, int index);
+ private native int getIntAt0 (Object constantPoolOop, int index);
+ private native long getLongAt0 (Object constantPoolOop, int index);
+ private native float getFloatAt0 (Object constantPoolOop, int index);
+ private native double getDoubleAt0 (Object constantPoolOop, int index);
+ private native String getStringAt0 (Object constantPoolOop, int index);
+ private native String getUTF8At0 (Object constantPoolOop, int index);
+}
--- /dev/null
+/*
+ * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.reflect.annotation;
+
+import java.lang.annotation.*;
+import java.util.*;
+import java.nio.ByteBuffer;
+import java.nio.BufferUnderflowException;
+import java.lang.reflect.*;
+import sun.reflect.ConstantPool;
+
+import gnu.java.lang.reflect.FieldSignatureParser;
+
+
+/**
+ * Parser for Java programming language annotations. Translates
+ * annotation byte streams emitted by compiler into annotation objects.
+ *
+ * @author Josh Bloch
+ * @since 1.5
+ */
+public class AnnotationParser {
+ /**
+ * Parses the annotations described by the passed byte array,
+ * but returns Annotation[] so I don't have to do this in C.
+ *
+ * @author Mathias Panzenböck
+ *
+ * @param rawAnnotations are the unparsed annotations
+ * @param constPool is the constant pool of the declaring class
+ * @param container is the containing class
+ * @return the parsed annotations in an array
+ * @throws AnnotationFormatError if an annotation is found to be
+ * malformed.
+ */
+ public static Annotation[] parseAnnotationsIntoArray(
+ byte[] rawAnnotations,
+ ConstantPool constPool,
+ Class container) {
+ Map<Class, Annotation> annotations = parseAnnotations(rawAnnotations, constPool, container);
+ return annotations.values().toArray(EMPTY_ANNOTATIONS_ARRAY);
+ }
+
+ /**
+ * Parses parameter annotations.
+ *
+ * @author Mathias Panzenböck
+ *
+ * @param parameterAnnotations are the unparsed parameter annotations
+ * @param constPool is the constant pool of the declaring class
+ * @param container is the containing class
+ * @return the parsed parameter annotations in an array 2 dimensional array
+ * @throws AnnotationFormatError if an annotation is found to be
+ * malformed.
+ */
+ public static Annotation[][] parseParameterAnnotations(
+ byte[] parameterAnnotations,
+ ConstantPool constPool,
+ Class container,
+ int numParameters) {
+ if (parameterAnnotations == null)
+ return new Annotation[numParameters][0];
+
+ Annotation[][] result = parseParameterAnnotations(
+ parameterAnnotations, constPool, container);
+
+ if (result.length != numParameters)
+ throw new AnnotationFormatError(
+ "Parameter annotations don't match number of parameters (count was " +
+ result.length + " but should be " + numParameters + ").");
+ return result;
+ }
+
+ /**
+ * Parses the annotation default value of the supplied method.
+ * This method is basically copied from OpenJDKs
+ * java.lang.reflect.Method.getAnnotationDefault()
+ *
+ * @author Mathias Panzenböck
+ *
+ * @param method represents the method for which the annotation default value has to be parsed
+ * @param annotationDefault is the unparsed annotation default value
+ * @param constPool is the constant pool of the declaring class
+ * @return the parsed annotation default value (boxed, if it's a primitive type)
+ * @throws AnnotationFormatError if an annotation is found to be
+ * malformed.
+ */
+ public static Object parseAnnotationDefault(Method method,
+ byte[] annotationDefault,
+ ConstantPool constPool) {
+ if (annotationDefault == null)
+ return null;
+
+ Class memberType = AnnotationType.invocationHandlerReturnType(
+ method.getReturnType());
+
+ Object result = AnnotationParser.parseMemberValue(
+ memberType, ByteBuffer.wrap(annotationDefault),
+ constPool, method.getDeclaringClass());
+
+ if (result instanceof sun.reflect.annotation.ExceptionProxy)
+ throw new AnnotationFormatError("Invalid default: " + method);
+
+ return result;
+ }
+
+ /**
+ * Parses the annotations described by the specified byte array.
+ * resolving constant references in the specified constant pool.
+ * The array must contain an array of annotations as described
+ * in the RuntimeVisibleAnnotations_attribute:
+ *
+ * u2 num_annotations;
+ * annotation annotations[num_annotations];
+ *
+ * @throws AnnotationFormatError if an annotation is found to be
+ * malformed.
+ */
+ public static Map<Class, Annotation> parseAnnotations(
+ byte[] rawAnnotations,
+ ConstantPool constPool,
+ Class container) {
+ if (rawAnnotations == null)
+ return Collections.emptyMap();
+
+ try {
+ return parseAnnotations2(rawAnnotations, constPool, container);
+ } catch(BufferUnderflowException e) {
+ throw new AnnotationFormatError("Unexpected end of annotations.");
+ } catch(IllegalArgumentException e) {
+ // Type mismatch in constant pool
+ throw new AnnotationFormatError(e);
+ }
+ }
+
+ private static Map<Class, Annotation> parseAnnotations2(
+ byte[] rawAnnotations,
+ ConstantPool constPool,
+ Class container) {
+ Map<Class, Annotation> result = new LinkedHashMap<Class, Annotation>();
+ ByteBuffer buf = ByteBuffer.wrap(rawAnnotations);
+ int numAnnotations = buf.getShort() & 0xFFFF;
+ for (int i = 0; i < numAnnotations; i++) {
+ Annotation a = parseAnnotation(buf, constPool, container, false);
+ if (a != null) {
+ Class klass = a.annotationType();
+ AnnotationType type = AnnotationType.getInstance(klass);
+ if (type.retention() == RetentionPolicy.RUNTIME)
+ if (result.put(klass, a) != null)
+ throw new AnnotationFormatError(
+ "Duplicate annotation for class: "+klass+": " + a);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Parses the parameter annotations described by the specified byte array.
+ * resolving constant references in the specified constant pool.
+ * The array must contain an array of annotations as described
+ * in the RuntimeVisibleParameterAnnotations_attribute:
+ *
+ * u1 num_parameters;
+ * {
+ * u2 num_annotations;
+ * annotation annotations[num_annotations];
+ * } parameter_annotations[num_parameters];
+ *
+ * Unlike parseAnnotations, rawAnnotations must not be null!
+ * A null value must be handled by the caller. This is so because
+ * we cannot determine the number of parameters if rawAnnotations
+ * is null. Also, the caller should check that the number
+ * of parameters indicated by the return value of this method
+ * matches the actual number of method parameters. A mismatch
+ * indicates that an AnnotationFormatError should be thrown.
+ *
+ * @throws AnnotationFormatError if an annotation is found to be
+ * malformed.
+ */
+ public static Annotation[][] parseParameterAnnotations(
+ byte[] rawAnnotations,
+ ConstantPool constPool,
+ Class container) {
+ try {
+ return parseParameterAnnotations2(rawAnnotations, constPool, container);
+ } catch(BufferUnderflowException e) {
+ throw new AnnotationFormatError(
+ "Unexpected end of parameter annotations.");
+ } catch(IllegalArgumentException e) {
+ // Type mismatch in constant pool
+ throw new AnnotationFormatError(e);
+ }
+ }
+
+ private static Annotation[][] parseParameterAnnotations2(
+ byte[] rawAnnotations,
+ ConstantPool constPool,
+ Class container) {
+ ByteBuffer buf = ByteBuffer.wrap(rawAnnotations);
+ int numParameters = buf.get() & 0xFF;
+ Annotation[][] result = new Annotation[numParameters][];
+
+ for (int i = 0; i < numParameters; i++) {
+ int numAnnotations = buf.getShort() & 0xFFFF;
+ List<Annotation> annotations =
+ new ArrayList<Annotation>(numAnnotations);
+ for (int j = 0; j < numAnnotations; j++) {
+ Annotation a = parseAnnotation(buf, constPool, container, false);
+ if (a != null) {
+ AnnotationType type = AnnotationType.getInstance(
+ a.annotationType());
+ if (type.retention() == RetentionPolicy.RUNTIME)
+ annotations.add(a);
+ }
+ }
+ result[i] = annotations.toArray(EMPTY_ANNOTATIONS_ARRAY);
+ }
+ return result;
+ }
+
+ private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY =
+ new Annotation[0];
+
+ /**
+ * Parses the annotation at the current position in the specified
+ * byte buffer, resolving constant references in the specified constant
+ * pool. The cursor of the byte buffer must point to an "annotation
+ * structure" as described in the RuntimeVisibleAnnotations_attribute:
+ *
+ * annotation {
+ * u2 type_index;
+ * u2 num_member_value_pairs;
+ * { u2 member_name_index;
+ * member_value value;
+ * } member_value_pairs[num_member_value_pairs];
+ * }
+ * }
+ *
+ * Returns the annotation, or null if the annotation's type cannot
+ * be found by the VM, or is not a valid annotation type.
+ *
+ * @param exceptionOnMissingAnnotationClass if true, throw
+ * TypeNotPresentException if a referenced annotation type is not
+ * available at runtime
+ */
+ private static Annotation parseAnnotation(ByteBuffer buf,
+ ConstantPool constPool,
+ Class container,
+ boolean exceptionOnMissingAnnotationClass) {
+ int typeIndex = buf.getShort() & 0xFFFF;
+ Class annotationClass = null;
+ String sig = "[unknown]";
+ try {
+ try {
+ sig = constPool.getUTF8At(typeIndex);
+ annotationClass = parseSig(sig, container);
+ } catch (IllegalArgumentException ex) {
+ // support obsolete early jsr175 format class files
+ annotationClass = constPool.getClassAt(typeIndex);
+ }
+ } catch (NoClassDefFoundError e) {
+ if (exceptionOnMissingAnnotationClass)
+ // note: at this point sig is "[unknown]" or VM-style
+ // name instead of a binary name
+ throw new TypeNotPresentException(sig, e);
+ skipAnnotation(buf, false);
+ return null;
+ }
+ catch (TypeNotPresentException e) {
+ if (exceptionOnMissingAnnotationClass)
+ throw e;
+ skipAnnotation(buf, false);
+ return null;
+ }
+ AnnotationType type = null;
+ try {
+ type = AnnotationType.getInstance(annotationClass);
+ } catch (IllegalArgumentException e) {
+ skipAnnotation(buf, false);
+ return null;
+ }
+
+ Map<String, Class> memberTypes = type.memberTypes();
+ Map<String, Object> memberValues =
+ new LinkedHashMap<String, Object>(type.memberDefaults());
+
+ int numMembers = buf.getShort() & 0xFFFF;
+ for (int i = 0; i < numMembers; i++) {
+ int memberNameIndex = buf.getShort() & 0xFFFF;
+ String memberName = constPool.getUTF8At(memberNameIndex);
+ Class memberType = memberTypes.get(memberName);
+
+ if (memberType == null) {
+ // Member is no longer present in annotation type; ignore it
+ skipMemberValue(buf);
+ } else {
+ Object value = parseMemberValue(memberType, buf, constPool, container);
+ if (value instanceof AnnotationTypeMismatchExceptionProxy)
+ ((AnnotationTypeMismatchExceptionProxy) value).
+ setMember(type.members().get(memberName));
+ memberValues.put(memberName, value);
+ }
+ }
+ return annotationForMap(annotationClass, memberValues);
+ }
+
+ /**
+ * Returns an annotation of the given type backed by the given
+ * member -> value map.
+ */
+ public static Annotation annotationForMap(
+ Class type, Map<String, Object> memberValues)
+ {
+ return (Annotation) Proxy.newProxyInstance(
+ type.getClassLoader(), new Class[] { type },
+ new AnnotationInvocationHandler(type, memberValues));
+ }
+
+ /**
+ * Parses the annotation member value at the current position in the
+ * specified byte buffer, resolving constant references in the specified
+ * constant pool. The cursor of the byte buffer must point to a
+ * "member_value structure" as described in the
+ * RuntimeVisibleAnnotations_attribute:
+ *
+ * member_value {
+ * u1 tag;
+ * union {
+ * u2 const_value_index;
+ * {
+ * u2 type_name_index;
+ * u2 const_name_index;
+ * } enum_const_value;
+ * u2 class_info_index;
+ * annotation annotation_value;
+ * {
+ * u2 num_values;
+ * member_value values[num_values];
+ * } array_value;
+ * } value;
+ * }
+ *
+ * The member must be of the indicated type. If it is not, this
+ * method returns an AnnotationTypeMismatchExceptionProxy.
+ */
+ public static Object parseMemberValue(Class memberType, ByteBuffer buf,
+ ConstantPool constPool,
+ Class container) {
+ Object result = null;
+ int tag = buf.get();
+ switch(tag) {
+ case 'e':
+ return parseEnumValue(memberType, buf, constPool, container);
+ case 'c':
+ result = parseClassValue(buf, constPool, container);
+ break;
+ case '@':
+ result = parseAnnotation(buf, constPool, container, true);
+ break;
+ case '[':
+ return parseArray(memberType, buf, constPool, container);
+ default:
+ result = parseConst(tag, buf, constPool);
+ }
+
+ if (!(result instanceof ExceptionProxy) &&
+ !memberType.isInstance(result))
+ result = new AnnotationTypeMismatchExceptionProxy(
+ result.getClass() + "[" + result + "]");
+ return result;
+ }
+
+ /**
+ * Parses the primitive or String annotation member value indicated by
+ * the specified tag byte at the current position in the specified byte
+ * buffer, resolving constant reference in the specified constant pool.
+ * The cursor of the byte buffer must point to an annotation member value
+ * of the type indicated by the specified tag, as described in the
+ * RuntimeVisibleAnnotations_attribute:
+ *
+ * u2 const_value_index;
+ */
+ private static Object parseConst(int tag,
+ ByteBuffer buf, ConstantPool constPool) {
+ int constIndex = buf.getShort() & 0xFFFF;
+ switch(tag) {
+ case 'B':
+ return Byte.valueOf((byte) constPool.getIntAt(constIndex));
+ case 'C':
+ return Character.valueOf((char) constPool.getIntAt(constIndex));
+ case 'D':
+ return Double.valueOf(constPool.getDoubleAt(constIndex));
+ case 'F':
+ return Float.valueOf(constPool.getFloatAt(constIndex));
+ case 'I':
+ return Integer.valueOf(constPool.getIntAt(constIndex));
+ case 'J':
+ return Long.valueOf(constPool.getLongAt(constIndex));
+ case 'S':
+ return Short.valueOf((short) constPool.getIntAt(constIndex));
+ case 'Z':
+ return Boolean.valueOf(constPool.getIntAt(constIndex) != 0);
+ case 's':
+ return constPool.getUTF8At(constIndex);
+ default:
+ throw new AnnotationFormatError(
+ "Invalid member-value tag in annotation: " + tag);
+ }
+ }
+
+ /**
+ * Parses the Class member value at the current position in the
+ * specified byte buffer, resolving constant references in the specified
+ * constant pool. The cursor of the byte buffer must point to a "class
+ * info index" as described in the RuntimeVisibleAnnotations_attribute:
+ *
+ * u2 class_info_index;
+ */
+ private static Object parseClassValue(ByteBuffer buf,
+ ConstantPool constPool,
+ Class container) {
+ int classIndex = buf.getShort() & 0xFFFF;
+ try {
+ try {
+ String sig = constPool.getUTF8At(classIndex);
+ return parseSig(sig, container);
+ } catch (IllegalArgumentException ex) {
+ // support obsolete early jsr175 format class files
+ return constPool.getClassAt(classIndex);
+ }
+ } catch (NoClassDefFoundError e) {
+ return new TypeNotPresentExceptionProxy("[unknown]", e);
+ }
+ catch (TypeNotPresentException e) {
+ return new TypeNotPresentExceptionProxy(e.typeName(), e.getCause());
+ }
+ }
+
+ /**
+ * Parses a return type signature and returns the according Class object.
+ */
+ private static Class<?> parseSig(String sig, Class container) {
+ if (sig.equals("V")) {
+ return void.class;
+ }
+ else {
+ return toClass(new FieldSignatureParser(container, sig).getFieldType());
+ }
+ }
+
+ static Class<?> toClass(Type o) {
+ if (o instanceof GenericArrayType)
+ return Array.newInstance(toClass(((GenericArrayType)o).getGenericComponentType()),
+ 0)
+ .getClass();
+ return (Class<?>)o;
+ }
+
+ /**
+ * Parses the enum constant member value at the current position in the
+ * specified byte buffer, resolving constant references in the specified
+ * constant pool. The cursor of the byte buffer must point to a
+ * "enum_const_value structure" as described in the
+ * RuntimeVisibleAnnotations_attribute:
+ *
+ * {
+ * u2 type_name_index;
+ * u2 const_name_index;
+ * } enum_const_value;
+ */
+ private static Object parseEnumValue(Class enumType, ByteBuffer buf,
+ ConstantPool constPool,
+ Class container) {
+ int typeNameIndex = buf.getShort() & 0xFFFF;
+ String typeName = constPool.getUTF8At(typeNameIndex);
+ int constNameIndex = buf.getShort() & 0xFFFF;
+ String constName = constPool.getUTF8At(constNameIndex);
+
+ if (!typeName.endsWith(";")) {
+ // support now-obsolete early jsr175-format class files.
+ if (!enumType.getName().equals(typeName))
+ return new AnnotationTypeMismatchExceptionProxy(
+ typeName + "." + constName);
+ } else if (enumType != parseSig(typeName, container)) {
+ return new AnnotationTypeMismatchExceptionProxy(
+ typeName + "." + constName);
+ }
+
+ try {
+ return Enum.valueOf(enumType, constName);
+ } catch(IllegalArgumentException e) {
+ return new EnumConstantNotPresentExceptionProxy(
+ (Class<? extends Enum>)enumType, constName);
+ }
+ }
+
+ /**
+ * Parses the array value at the current position in the specified byte
+ * buffer, resolving constant references in the specified constant pool.
+ * The cursor of the byte buffer must point to an array value struct
+ * as specified in the RuntimeVisibleAnnotations_attribute:
+ *
+ * {
+ * u2 num_values;
+ * member_value values[num_values];
+ * } array_value;
+ *
+ * If the array values do not match arrayType, an
+ * AnnotationTypeMismatchExceptionProxy will be returned.
+ */
+ private static Object parseArray(Class arrayType,
+ ByteBuffer buf,
+ ConstantPool constPool,
+ Class container) {
+ int length = buf.getShort() & 0xFFFF; // Number of array components
+ Class componentType = arrayType.getComponentType();
+
+ if (componentType == byte.class) {
+ return parseByteArray(length, buf, constPool);
+ } else if (componentType == char.class) {
+ return parseCharArray(length, buf, constPool);
+ } else if (componentType == double.class) {
+ return parseDoubleArray(length, buf, constPool);
+ } else if (componentType == float.class) {
+ return parseFloatArray(length, buf, constPool);
+ } else if (componentType == int.class) {
+ return parseIntArray(length, buf, constPool);
+ } else if (componentType == long.class) {
+ return parseLongArray(length, buf, constPool);
+ } else if (componentType == short.class) {
+ return parseShortArray(length, buf, constPool);
+ } else if (componentType == boolean.class) {
+ return parseBooleanArray(length, buf, constPool);
+ } else if (componentType == String.class) {
+ return parseStringArray(length, buf, constPool);
+ } else if (componentType == Class.class) {
+ return parseClassArray(length, buf, constPool, container);
+ } else if (componentType.isEnum()) {
+ return parseEnumArray(length, componentType, buf,
+ constPool, container);
+ } else {
+ assert componentType.isAnnotation();
+ return parseAnnotationArray(length, componentType, buf,
+ constPool, container);
+ }
+ }
+
+ private static Object parseByteArray(int length,
+ ByteBuffer buf, ConstantPool constPool) {
+ byte[] result = new byte[length];
+ boolean typeMismatch = false;
+ int tag = 0;
+
+ for (int i = 0; i < length; i++) {
+ tag = buf.get();
+ if (tag == 'B') {
+ int index = buf.getShort() & 0xFFFF;
+ result[i] = (byte) constPool.getIntAt(index);
+ } else {
+ skipMemberValue(tag, buf);
+ typeMismatch = true;
+ }
+ }
+ return typeMismatch ? exceptionProxy(tag) : result;
+ }
+
+ private static Object parseCharArray(int length,
+ ByteBuffer buf, ConstantPool constPool) {
+ char[] result = new char[length];
+ boolean typeMismatch = false;
+ byte tag = 0;
+
+ for (int i = 0; i < length; i++) {
+ tag = buf.get();
+ if (tag == 'C') {
+ int index = buf.getShort() & 0xFFFF;
+ result[i] = (char) constPool.getIntAt(index);
+ } else {
+ skipMemberValue(tag, buf);
+ typeMismatch = true;
+ }
+ }
+ return typeMismatch ? exceptionProxy(tag) : result;
+ }
+
+ private static Object parseDoubleArray(int length,
+ ByteBuffer buf, ConstantPool constPool) {
+ double[] result = new double[length];
+ boolean typeMismatch = false;
+ int tag = 0;
+
+ for (int i = 0; i < length; i++) {
+ tag = buf.get();
+ if (tag == 'D') {
+ int index = buf.getShort() & 0xFFFF;
+ result[i] = constPool.getDoubleAt(index);
+ } else {
+ skipMemberValue(tag, buf);
+ typeMismatch = true;
+ }
+ }
+ return typeMismatch ? exceptionProxy(tag) : result;
+ }
+
+ private static Object parseFloatArray(int length,
+ ByteBuffer buf, ConstantPool constPool) {
+ float[] result = new float[length];
+ boolean typeMismatch = false;
+ int tag = 0;
+
+ for (int i = 0; i < length; i++) {
+ tag = buf.get();
+ if (tag == 'F') {
+ int index = buf.getShort() & 0xFFFF;
+ result[i] = constPool.getFloatAt(index);
+ } else {
+ skipMemberValue(tag, buf);
+ typeMismatch = true;
+ }
+ }
+ return typeMismatch ? exceptionProxy(tag) : result;
+ }
+
+ private static Object parseIntArray(int length,
+ ByteBuffer buf, ConstantPool constPool) {
+ int[] result = new int[length];
+ boolean typeMismatch = false;
+ int tag = 0;
+
+ for (int i = 0; i < length; i++) {
+ tag = buf.get();
+ if (tag == 'I') {
+ int index = buf.getShort() & 0xFFFF;
+ result[i] = constPool.getIntAt(index);
+ } else {
+ skipMemberValue(tag, buf);
+ typeMismatch = true;
+ }
+ }
+ return typeMismatch ? exceptionProxy(tag) : result;
+ }
+
+ private static Object parseLongArray(int length,
+ ByteBuffer buf, ConstantPool constPool) {
+ long[] result = new long[length];
+ boolean typeMismatch = false;
+ int tag = 0;
+
+ for (int i = 0; i < length; i++) {
+ tag = buf.get();
+ if (tag == 'J') {
+ int index = buf.getShort() & 0xFFFF;
+ result[i] = constPool.getLongAt(index);
+ } else {
+ skipMemberValue(tag, buf);
+ typeMismatch = true;
+ }
+ }
+ return typeMismatch ? exceptionProxy(tag) : result;
+ }
+
+ private static Object parseShortArray(int length,
+ ByteBuffer buf, ConstantPool constPool) {
+ short[] result = new short[length];
+ boolean typeMismatch = false;
+ int tag = 0;
+
+ for (int i = 0; i < length; i++) {
+ tag = buf.get();
+ if (tag == 'S') {
+ int index = buf.getShort() & 0xFFFF;
+ result[i] = (short) constPool.getIntAt(index);
+ } else {
+ skipMemberValue(tag, buf);
+ typeMismatch = true;
+ }
+ }
+ return typeMismatch ? exceptionProxy(tag) : result;
+ }
+
+ private static Object parseBooleanArray(int length,
+ ByteBuffer buf, ConstantPool constPool) {
+ boolean[] result = new boolean[length];
+ boolean typeMismatch = false;
+ int tag = 0;
+
+ for (int i = 0; i < length; i++) {
+ tag = buf.get();
+ if (tag == 'Z') {
+ int index = buf.getShort() & 0xFFFF;
+ result[i] = (constPool.getIntAt(index) != 0);
+ } else {
+ skipMemberValue(tag, buf);
+ typeMismatch = true;
+ }
+ }
+ return typeMismatch ? exceptionProxy(tag) : result;
+ }
+
+ private static Object parseStringArray(int length,
+ ByteBuffer buf, ConstantPool constPool) {
+ String[] result = new String[length];
+ boolean typeMismatch = false;
+ int tag = 0;
+
+ for (int i = 0; i < length; i++) {
+ tag = buf.get();
+ if (tag == 's') {
+ int index = buf.getShort() & 0xFFFF;
+ result[i] = constPool.getUTF8At(index);
+ } else {
+ skipMemberValue(tag, buf);
+ typeMismatch = true;
+ }
+ }
+ return typeMismatch ? exceptionProxy(tag) : result;
+ }
+
+ private static Object parseClassArray(int length,
+ ByteBuffer buf,
+ ConstantPool constPool,
+ Class container) {
+ Object[] result = new Class[length];
+ boolean typeMismatch = false;
+ int tag = 0;
+
+ for (int i = 0; i < length; i++) {
+ tag = buf.get();
+ if (tag == 'c') {
+ result[i] = parseClassValue(buf, constPool, container);
+ } else {
+ skipMemberValue(tag, buf);
+ typeMismatch = true;
+ }
+ }
+ return typeMismatch ? exceptionProxy(tag) : result;
+ }
+
+ private static Object parseEnumArray(int length, Class enumType,
+ ByteBuffer buf,
+ ConstantPool constPool,
+ Class container) {
+ Object[] result = (Object[]) Array.newInstance(enumType, length);
+ boolean typeMismatch = false;
+ int tag = 0;
+
+ for (int i = 0; i < length; i++) {
+ tag = buf.get();
+ if (tag == 'e') {
+ result[i] = parseEnumValue(enumType, buf, constPool, container);
+ } else {
+ skipMemberValue(tag, buf);
+ typeMismatch = true;
+ }
+ }
+ return typeMismatch ? exceptionProxy(tag) : result;
+ }
+
+ private static Object parseAnnotationArray(int length,
+ Class annotationType,
+ ByteBuffer buf,
+ ConstantPool constPool,
+ Class container) {
+ Object[] result = (Object[]) Array.newInstance(annotationType, length);
+ boolean typeMismatch = false;
+ int tag = 0;
+
+ for (int i = 0; i < length; i++) {
+ tag = buf.get();
+ if (tag == '@') {
+ result[i] = parseAnnotation(buf, constPool, container, true);
+ } else {
+ skipMemberValue(tag, buf);
+ typeMismatch = true;
+ }
+ }
+ return typeMismatch ? exceptionProxy(tag) : result;
+ }
+
+ /**
+ * Return an appropriate exception proxy for a mismatching array
+ * annotation where the erroneous array has the specified tag.
+ */
+ private static ExceptionProxy exceptionProxy(int tag) {
+ return new AnnotationTypeMismatchExceptionProxy(
+ "Array with component tag: " + tag);
+ }
+
+ /**
+ * Skips the annotation at the current position in the specified
+ * byte buffer. The cursor of the byte buffer must point to
+ * an "annotation structure" OR two bytes into an annotation
+ * structure (i.e., after the type index).
+ *
+ * @parameter complete true if the byte buffer points to the beginning
+ * of an annotation structure (rather than two bytes in).
+ */
+ private static void skipAnnotation(ByteBuffer buf, boolean complete) {
+ if (complete)
+ buf.getShort(); // Skip type index
+ int numMembers = buf.getShort() & 0xFFFF;
+ for (int i = 0; i < numMembers; i++) {
+ buf.getShort(); // Skip memberNameIndex
+ skipMemberValue(buf);
+ }
+ }
+
+ /**
+ * Skips the annotation member value at the current position in the
+ * specified byte buffer. The cursor of the byte buffer must point to a
+ * "member_value structure."
+ */
+ private static void skipMemberValue(ByteBuffer buf) {
+ int tag = buf.get();
+ skipMemberValue(tag, buf);
+ }
+
+ /**
+ * Skips the annotation member value at the current position in the
+ * specified byte buffer. The cursor of the byte buffer must point
+ * immediately after the tag in a "member_value structure."
+ */
+ private static void skipMemberValue(int tag, ByteBuffer buf) {
+ switch(tag) {
+ case 'e': // Enum value
+ buf.getInt(); // (Two shorts, actually.)
+ break;
+ case '@':
+ skipAnnotation(buf, true);
+ break;
+ case '[':
+ skipArray(buf);
+ break;
+ default:
+ // Class, primitive, or String
+ buf.getShort();
+ }
+ }
+
+ /**
+ * Skips the array value at the current position in the specified byte
+ * buffer. The cursor of the byte buffer must point to an array value
+ * struct.
+ */
+ private static void skipArray(ByteBuffer buf) {
+ int length = buf.getShort() & 0xFFFF;
+ for (int i = 0; i < length; i++)
+ skipMemberValue(buf);
+ }
+}
--- /dev/null
+/*
+ * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.reflect.annotation;
+
+import java.lang.annotation.*;
+import java.lang.reflect.*;
+import java.util.*;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Represents an annotation type at run time. Used to type-check annotations
+ * and apply member defaults.
+ *
+ * @author Josh Bloch
+ * @since 1.5
+ */
+public class AnnotationType {
+ /**
+ * Annotation class -> AnnotationType mapping. This emulates
+ * sun.misc.SharedSecrets.getJavaLangAccess().getAnnotationType() and
+ * sun.misc.SharedSecrets.getJavaLangAccess().setAnnotationType() so
+ * this class can be used with gnu classpath.
+ *
+ * @author Mathias Panzenböck
+ */
+ private static Map<Class, AnnotationType> annotationTypes =
+ new HashMap<Class, AnnotationType>();
+
+ /**
+ * Member name -> type mapping. Note that primitive types
+ * are represented by the class objects for the corresponding wrapper
+ * types. This matches the return value that must be used for a
+ * dynamic proxy, allowing for a simple isInstance test.
+ */
+ private final Map<String, Class> memberTypes = new HashMap<String,Class>();
+
+ /**
+ * Member name -> default value mapping.
+ */
+ private final Map<String, Object> memberDefaults =
+ new HashMap<String, Object>();
+
+ /**
+ * Member name -> Method object mapping. This (and its assoicated
+ * accessor) are used only to generate AnnotationTypeMismatchExceptions.
+ */
+ private final Map<String, Method> members = new HashMap<String, Method>();
+
+ /**
+ * The retention policy for this annotation type.
+ */
+ private RetentionPolicy retention = RetentionPolicy.RUNTIME;;
+
+ /**
+ * Whether this annotation type is inherited.
+ */
+ private boolean inherited = false;
+
+ /**
+ * Returns an AnnotationType instance for the specified annotation type.
+ *
+ * @throw IllegalArgumentException if the specified class object for
+ * does not represent a valid annotation type
+ */
+ public static synchronized AnnotationType getInstance(
+ Class annotationClass)
+ {
+ /*
+ AnnotationType result = sun.misc.SharedSecrets.getJavaLangAccess().
+ getAnnotationType(annotationClass);
+ */
+ // emulating OpenJDKs SharedSecrets in GNU Classpath:
+ AnnotationType result = annotationTypes.get(annotationClass);
+ if (result == null)
+ result = new AnnotationType((Class<?>) annotationClass);
+
+ return result;
+ }
+
+ /**
+ * Sole constructor.
+ *
+ * @param annotationClass the class object for the annotation type
+ * @throw IllegalArgumentException if the specified class object for
+ * does not represent a valid annotation type
+ */
+ private AnnotationType(final Class<?> annotationClass) {
+ if (!annotationClass.isAnnotation())
+ throw new IllegalArgumentException("Not an annotation type");
+
+ Method[] methods =
+ AccessController.doPrivileged(new PrivilegedAction<Method[]>() {
+ public Method[] run() {
+ // Initialize memberTypes and defaultValues
+ return annotationClass.getDeclaredMethods();
+ }
+ });
+
+
+ for (Method method : methods) {
+ if (method.getParameterTypes().length != 0)
+ throw new IllegalArgumentException(method + " has params");
+ String name = method.getName();
+ Class type = method.getReturnType();
+ memberTypes.put(name, invocationHandlerReturnType(type));
+ members.put(name, method);
+
+ Object defaultValue = method.getDefaultValue();
+ if (defaultValue != null)
+ memberDefaults.put(name, defaultValue);
+
+ members.put(name, method);
+ }
+
+ /*
+ sun.misc.SharedSecrets.getJavaLangAccess().
+ setAnnotationType(annotationClass, this);
+ */
+ // emulating OpenJDKs SharedSecrets in GNU Classpath:
+ annotationTypes.put(annotationClass, this);
+
+ // Initialize retention, & inherited fields. Special treatment
+ // of the corresponding annotation types breaks infinite recursion.
+ if (annotationClass != Retention.class &&
+ annotationClass != Inherited.class) {
+ Retention ret = annotationClass.getAnnotation(Retention.class);
+ retention = (ret == null ? RetentionPolicy.CLASS : ret.value());
+ inherited = annotationClass.isAnnotationPresent(Inherited.class);
+ }
+ }
+
+ /**
+ * Returns the type that must be returned by the invocation handler
+ * of a dynamic proxy in order to have the dynamic proxy return
+ * the specified type (which is assumed to be a legal member type
+ * for an annotation).
+ */
+ public static Class invocationHandlerReturnType(Class type) {
+ // Translate primitives to wrappers
+ if (type == byte.class)
+ return Byte.class;
+ if (type == char.class)
+ return Character.class;
+ if (type == double.class)
+ return Double.class;
+ if (type == float.class)
+ return Float.class;
+ if (type == int.class)
+ return Integer.class;
+ if (type == long.class)
+ return Long.class;
+ if (type == short.class)
+ return Short.class;
+ if (type == boolean.class)
+ return Boolean.class;
+
+ // Otherwise, just return declared type
+ return type;
+ }
+
+ /**
+ * Returns member types for this annotation type
+ * (member name -> type mapping).
+ */
+ public Map<String, Class> memberTypes() {
+ return memberTypes;
+ }
+
+ /**
+ * Returns members of this annotation type
+ * (member name -> associated Method object mapping).
+ */
+ public Map<String, Method> members() {
+ return members;
+ }
+
+ /**
+ * Returns the default values for this annotation type
+ * (Member name -> default value mapping).
+ */
+ public Map<String, Object> memberDefaults() {
+ return memberDefaults;
+ }
+
+ /**
+ * Returns the retention policy for this annotation type.
+ */
+ public RetentionPolicy retention() {
+ return retention;
+ }
+
+ /**
+ * Returns true if this this annotation type is inherited.
+ */
+ public boolean isInherited() {
+ return inherited;
+ }
+
+ /**
+ * For debugging.
+ */
+ public String toString() {
+ StringBuffer s = new StringBuffer("Annotation Type:" + "\n");
+ s.append(" Member types: " + memberTypes + "\n");
+ s.append(" Member defaults: " + memberDefaults + "\n");
+ s.append(" Retention policy: " + retention + "\n");
+ s.append(" Inherited: " + inherited);
+ return s.toString();
+ }
+}
--- /dev/null
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.reflect.annotation;
+import java.lang.annotation.*;
+import java.lang.reflect.Method;
+
+/**
+ * ExceptionProxy for AnnotationTypeMismatchException.
+ *
+ * @author Josh Bloch
+ * @since 1.5
+ */
+class AnnotationTypeMismatchExceptionProxy extends ExceptionProxy {
+ private Method member;
+ private String foundType;
+
+ /**
+ * It turns out to be convenient to construct these proxies in
+ * two stages. Since this is a private implementation class, we
+ * permit ourselves this liberty even though it's normally a very
+ * bad idea.
+ */
+ AnnotationTypeMismatchExceptionProxy(String foundType) {
+ this.foundType = foundType;
+ }
+
+ AnnotationTypeMismatchExceptionProxy setMember(Method member) {
+ this.member = member;
+ return this;
+ }
+
+ protected RuntimeException generateException() {
+ return new AnnotationTypeMismatchException(member, foundType);
+ }
+}
--- /dev/null
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.reflect.annotation;
+import java.lang.annotation.*;
+
+/**
+ * ExceptionProxy for EnumConstantNotPresentException.
+ *
+ * @author Josh Bloch
+ * @since 1.5
+ */
+public class EnumConstantNotPresentExceptionProxy extends ExceptionProxy {
+ Class<? extends Enum> enumType;
+ String constName;
+
+ public EnumConstantNotPresentExceptionProxy(Class<? extends Enum> enumType,
+ String constName) {
+ this.enumType = enumType;
+ this.constName = constName;
+ }
+
+ protected RuntimeException generateException() {
+ return new EnumConstantNotPresentException(enumType, constName);
+ }
+}
--- /dev/null
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.reflect.annotation;
+
+/**
+ * An instance of this class is stored in an AnnotationInvocationHandler's
+ * "memberValues" map in lieu of a value for an annotation member that
+ * cannot be returned due to some exceptional condition (typically some
+ * form of illegal evolution of the annotation class). The ExceptionProxy
+ * instance describes the exception that the dynamic proxy should throw if
+ * it is queried for this member.
+ *
+ * @author Josh Bloch
+ * @since 1.5
+ */
+public abstract class ExceptionProxy implements java.io.Serializable {
+ protected abstract RuntimeException generateException();
+}
--- /dev/null
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.reflect.annotation;
+import java.lang.annotation.*;
+
+/**
+ * ExceptionProxy for TypeNotPresentException.
+ *
+ * @author Josh Bloch
+ * @since 1.5
+ */
+public class TypeNotPresentExceptionProxy extends ExceptionProxy {
+ String typeName;
+ Throwable cause;
+
+ public TypeNotPresentExceptionProxy(String typeName, Throwable cause) {
+ this.typeName = typeName;
+ this.cause = cause;
+ }
+
+ protected RuntimeException generateException() {
+ return new TypeNotPresentException(typeName, cause);
+ }
+}
+++ /dev/null
-## src/lib/Makefile.am
-##
-## Copyright (C) 1996-2005, 2006, 2007, 2008
-## CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
-##
-## This file is part of CACAO.
-##
-## This program is free software; you can redistribute it and/or
-## modify it under the terms of the GNU General Public License as
-## published by the Free Software Foundation; either version 2, or (at
-## your option) any later version.
-##
-## This program is distributed in the hope that it will be useful, but
-## WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-## General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## along with this program; if not, write to the Free Software
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-## 02110-1301, USA.
-
-
-EXTRA_DIST = \
- $(VM_JAVA_FILES_GNU) \
- $(VM_JAVA_FILES_GNU_ANNOTATIONS) \
- $(VM_JAVA_FILES_CLDC1_1)
-
-CLEANFILES = vm.zip
-
-VM_JAVA_FILES_GNU = \
- $(top_srcdir)/src/lib/gnu/gnu/classpath/VMStackWalker.java \
- $(top_srcdir)/src/lib/gnu/gnu/classpath/VMSystemProperties.java \
- $(top_srcdir)/src/lib/gnu/gnu/java/lang/management/VMMemoryMXBeanImpl.java \
- $(top_srcdir)/src/lib/gnu/gnu/java/lang/management/VMRuntimeMXBeanImpl.java \
- $(top_srcdir)/src/lib/gnu/java/lang/VMClassLoader.java \
- $(top_srcdir)/src/lib/gnu/java/lang/VMString.java \
- $(top_srcdir)/src/lib/gnu/java/lang/VMThread.java \
- $(top_srcdir)/src/lib/gnu/java/lang/reflect/Constructor.java \
- $(top_srcdir)/src/lib/gnu/java/lang/reflect/Field.java \
- $(top_srcdir)/src/lib/gnu/java/lang/reflect/Method.java \
- $(top_srcdir)/src/lib/gnu/java/security/VMAccessController.java \
- $(top_srcdir)/src/lib/gnu/sun/misc/Unsafe.java
-
-VM_JAVA_FILES_GNU_ANNOTATIONS = \
- $(top_srcdir)/src/lib/gnu/sun/reflect/ConstantPool.java \
- $(top_srcdir)/src/lib/gnu/sun/reflect/annotation/ExceptionProxy.java \
- $(top_srcdir)/src/lib/gnu/sun/reflect/annotation/EnumConstantNotPresentExceptionProxy.java \
- $(top_srcdir)/src/lib/gnu/sun/reflect/annotation/TypeNotPresentExceptionProxy.java \
- $(top_srcdir)/src/lib/gnu/sun/reflect/annotation/AnnotationTypeMismatchExceptionProxy.java \
- $(top_srcdir)/src/lib/gnu/sun/reflect/annotation/AnnotationType.java \
- $(top_srcdir)/src/lib/gnu/sun/reflect/annotation/AnnotationParser.java
-
-VM_JAVA_FILES_CLDC1_1 = \
- $(top_srcdir)/src/lib/cldc1.1/com/sun/cldchi/jvm/FileDescriptor.java
-
-BOOTCLASSPATH = $(top_builddir)/src/lib/classes:$(CLASSPATH_CLASSES)
-
-if WITH_CLASSPATH_GNU
-VM_JAVA_FILES = \
- $(VM_JAVA_FILES_GNU)
-
-if ENABLE_ANNOTATIONS
-VM_JAVA_FILES += \
- $(VM_JAVA_FILES_GNU_ANNOTATIONS)
-endif
-
-if ENABLE_ZLIB
-pkgdata_DATA = vm.zip
-else
-pkgdata_DATA = nozip
-endif
-endif
-
-if WITH_CLASSPATH_CLDC1_1
-VM_JAVA_FILES = \
- $(VM_JAVA_FILES_CLDC1_1)
-
-if ENABLE_ZLIB
-pkgdata_DATA = vm.zip
-else
-pkgdata_DATA = nozip
-endif
-endif
-
-if ENABLE_ZLIB
-VM_ZIP = ../vm.zip
-
-vm.zip: $(VM_JAVA_FILES)
- $(mkdir_p) classes
- $(JAVAC) -bootclasspath $(BOOTCLASSPATH) -source 1.5 -target 1.5 -d classes $(VM_JAVA_FILES)
- @if test "$(JAR)" = "zip" -o "$(JAR)" = "zip.exe"; then \
- cd classes && $(JAR) -r -D $(VM_ZIP) .; \
- else \
- cd classes && $(JAR) cvf $(VM_ZIP) .; \
- fi
-else
-nozip: $(VM_JAVA_FILES)
- $(mkdir_p) classes
- $(JAVAC) -bootclasspath $(BOOTCLASSPATH) -source 1.5 -target 1.5 -d classes $(VM_JAVA_FILES)
-endif
-
-clean-local:
- -rm -rf classes
-
-
-## Local variables:
-## mode: Makefile
-## indent-tabs-mode: t
-## c-basic-offset: 4
-## tab-width: 8
-## compile-command: "automake --add-missing"
-## End:
+++ /dev/null
-/* src/lib/com/sun/cldchi/jvm/FileDescriptor.java
-
- Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel, C. Oates,
- R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
- C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
- Institut f. Computersprachen - TU Wien
-
- This file is part of CACAO.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
-*/
-
-package com.sun.cldchi.jvm;
-
-class FileDescriptor {
- long pointer;
- int position;
- int length;
-}
+++ /dev/null
-/* VMStackWalker.java -- Reference implementation of VM hooks for stack access
- Copyright (C) 2005 Free Software Foundation
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-package gnu.classpath;
-
-/**
- * This class provides access to the classes on the Java stack
- * for reflection and security purposes.
- *
- * <p>
- * This class is only available to privileged code (i.e., code loaded
- * by the bootstrap loader).
- *
- * @author John Keiser
- * @author Eric Blake <ebb9@email.byu.edu>
- * @author Archie Cobbs
- */
-public final class VMStackWalker
-{
- /**
- * Get a list of all the classes currently executing methods on the
- * Java stack. <code>getClassContext()[0]</code> is the class associated
- * with the currently executing method, i.e., the method that called
- * <code>VMStackWalker.getClassContext()</code> (possibly through
- * reflection). So you may need to pop off these stack frames from
- * the top of the stack:
- * <ul>
- * <li><code>VMStackWalker.getClassContext()</code>
- * <li><code>Method.invoke()</code>
- * </ul>
- *
- * @return an array of the declaring classes of each stack frame
- */
- public static native Class[] getClassContext();
-
- /**
- * Get the class associated with the method invoking the method
- * invoking this method, or <code>null</code> if the stack is not
- * that deep (e.g., invoked via JNI invocation API). This method
- * is an optimization for the expression <code>getClassContext()[1]</code>
- * and should return the same result.
- *
- * <p>
- * VM implementers are encouraged to provide a more efficient
- * version of this method.
- */
-// public static Class getCallingClass()
-// {
-// Class[] ctx = getClassContext();
-// if (ctx.length < 3)
-// return null;
-// return ctx[2];
-// }
- public static native Class getCallingClass();
-
- /**
- * Get the class loader associated with the Class returned by
- * <code>getCallingClass()</code>, or <code>null</code> if no such class
- * exists or it is the boot loader. This method is an optimization for the
- * expression <code>VMStackWalker.getClassLoader(getClassContext()[1])</code>
- * and should return the same result.
- *
- * <p>
- * VM implementers are encouraged to provide a more efficient
- * version of this method.
- */
-// public static ClassLoader getCallingClassLoader()
-// {
-// Class[] ctx = getClassContext();
-// if (ctx.length < 3)
-// return null;
-// return getClassLoader(ctx[2]);
-// }
- public static native ClassLoader getCallingClassLoader();
-
-
- /**
- * Retrieve the class's ClassLoader, or <code>null</code> if loaded
- * by the bootstrap loader. I.e., this should return the same thing
- * as {@link java.lang.VMClass#getClassLoader}. This duplicate version
- * is here to work around access permissions.
- */
-// public static native ClassLoader getClassLoader(Class cl);
-
- /**
- * Walk up the stack and return the first non-null class loader.
- * If there aren't any non-null class loaders on the stack, return null.
- */
-// public static ClassLoader firstNonNullClassLoader()
-// {
-// Class[] stack = getClassContext();
-// for (int i = 0; i < stack.length; i++)
-// {
-// ClassLoader loader = getClassLoader(stack[i]);
-// if (loader != null)
-// return loader;
-// }
-// return null;
-// }
- public static native ClassLoader firstNonNullClassLoader();
-}
+++ /dev/null
-/* VMSystemProperties.java -- Allow the VM to set System properties.
- Copyright (C) 2004 Free Software Foundation
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-package gnu.classpath;
-
-import java.util.Properties;
-
-class VMSystemProperties
-{
- /**
- * Get the system properties. This is done here, instead of in System,
- * because of the bootstrap sequence. Note that the native code should
- * not try to use the Java I/O classes yet, as they rely on the properties
- * already existing. The only safe method to use to insert these default
- * system properties is {@link Properties#setProperty(String, String)}.
- *
- * <p>These properties MUST include:
- * <dl>
- * <dt>java.version <dd>Java version number
- * <dt>java.vendor <dd>Java vendor specific string
- * <dt>java.vendor.url <dd>Java vendor URL
- * <dt>java.home <dd>Java installation directory
- * <dt>java.vm.specification.version <dd>VM Spec version
- * <dt>java.vm.specification.vendor <dd>VM Spec vendor
- * <dt>java.vm.specification.name <dd>VM Spec name
- * <dt>java.vm.version <dd>VM implementation version
- * <dt>java.vm.vendor <dd>VM implementation vendor
- * <dt>java.vm.name <dd>VM implementation name
- * <dt>java.specification.version <dd>Java Runtime Environment version
- * <dt>java.specification.vendor <dd>Java Runtime Environment vendor
- * <dt>java.specification.name <dd>Java Runtime Environment name
- * <dt>java.class.version <dd>Java class version number
- * <dt>java.class.path <dd>Java classpath
- * <dt>java.library.path <dd>Path for finding Java libraries
- * <dt>java.io.tmpdir <dd>Default temp file path
- * <dt>java.compiler <dd>Name of JIT to use
- * <dt>java.ext.dirs <dd>Java extension path
- * <dt>os.name <dd>Operating System Name
- * <dt>os.arch <dd>Operating System Architecture
- * <dt>os.version <dd>Operating System Version
- * <dt>file.separator <dd>File separator ("/" on Unix)
- * <dt>path.separator <dd>Path separator (":" on Unix)
- * <dt>line.separator <dd>Line separator ("\n" on Unix)
- * <dt>user.name <dd>User account name
- * <dt>user.home <dd>User home directory
- * <dt>user.dir <dd>User's current working directory
- * <dt>gnu.cpu.endian <dd>"big" or "little"
- * </dl>
- *
- * @param properties the Properties object to insert the system properties into
- */
- static native void preInit(Properties properties);
-
- /**
- * Here you get a chance to overwrite some of the properties set by
- * the common SystemProperties code. For example, it might be
- * a good idea to process the properties specified on the command
- * line here.
- */
-// static void postInit(Properties properties)
-// {
-// }
- static native void postInit(Properties properties);
-}
+++ /dev/null
-/* VMMemoryMXBeanImpl.java - VM impl. of a memory bean
- Copyright (C) 2006 Free Software Foundation
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-package gnu.java.lang.management;
-
-import java.lang.management.MemoryUsage;
-
-/**
- * Provides access to information about the memory
- * management of the current invocation of the virtual
- * machine. Instances of this bean are obtained by calling
- * {@link ManagementFactory#getMemoryMXBean()}.
- *
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @since 1.5
- */
-final class VMMemoryMXBeanImpl
-{
-
- /**
- * Returns an instance of {@link java.lang.management.MemoryUsage}
- * with appropriate initial, used, committed and maximum values
- * for the heap. By default, this uses the methods of
- * {@link java.lang.Runtime} to provide some of the values.
- *
- * @return an {@link java.lang.management.MemoryUsage} instance
- * for the heap.
- */
-// static MemoryUsage getHeapMemoryUsage()
-// {
-// Runtime runtime = Runtime.getRuntime();
-// long totalMem = runtime.totalMemory();
-// return new MemoryUsage(-1, totalMem - runtime.freeMemory(),
-// totalMem, runtime.maxMemory());
-// }
- static native MemoryUsage getHeapMemoryUsage();
-
- /**
- * Returns an instance of {@link java.lang.management.MemoryUsage}
- * with appropriate initial, used, committed and maximum values
- * for non-heap memory.
- *
- * @return an {@link java.lang.management.MemoryUsage} instance
- * for non-heap memory.
- */
- static native MemoryUsage getNonHeapMemoryUsage();
-
- /**
- * Returns the number of objects ready to be garbage collected.
- *
- * @return the number of finalizable objects.
- */
- static native int getObjectPendingFinalizationCount();
-
- /**
- * Returns true if the virtual machine will emit additional
- * information when memory is allocated and deallocated. The
- * format of the output is left up to the virtual machine.
- *
- * @return true if verbose class loading output is on.
- */
- static native boolean isVerbose();
-
- /**
- * Turns on or off the emission of additional information
- * when memory is allocated and deallocated. The format of the
- * output is left up to the virtual machine. This method
- * may be called by multiple threads concurrently, but there
- * is only one global setting of verbosity that is affected.
- *
- * @param verbose the new setting for verbose class loading
- * output.
- */
- static native void setVerbose(boolean verbose);
-
-}
+++ /dev/null
-/* VMRuntimeMXBeanImpl.java - VM implementation of an runtime bean
- Copyright (C) 2006 Free Software Foundation
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-package gnu.java.lang.management;
-
-import gnu.classpath.SystemProperties;
-
-/**
- * Provides access to information about the virtual machine.
- *
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @since 1.5
- */
-final class VMRuntimeMXBeanImpl
-{
-
- /**
- * Returns the command-line arguments supplied
- * to the virtual machine, excluding those supplied
- * to <code>main()</code>.
- *
- * @return the command-line arguments.
- */
- static native String[] getInputArguments();
-
- /**
- * Returns a developer-chosen name for the virtual
- * machine, which may differ over different running
- * instances of the same virtual machine binary.
- * For example, this may include the particular
- * process identifier used by this instance or
- * the host name of the machine on which it is
- * running. The intention is that this name refers
- * to the precise entity that the other data supplied
- * by the bean refers to, rather than the VM in general.
- *
- * @return the custom name of the VM.
- */
- static String getName()
- {
- return SystemProperties.getProperty("java.vm.name") + " " +
- SystemProperties.getProperty("java.vm.version");
- }
-
- /**
- * The time in milliseconds at which the virtual
- * machine was started. This method is only executed
- * once (for efficency), as the value is not expected
- * to change.
- *
- * @return the VM start time.
- */
- static native long getStartTime();
-
-}
+++ /dev/null
-/* VMClassLoader.java -- Reference implementation of native interface
- required by ClassLoader
- Copyright (C) 1998, 2001, 2002, 2004, 2005, 2006 Free Software Foundation
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.lang;
-
-import gnu.classpath.Configuration;
-import gnu.classpath.SystemProperties;
-import gnu.java.lang.InstrumentationImpl;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.lang.instrument.Instrumentation;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.security.ProtectionDomain;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.Vector;
-import java.util.zip.ZipFile;
-import java.util.Collections;
-import java.lang.Boolean;
-
-/**
- * java.lang.VMClassLoader is a package-private helper for VMs to implement
- * on behalf of java.lang.ClassLoader.
- *
- * @author John Keiser
- * @author Mark Wielaard (mark@klomp.org)
- * @author Eric Blake (ebb9@email.byu.edu)
- */
-final class VMClassLoader
-{
-
-
- /** packages loaded by the bootstrap class loader */
- static final HashMap definedPackages = new HashMap();
-
- /** jars from property java.boot.class.path */
- static final HashMap bootjars = new HashMap();
-
-
- /**
- * Converts the array string of native package names to
- * Packages. The packages are then put into the
- * definedPackages hashMap
- */
- static
- {
- String[] packages = getBootPackages();
-
- if( packages != null)
- {
- String specName =
- SystemProperties.getProperty("java.specification.name");
- String vendor =
- SystemProperties.getProperty("java.specification.vendor");
- String version =
- SystemProperties.getProperty("java.specification.version");
-
- Package p;
-
- for(int i = 0; i < packages.length; i++)
- {
- p = new Package(packages[i],
- specName,
- vendor,
- version,
- "GNU Classpath",
- "GNU",
- Configuration.CLASSPATH_VERSION,
- null,
- null);
-
- definedPackages.put(packages[i], p);
- }
- }
- }
-
-
- /**
- * Helper to define a class using a string of bytes. This assumes that
- * the security checks have already been performed, if necessary.
- *
- * Implementations of this method are advised to consider the
- * situation where user code modifies the byte array after it has
- * been passed to defineClass. This can be handled by making a
- * private copy of the array, or arranging to only read any given
- * byte a single time.
- *
- * @param name the name to give the class, or null if unknown
- * @param data the data representing the classfile, in classfile format
- * @param offset the offset into the data where the classfile starts
- * @param len the length of the classfile data in the array
- * @param pd the protection domain
- * @return the class that was defined
- * @throws ClassFormatError if data is not in proper classfile format
- */
- static final native Class defineClass(ClassLoader cl, String name,
- byte[] data, int offset, int len,
- ProtectionDomain pd)
- throws ClassFormatError;
-
- /**
- * Helper to resolve all references to other classes from this class.
- *
- * @param c the class to resolve
- */
- static final native void resolveClass(Class c);
-
- /**
- * Helper to load a class from the bootstrap class loader.
- *
- * @param name the class name to load
- * @param resolve whether to resolve it
- * @return the class, loaded by the bootstrap classloader or null
- * if the class wasn't found. Returning null is equivalent to throwing
- * a ClassNotFoundException (but a possible performance optimization).
- */
- static final native Class loadClass(String name, boolean resolve)
- throws ClassNotFoundException;
-
- /**
- * Helper to load a resource from the bootstrap class loader.
- *
- * @param name the resource to find
- * @return the URL to the resource
- */
- static URL getResource(String name)
- {
- Enumeration e = getResources(name);
- if (e.hasMoreElements())
- return (URL)e.nextElement();
- return null;
- }
- /**
- * Helper to get a list of resources from the bootstrap class loader.
- *
- * @param name the resource to find
- * @return an enumeration of resources
- */
- static Enumeration getResources(String name)
- {
-// StringTokenizer st = new StringTokenizer(
-// SystemProperties.getProperty("java.boot.class.path", "."),
-// File.pathSeparator);
-// Vector v = new Vector();
-// while (st.hasMoreTokens())
-// {
-// File file = new File(st.nextToken());
-// if (file.isDirectory())
-// {
-// try
-// {
-// File f = new File(file, name);
-// if (!f.exists()) continue;
-// v.add(new URL("file://" + f.getAbsolutePath()));
-// }
-// catch (MalformedURLException e)
-// {
-// throw new Error(e);
-// }
-// }
-// else if (file.isFile())
-// {
-// ZipFile zip;
-// synchronized(bootjars)
-// {
-// zip = (ZipFile) bootjars.get(file.getName());
-// }
-// if(zip == null)
-// {
-// try
-// {
-// zip = new ZipFile(file);
-// synchronized(bootjars)
-// {
-// bootjars.put(file.getName(), zip);
-// }
-// }
-// catch (IOException e)
-// {
-// continue;
-// }
-// }
-// String zname = name.startsWith("/") ? name.substring(1) : name;
-// if (zip.getEntry(zname) == null)
-// continue;
-// try
-// {
-// v.add(new URL("jar:file://"
-// + file.getAbsolutePath() + "!/" + zname));
-// }
-// catch (MalformedURLException e)
-// {
-// throw new Error(e);
-// }
-// }
-// }
-// return v.elements();
-// }
- Vector urls = nativeGetResources(name);
- Vector v = new Vector();
- for (Enumeration en = urls.elements(); en.hasMoreElements();)
- {
- try
- {
- v.add(new URL((String) en.nextElement()));
- }
- catch (MalformedURLException e)
- {
- throw new Error(e);
- }
- }
- return v.elements();
- }
-
- private native static final Vector nativeGetResources(String name);
-
-
- /**
- * Returns a String[] of native package names. The default
- * implementation tries to load a list of package from
- * the META-INF/INDEX.LIST file in the boot jar file.
- * If not found or if any exception is raised, it returns
- * an empty array. You may decide this needs native help.
- */
- private static String[] getBootPackages()
- {
- try
- {
- Enumeration indexListEnumeration = getResources("META-INF/INDEX.LIST");
- Set packageSet = new HashSet();
-
- while (indexListEnumeration.hasMoreElements())
- {
- try
- {
- String line;
- int lineToSkip = 3;
- BufferedReader reader = new BufferedReader(
- new InputStreamReader(
- ((URL) indexListEnumeration.nextElement()).openStream()));
- while ((line = reader.readLine()) != null)
- {
- if (lineToSkip == 0)
- {
- if (line.length() == 0)
- lineToSkip = 1;
- else
- packageSet.add(line.replace('/', '.'));
- }
- else
- lineToSkip--;
- }
- reader.close();
- }
- catch (IOException e)
- {
- // Empty catch block on purpose
- }
- }
- return (String[]) packageSet.toArray(new String[packageSet.size()]);
- }
- catch (Exception e)
- {
- return new String[0];
- }
- }
-
-
- /**
- * Helper to get a package from the bootstrap class loader.
- *
- * @param name the name to find
- * @return the named package, if it exists
- */
- static Package getPackage(String name)
- {
- return (Package)definedPackages.get(name);
- }
-
-
-
- /**
- * Helper to get all packages from the bootstrap class loader.
- *
- * @return all named packages, if any exist
- */
- static Package[] getPackages()
- {
- Package[] packages = new Package[definedPackages.size()];
- definedPackages.values().toArray(packages);
- return packages;
- }
-
- /**
- * Helper for java.lang.Integer, Byte, etc to get the TYPE class
- * at initialization time. The type code is one of the chars that
- * represents the primitive type as in JNI.
- *
- * <ul>
- * <li>'Z' - boolean</li>
- * <li>'B' - byte</li>
- * <li>'C' - char</li>
- * <li>'D' - double</li>
- * <li>'F' - float</li>
- * <li>'I' - int</li>
- * <li>'J' - long</li>
- * <li>'S' - short</li>
- * <li>'V' - void</li>
- * </ul>
- *
- * @param type the primitive type
- * @return a "bogus" class representing the primitive type
- */
- static final native Class getPrimitiveClass(char type);
-
- /**
- * The system default for assertion status. This is used for all system
- * classes (those with a null ClassLoader), as well as the initial value for
- * every ClassLoader's default assertion status.
- *
- * @return the system-wide default assertion status
- */
- static native final boolean defaultAssertionStatus();
-
- static native final boolean defaultUserAssertionStatus();
-
-
- static final Map packageAssertionMap =
- Collections.unmodifiableMap(packageAssertionStatus0(Boolean.TRUE, Boolean.FALSE));
-
- static native final Map packageAssertionStatus0(Boolean jtrue, Boolean jfalse);
- /**
- * The system default for package assertion status. This is used for all
- * ClassLoader's packageAssertionStatus defaults. It must be a map of
- * package names to Boolean.TRUE or Boolean.FALSE, with the unnamed package
- * represented as a null key.
- *
- * @return a (read-only) map for the default packageAssertionStatus
- */
-
- static final Map packageAssertionStatus() {
- return packageAssertionMap;
- }
-
- static final Map classAssertionMap =
- Collections.unmodifiableMap(classAssertionStatus0(Boolean.TRUE, Boolean.FALSE));
-
- static native final Map classAssertionStatus0(Boolean jtrue, Boolean jfalse);
-
- /**
- * The system default for class assertion status. This is used for all
- * ClassLoader's classAssertionStatus defaults. It must be a map of
- * class names to Boolean.TRUE or Boolean.FALSE
- *
- * @return a (read-only) map for the default classAssertionStatus
- */
- static final Map classAssertionStatus() {
- return classAssertionMap;
- }
-
- static ClassLoader getSystemClassLoader()
- {
- return ClassLoader.defaultGetSystemClassLoader();
- }
-
- /**
- * Find the class if this class loader previously defined this class
- * or if this class loader has been recorded as the initiating class loader
- * for this class.
- */
- static native Class findLoadedClass(ClassLoader cl, String name);
-
- /**
- * The Instrumentation object created by the vm when agents are defined.
- */
- static final Instrumentation instrumenter = null;
-
- /**
- * Call the transformers of the possible Instrumentation object. This
- * implementation assumes the instrumenter is a
- * <code>InstrumentationImpl</code> object. VM implementors would
- * have to redefine this method if they provide their own implementation
- * of the <code>Instrumentation</code> interface.
- *
- * @param loader the initiating loader
- * @param name the name of the class
- * @param data the data representing the classfile, in classfile format
- * @param offset the offset into the data where the classfile starts
- * @param len the length of the classfile data in the array
- * @param pd the protection domain
- * @return the new data representing the classfile
- */
- static final Class defineClassWithTransformers(ClassLoader loader,
- String name, byte[] data, int offset, int len, ProtectionDomain pd)
- {
-
- if (instrumenter != null)
- {
- byte[] modifiedData = new byte[len];
- System.arraycopy(data, offset, modifiedData, 0, len);
- modifiedData =
- ((InstrumentationImpl)instrumenter).callTransformers(loader, name,
- null, pd, modifiedData);
-
- return defineClass(loader, name, modifiedData, 0, modifiedData.length,
- pd);
- }
- else
- {
- return defineClass(loader, name, data, offset, len, pd);
- }
- }
-}
+++ /dev/null
-/* VMString.java -- VM Specific String methods
- Copyright (C) 2003 Free Software Foundation
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-package java.lang;
-
-import java.lang.ref.WeakReference;
-import java.util.WeakHashMap;
-
-/*
- * This class is a reference version, mainly for compiling a class library
- * jar. It is likely that VM implementers replace this with their own
- * version that can communicate effectively with the VM.
- */
-
-/**
- * Code relocated from java.lang.String by
- * @author Dave Grove <groved@us.ibm.com>
- */
-final class VMString
-{
-
- /**
- * Holds the references for each intern()'d String. If all references to
- * the string disappear, and the VM properly supports weak references,
- * the String will be GC'd.
- */
-// private static final WeakHashMap internTable = new WeakHashMap();
-
- /**
- * Fetches this String from the intern hashtable. If two Strings are
- * considered equal, by the equals() method, then intern() will return the
- * same String instance. ie. if (s1.equals(s2)) then
- * (s1.intern() == s2.intern()). All string literals and string-valued
- * constant expressions are already interned.
- *
- * @param str the String to intern
- * @return the interned String
- */
-// static String intern(String str)
-// {
-// synchronized (internTable)
-// {
-// WeakReference ref = (WeakReference) internTable.get(str);
-// if (ref != null)
-// {
-// String s = (String) ref.get();
-// // If s is null, then no strong references exist to the String;
-// // the weak hash map will soon delete the key.
-// if (s != null)
-// return s;
-// }
-// internTable.put(str, new WeakReference(str));
-// }
-// return str;
-// }
-
- /**
- * this one is native in CACAO
- */
- static native String intern(String str);
-
-} // class VMString
+++ /dev/null
-/* VMThread -- VM interface for Thread of executable code
- Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-package java.lang;
-
-/**
- * VM interface for Thread of executable code. Holds VM dependent state.
- * It is deliberately package local and final and should only be accessed
- * by the Thread class.
- * <p>
- * This is the GNU Classpath reference implementation, it should be adapted
- * for a specific VM.
- * <p>
- * The following methods must be implemented:
- * <ul>
- * <li>native void start(long stacksize);
- * <li>native void interrupt();
- * <li>native boolean isInterrupted();
- * <li>native void suspend();
- * <li>native void resume();
- * <li>native void nativeSetPriority(int priority);
- * <li>native void nativeStop(Throwable t);
- * <li>native static Thread currentThread();
- * <li>static native void yield();
- * <li>static native boolean interrupted();
- * </ul>
- * All other methods may be implemented to make Thread handling more efficient
- * or to implement some optional (and sometimes deprecated) behaviour. Default
- * implementations are provided but it is highly recommended to optimize them
- * for a specific VM.
- *
- * @author Jeroen Frijters (jeroen@frijters.net)
- * @author Dalibor Topic (robilad@kaffe.org)
- */
-final class VMThread
-{
- /**
- * The Thread object that this VM state belongs to.
- * Used in currentThread() and start().
- * Note: when this thread dies, this reference is *not* cleared
- */
- volatile Thread thread;
-
- /**
- * Flag that is set when the thread runs, used by stop() to protect against
- * stop's getting lost.
- */
- private volatile boolean running;
-
- /**
- * VM private data.
- */
- private transient Object vmdata;
-
- /**
- * Private constructor, create VMThreads with the static create method.
- *
- * @param thread The Thread object that was just created.
- */
- private VMThread(Thread thread)
- {
- this.thread = thread;
- }
-
- /**
- * This method is the initial Java code that gets executed when a native
- * thread starts. It's job is to coordinate with the rest of the VMThread
- * logic and to start executing user code and afterwards handle clean up.
- */
- private void run()
- {
- try
- {
- try
- {
- running = true;
- synchronized(thread)
- {
- Throwable t = thread.stillborn;
- if(t != null)
- {
- thread.stillborn = null;
- throw t;
- }
- }
- thread.run();
- }
- catch(Throwable t)
- {
- try
- {
- Thread.UncaughtExceptionHandler handler;
- handler = thread.getUncaughtExceptionHandler();
- handler.uncaughtException(thread, t);
- }
- catch(Throwable ignore)
- {
- }
- }
- }
- finally
- {
- // Setting runnable to false is partial protection against stop
- // being called while we're cleaning up. To be safe all code in
- // VMThread be unstoppable.
- running = false;
- thread.die();
- synchronized(this)
- {
- // release the threads waiting to join us
- notifyAll();
- }
- }
- }
-
- /**
- * Creates a native Thread. This is called from the start method of Thread.
- * The Thread is started.
- *
- * @param thread The newly created Thread object
- * @param stacksize Indicates the requested stacksize. Normally zero,
- * non-zero values indicate requested stack size in bytes but it is up
- * to the specific VM implementation to interpret them and may be ignored.
- */
- static void create(Thread thread, long stacksize)
- {
- VMThread vmThread = new VMThread(thread);
- thread.vmThread = vmThread;
- vmThread.start(stacksize);
- }
-
- /**
- * Gets the name of the thread. Usually this is the name field of the
- * associated Thread object, but some implementation might choose to
- * return the name of the underlying platform thread.
- */
- String getName()
- {
- return thread.name;
- }
-
- /**
- * Set the name of the thread. Usually this sets the name field of the
- * associated Thread object, but some implementations might choose to
- * set the name of the underlying platform thread.
- * @param name The new name
- */
- void setName(String name)
- {
- thread.name = name;
- }
-
- /**
- * Set the thread priority field in the associated Thread object and
- * calls the native method to set the priority of the underlying
- * platform thread.
- * @param priority The new priority
- */
- void setPriority(int priority)
- {
- thread.priority = priority;
- nativeSetPriority(priority);
- }
-
- /**
- * Returns the priority. Usually this is the priority field from the
- * associated Thread object, but some implementation might choose to
- * return the priority of the underlying platform thread.
- * @return this Thread's priority
- */
- int getPriority()
- {
- return thread.priority;
- }
-
- /**
- * Returns true if the thread is a daemon thread. Usually this is the
- * daemon field from the associated Thread object, but some
- * implementation might choose to return the daemon state of the underlying
- * platform thread.
- * @return whether this is a daemon Thread or not
- */
- boolean isDaemon()
- {
- return thread.daemon;
- }
-
- /**
- * Returns the number of stack frames in this Thread.
- * Will only be called when when a previous call to suspend() returned true.
- *
- * @deprecated unsafe operation
- */
- native int countStackFrames();
-
- /**
- * Wait the specified amount of time for the Thread in question to die.
- *
- * <p>Note that 1,000,000 nanoseconds == 1 millisecond, but most VMs do
- * not offer that fine a grain of timing resolution. Besides, there is
- * no guarantee that this thread can start up immediately when time expires,
- * because some other thread may be active. So don't expect real-time
- * performance.
- *
- * @param ms the number of milliseconds to wait, or 0 for forever
- * @param ns the number of extra nanoseconds to sleep (0-999999)
- * @throws InterruptedException if the Thread is interrupted; it's
- * <i>interrupted status</i> will be cleared
- */
- synchronized void join(long ms, int ns) throws InterruptedException
- {
- // Round up
- ms += (ns != 0) ? 1 : 0;
-
- // Compute end time, but don't overflow
- long now = System.currentTimeMillis();
- long end = now + ms;
- if (end < now)
- end = Long.MAX_VALUE;
-
- // A VM is allowed to return from wait() without notify() having been
- // called, so we loop to handle possible spurious wakeups.
- while(thread.vmThread != null)
- {
- // We use the VMThread object to wait on, because this is a private
- // object, so client code cannot call notify on us.
- wait(ms);
- if(ms != 0)
- {
- now = System.currentTimeMillis();
- ms = end - now;
- if(ms <= 0)
- {
- break;
- }
- }
- }
- }
-
- /**
- * Cause this Thread to stop abnormally and throw the specified exception.
- * If you stop a Thread that has not yet started, the stop is ignored
- * (contrary to what the JDK documentation says).
- * <b>WARNING</b>This bypasses Java security, and can throw a checked
- * exception which the call stack is unprepared to handle. Do not abuse
- * this power.
- *
- * <p>This is inherently unsafe, as it can interrupt synchronized blocks and
- * leave data in bad states.
- *
- * <p><b>NOTE</b> stop() should take care not to stop a thread if it is
- * executing code in this class.
- *
- * @param t the Throwable to throw when the Thread dies
- * @deprecated unsafe operation, try not to use
- */
- void stop(Throwable t)
- {
- // Note: we assume that we own the lock on thread
- // (i.e. that Thread.stop() is synchronized)
- if(running)
- nativeStop(t);
- else
- thread.stillborn = t;
- }
-
- /**
- * Create a native thread on the underlying platform and start it executing
- * on the run method of this object.
- * @param stacksize the requested size of the native thread stack
- */
- native void start(long stacksize);
-
- /**
- * Interrupt this thread.
- */
- native void interrupt();
-
- /**
- * Determine whether this Thread has been interrupted, but leave
- * the <i>interrupted status</i> alone in the process.
- *
- * @return whether the Thread has been interrupted
- */
- native boolean isInterrupted();
-
- /**
- * Suspend this Thread. It will not come back, ever, unless it is resumed.
- */
- native void suspend();
-
- /**
- * Resume this Thread. If the thread is not suspended, this method does
- * nothing.
- */
- native void resume();
-
- /**
- * Set the priority of the underlying platform thread.
- *
- * @param priority the new priority
- */
- native void nativeSetPriority(int priority);
-
- /**
- * Asynchronously throw the specified throwable in this Thread.
- *
- * @param t the exception to throw
- */
- native void nativeStop(Throwable t);
-
- /**
- * Return the Thread object associated with the currently executing
- * thread.
- *
- * @return the currently executing Thread
- */
- static native Thread currentThread();
-
- /**
- * Yield to another thread. The Thread will not lose any locks it holds
- * during this time. There are no guarantees which thread will be
- * next to run, and it could even be this one, but most VMs will choose
- * the highest priority thread that has been waiting longest.
- */
- static native void yield();
-
- /**
- * Suspend the current Thread's execution for the specified amount of
- * time. The Thread will not lose any locks it has during this time. There
- * are no guarantees which thread will be next to run, but most VMs will
- * choose the highest priority thread that has been waiting longest.
- *
- * <p>Note that 1,000,000 nanoseconds == 1 millisecond, but most VMs do
- * not offer that fine a grain of timing resolution. Besides, there is
- * no guarantee that this thread can start up immediately when time expires,
- * because some other thread may be active. So don't expect real-time
- * performance.
- *
- * @param ms the number of milliseconds to sleep.
- * @param ns the number of extra nanoseconds to sleep (0-999999)
- * @throws InterruptedException if the Thread is (or was) interrupted;
- * it's <i>interrupted status</i> will be cleared
- */
- static void sleep(long ms, int ns) throws InterruptedException
- {
- // Note: JDK treats a zero length sleep is like Thread.yield(),
- // without checking the interrupted status of the thread.
- // It's unclear if this is a bug in the implementation or the spec.
- // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213203
- if (ms == 0 && ns == 0)
- {
- if (Thread.interrupted())
- throw new InterruptedException();
- return;
- }
-
- // Compute end time, but don't overflow
- long now = System.currentTimeMillis();
- long end = now + ms;
- if (end < now)
- end = Long.MAX_VALUE;
-
- // A VM is allowed to return from wait() without notify() having been
- // called, so we loop to handle possible spurious wakeups.
- VMThread vt = Thread.currentThread().vmThread;
- synchronized (vt)
- {
- while (true)
- {
- vt.wait(ms, ns);
- now = System.currentTimeMillis();
- if (now >= end)
- break;
- ms = end - now;
- ns = 0;
- }
- }
- }
-
- /**
- * Determine whether the current Thread has been interrupted, and clear
- * the <i>interrupted status</i> in the process.
- *
- * @return whether the current Thread has been interrupted
- */
- static native boolean interrupted();
-
- /**
- * Checks whether the current thread holds the monitor on a given object.
- * This allows you to do <code>assert Thread.holdsLock(obj)</code>.
- *
- * @param obj the object to check
- * @return true if the current thread is currently synchronized on obj
- * @throws NullPointerException if obj is null
- */
-// static boolean holdsLock(Object obj)
-// {
-// /* Use obj.notify to check if the current thread holds
-// * the monitor of the object.
-// * If it doesn't, notify will throw an exception.
-// */
-// try
-// {
-// obj.notify();
-// // okay, current thread holds lock
-// return true;
-// }
-// catch (IllegalMonitorStateException e)
-// {
-// // it doesn't hold the lock
-// return false;
-// }
-// }
- static native boolean holdsLock(Object obj);
-
- /**
- * Returns the current state of the thread.
- * The value must be one of "BLOCKED", "NEW",
- * "RUNNABLE", "TERMINATED", "TIMED_WAITING" or
- * "WAITING".
- *
- * @return a string corresponding to one of the
- * thread enumeration states specified above.
- */
- native String getState();
-
-}
+++ /dev/null
-/* java.lang.reflect.Constructor - reflection of Java constructors
- Copyright (C) 1998, 2001, 2004, 2005 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.lang.reflect;
-
-import gnu.java.lang.ClassHelper;
-
-import gnu.java.lang.reflect.MethodSignatureParser;
-
-import java.lang.annotation.Annotation;
-import java.util.Map;
-import java.util.Arrays;
-
-/**
- * The Constructor class represents a constructor of a class. It also allows
- * dynamic creation of an object, via reflection. Invocation on Constructor
- * objects knows how to do widening conversions, but throws
- * {@link IllegalArgumentException} if a narrowing conversion would be
- * necessary. You can query for information on this Constructor regardless
- * of location, but construction access may be limited by Java language
- * access controls. If you can't do it in the compiler, you can't normally
- * do it here either.<p>
- *
- * <B>Note:</B> This class returns and accepts types as Classes, even
- * primitive types; there are Class types defined that represent each
- * different primitive type. They are <code>java.lang.Boolean.TYPE,
- * java.lang.Byte.TYPE,</code>, also available as <code>boolean.class,
- * byte.class</code>, etc. These are not to be confused with the
- * classes <code>java.lang.Boolean, java.lang.Byte</code>, etc., which are
- * real classes.<p>
- *
- * Also note that this is not a serializable class. It is entirely feasible
- * to make it serializable using the Externalizable interface, but this is
- * on Sun, not me.
- *
- * @author John Keiser
- * @author Eric Blake <ebb9@email.byu.edu>
- * @see Member
- * @see Class
- * @see java.lang.Class#getConstructor(Class[])
- * @see java.lang.Class#getDeclaredConstructor(Class[])
- * @see java.lang.Class#getConstructors()
- * @see java.lang.Class#getDeclaredConstructors()
- * @since 1.1
- * @status updated to 1.4
- */
-public final class Constructor<T>
- extends AccessibleObject
- implements GenericDeclaration, Member
-{
- private Class<T> clazz;
- private int slot;
-
- /**
- * Unparsed annotations.
- */
- private byte[] annotations = null;
-
- /**
- * Unparsed parameter annotations.
- */
- private byte[] parameterAnnotations = null;
-
- /**
- * Annotations get parsed the first time they are
- * accessed and are then cached it this map.
- */
- private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations = null;
-
- private static final int CONSTRUCTOR_MODIFIERS
- = Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC;
-
- /**
- * Helper array for creating a new array from a java.util.Container.
- */
- private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY =
- new Annotation[0];
-
- /**
- * This class is uninstantiable except from native code.
- */
- private Constructor(Class declaringClass,int slot)
- {
- this.clazz = declaringClass;
- this.slot = slot;
- }
-
- private Constructor()
- {
- }
-
- /**
- * Gets the class that declared this constructor.
- * @return the class that declared this member
- */
- public Class<T> getDeclaringClass()
- {
- return clazz;
- }
-
- /**
- * Gets the name of this constructor (the non-qualified name of the class
- * it was declared in).
- * @return the name of this constructor
- */
- public String getName()
- {
- return getDeclaringClass().getName();
- }
-
- /**
- * Return the raw modifiers for this constructor. In particular
- * this will include the synthetic and varargs bits.
- * @return the constructor's modifiers
- */
- private native int getModifiersInternal();
-
- /**
- * Gets the modifiers this constructor uses. Use the <code>Modifier</code>
- * class to interpret the values. A constructor can only have a subset of the
- * following modifiers: public, private, protected.
- *
- * @return an integer representing the modifiers to this Member
- * @see Modifier
- */
- public int getModifiers()
- {
- return getModifiersInternal() & CONSTRUCTOR_MODIFIERS;
- }
-
- /**
- * Return true if this constructor is synthetic, false otherwise.
- * A synthetic member is one which is created by the compiler,
- * and which does not appear in the user's source code.
- * @since 1.5
- */
- public boolean isSynthetic()
- {
- return (getModifiersInternal() & Modifier.SYNTHETIC) != 0;
- }
-
- /**
- * Return true if this is a varargs constructor, that is if
- * the constructor takes a variable number of arguments.
- * @since 1.5
- */
- public boolean isVarArgs()
- {
- return (getModifiersInternal() & Modifier.VARARGS) != 0;
- }
-
- /**
- * Get the parameter list for this constructor, in declaration order. If the
- * constructor takes no parameters, returns a 0-length array (not null).
- *
- * @return a list of the types of the constructor's parameters
- */
- public native Class<?>[] getParameterTypes();
-
- /**
- * Get the exception types this constructor says it throws, in no particular
- * order. If the constructor has no throws clause, returns a 0-length array
- * (not null).
- *
- * @return a list of the types in the constructor's throws clause
- */
- public native Class<?>[] getExceptionTypes();
-
- /**
- * Compare two objects to see if they are semantically equivalent.
- * Two Constructors are semantically equivalent if they have the same
- * declaring class and the same parameter list. This ignores different
- * exception clauses, but since you can't create a Method except through the
- * VM, this is just the == relation.
- *
- * @param o the object to compare to
- * @return <code>true</code> if they are equal; <code>false</code> if not.
- */
- public boolean equals(Object o)
- {
- if (!(o instanceof Constructor))
- return false;
- Constructor that = (Constructor)o;
- if (this.getDeclaringClass() != that.getDeclaringClass())
- return false;
- if (!Arrays.equals(this.getParameterTypes(), that.getParameterTypes()))
- return false;
- return true;
- }
-
- /**
- * Get the hash code for the Constructor. The Constructor hash code is the
- * hash code of the declaring class's name.
- *
- * @return the hash code for the object
- */
- public int hashCode()
- {
- return getDeclaringClass().getName().hashCode();
- }
-
- /**
- * Get a String representation of the Constructor. A Constructor's String
- * representation is "<modifier> <classname>(<paramtypes>)
- * throws <exceptions>", where everything after ')' is omitted if
- * there are no exceptions.<br> Example:
- * <code>public java.io.FileInputStream(java.lang.Runnable)
- * throws java.io.FileNotFoundException</code>
- *
- * @return the String representation of the Constructor
- */
- public String toString()
- {
- // 128 is a reasonable buffer initial size for constructor
- StringBuilder sb = new StringBuilder(128);
- Modifier.toString(getModifiers(), sb).append(' ');
- sb.append(getDeclaringClass().getName()).append('(');
- Class[] c = getParameterTypes();
- if (c.length > 0)
- {
- sb.append(ClassHelper.getUserName(c[0]));
- for (int i = 1; i < c.length; i++)
- sb.append(',').append(ClassHelper.getUserName(c[i]));
- }
- sb.append(')');
- c = getExceptionTypes();
- if (c.length > 0)
- {
- sb.append(" throws ").append(c[0].getName());
- for (int i = 1; i < c.length; i++)
- sb.append(',').append(c[i].getName());
- }
- return sb.toString();
- }
-
- static <X extends GenericDeclaration>
- void addTypeParameters(StringBuilder sb, TypeVariable<X>[] typeArgs)
- {
- if (typeArgs.length == 0)
- return;
- sb.append('<');
- for (int i = 0; i < typeArgs.length; ++i)
- {
- if (i > 0)
- sb.append(',');
- sb.append(typeArgs[i]);
- }
- sb.append("> ");
- }
-
- public String toGenericString()
- {
- StringBuilder sb = new StringBuilder(128);
- Modifier.toString(getModifiers(), sb).append(' ');
- addTypeParameters(sb, getTypeParameters());
- sb.append(getDeclaringClass().getName()).append('(');
- Type[] types = getGenericParameterTypes();
- if (types.length > 0)
- {
- sb.append(types[0]);
- for (int i = 1; i < types.length; ++i)
- sb.append(',').append(types[i]);
- }
- sb.append(')');
- types = getGenericExceptionTypes();
- if (types.length > 0)
- {
- sb.append(" throws ").append(types[0]);
- for (int i = 1; i < types.length; i++)
- sb.append(',').append(types[i]);
- }
- return sb.toString();
- }
-
- /**
- * Create a new instance by invoking the constructor. Arguments are
- * automatically unwrapped and widened, if needed.<p>
- *
- * If this class is abstract, you will get an
- * <code>InstantiationException</code>. If the constructor takes 0
- * arguments, you may use null or a 0-length array for <code>args</code>.<p>
- *
- * If this Constructor enforces access control, your runtime context is
- * evaluated, and you may have an <code>IllegalAccessException</code> if
- * you could not create this object in similar compiled code. If the class
- * is uninitialized, you trigger class initialization, which may end in a
- * <code>ExceptionInInitializerError</code>.<p>
- *
- * Then, the constructor is invoked. If it completes normally, the return
- * value will be the new object. If it completes abruptly, the exception is
- * wrapped in an <code>InvocationTargetException</code>.
- *
- * @param args the arguments to the constructor
- * @return the newly created object
- * @throws IllegalAccessException if the constructor could not normally be
- * called by the Java code (i.e. it is not public)
- * @throws IllegalArgumentException if the number of arguments is incorrect;
- * or if the arguments types are wrong even with a widening
- * conversion
- * @throws InstantiationException if the class is abstract
- * @throws InvocationTargetException if the constructor throws an exception
- * @throws ExceptionInInitializerError if construction triggered class
- * initialization, which then failed
- */
- public T newInstance(Object... args)
- throws InstantiationException, IllegalAccessException,
- InvocationTargetException
- {
- return constructNative(args, clazz, slot);
- }
-
- private native T constructNative(Object[] args, Class declaringClass,
- int slot)
- throws InstantiationException, IllegalAccessException,
- InvocationTargetException;
-
- /**
- * Returns an array of <code>TypeVariable</code> objects that represents
- * the type variables declared by this constructor, in declaration order.
- * An array of size zero is returned if this constructor has no type
- * variables.
- *
- * @return the type variables associated with this constructor.
- * @throws GenericSignatureFormatError if the generic signature does
- * not conform to the format specified in the Virtual Machine
- * specification, version 3.
- * @since 1.5
- */
- public TypeVariable<Constructor<T>>[] getTypeParameters()
- {
- String sig = getSignature();
- if (sig == null)
- return new TypeVariable[0];
- MethodSignatureParser p = new MethodSignatureParser(this, sig);
- return p.getTypeParameters();
- }
-
- /**
- * Return the String in the Signature attribute for this constructor. If there
- * is no Signature attribute, return null.
- */
- private native String getSignature();
-
- /**
- * Returns an array of <code>Type</code> objects that represents
- * the exception types declared by this constructor, in declaration order.
- * An array of size zero is returned if this constructor declares no
- * exceptions.
- *
- * @return the exception types declared by this constructor.
- * @throws GenericSignatureFormatError if the generic signature does
- * not conform to the format specified in the Virtual Machine
- * specification, version 3.
- * @since 1.5
- */
- public Type[] getGenericExceptionTypes()
- {
- String sig = getSignature();
- if (sig == null)
- return getExceptionTypes();
- MethodSignatureParser p = new MethodSignatureParser(this, sig);
- return p.getGenericExceptionTypes();
- }
-
- /**
- * Returns an array of <code>Type</code> objects that represents
- * the parameter list for this constructor, in declaration order.
- * An array of size zero is returned if this constructor takes no
- * parameters.
- *
- * @return a list of the types of the constructor's parameters
- * @throws GenericSignatureFormatError if the generic signature does
- * not conform to the format specified in the Virtual Machine
- * specification, version 3.
- * @since 1.5
- */
- public Type[] getGenericParameterTypes()
- {
- String sig = getSignature();
- if (sig == null)
- return getParameterTypes();
- MethodSignatureParser p = new MethodSignatureParser(this, sig);
- return p.getGenericParameterTypes();
- }
-
- /**
- * @throws NullPointerException {@inheritDoc}
- * @since 1.5
- */
- public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
- if (annotationClass == null)
- throw new NullPointerException();
-
- return (T)declaredAnnotations().get(annotationClass);
- }
-
- /**
- * @since 1.5
- */
- public Annotation[] getDeclaredAnnotations() {
- return declaredAnnotations().values().toArray(EMPTY_ANNOTATIONS_ARRAY);
- }
-
- /**
- * Parses the annotations if they aren't parsed yet and stores them into
- * the declaredAnnotations map and return this map.
- */
- private synchronized native Map<Class<? extends Annotation>, Annotation> declaredAnnotations();
-
- /**
- * Returns an array of arrays that represent the annotations on the formal
- * parameters, in declaration order, of the method represented by
- * this <tt>Method</tt> object. (Returns an array of length zero if the
- * underlying method is parameterless. If the method has one or more
- * parameters, a nested array of length zero is returned for each parameter
- * with no annotations.) The annotation objects contained in the returned
- * arrays are serializable. The caller of this method is free to modify
- * the returned arrays; it will have no effect on the arrays returned to
- * other callers.
- *
- * @return an array of arrays that represent the annotations on the formal
- * parameters, in declaration order, of the method represented by this
- * Method object
- * @since 1.5
- */
- public native Annotation[][] getParameterAnnotations();
-}
+++ /dev/null
-/* java.lang.reflect.Field - reflection of Java fields
- Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.lang.reflect;
-
-import gnu.java.lang.ClassHelper;
-
-import gnu.java.lang.reflect.FieldSignatureParser;
-
-import java.lang.annotation.Annotation;
-import java.util.Map;
-
-
-/**
- * The Field class represents a member variable of a class. It also allows
- * dynamic access to a member, via reflection. This works for both
- * static and instance fields. Operations on Field objects know how to
- * do widening conversions, but throw {@link IllegalArgumentException} if
- * a narrowing conversion would be necessary. You can query for information
- * on this Field regardless of location, but get and set access may be limited
- * by Java language access controls. If you can't do it in the compiler, you
- * can't normally do it here either.<p>
- *
- * <B>Note:</B> This class returns and accepts types as Classes, even
- * primitive types; there are Class types defined that represent each
- * different primitive type. They are <code>java.lang.Boolean.TYPE,
- * java.lang.Byte.TYPE,</code>, also available as <code>boolean.class,
- * byte.class</code>, etc. These are not to be confused with the
- * classes <code>java.lang.Boolean, java.lang.Byte</code>, etc., which are
- * real classes.<p>
- *
- * Also note that this is not a serializable class. It is entirely feasible
- * to make it serializable using the Externalizable interface, but this is
- * on Sun, not me.
- *
- * @author John Keiser
- * @author Eric Blake <ebb9@email.byu.edu>
- * @see Member
- * @see Class
- * @see Class#getField(String)
- * @see Class#getDeclaredField(String)
- * @see Class#getFields()
- * @see Class#getDeclaredFields()
- * @since 1.1
- * @status updated to 1.4
- */
-public final class Field
-extends AccessibleObject implements Member
-{
- private Class clazz;
- private String name;
- private int slot;
-
- /**
- * Unparsed annotations.
- */
- private byte[] annotations = null;
-
- /**
- * Annotations get parsed the first time they are
- * accessed and are then cached it this map.
- */
- private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations = null;
-
- private static final int FIELD_MODIFIERS
- = Modifier.FINAL | Modifier.PRIVATE | Modifier.PROTECTED
- | Modifier.PUBLIC | Modifier.STATIC | Modifier.TRANSIENT
- | Modifier.VOLATILE;
-
- /**
- * Helper array for creating a new array from a java.util.Container.
- */
- private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY =
- new Annotation[0];
-
- /**
- * This class is uninstantiable except natively.
- */
- private Field(Class declaringClass, String name, int slot)
- {
- this.clazz = declaringClass;
- this.name = name;
- this.slot = slot;
- }
-
- /**
- * Gets the class that declared this field, or the class where this field
- * is a non-inherited member.
- * @return the class that declared this member
- */
- public Class<?> getDeclaringClass()
- {
- return clazz;
- }
-
- /**
- * Gets the name of this field.
- * @return the name of this field
- */
- public String getName()
- {
- return name;
- }
-
- /**
- * Return the raw modifiers for this field.
- * @return the field's modifiers
- */
- private native int getModifiersInternal();
-
- /**
- * Gets the modifiers this field uses. Use the <code>Modifier</code>
- * class to interpret the values. A field can only have a subset of the
- * following modifiers: public, private, protected, static, final,
- * transient, and volatile.
- *
- * @return an integer representing the modifiers to this Member
- * @see Modifier
- */
- public int getModifiers()
- {
- return getModifiersInternal() & FIELD_MODIFIERS;
- }
-
- /**
- * Return true if this field is synthetic, false otherwise.
- * @since 1.5
- */
- public boolean isSynthetic()
- {
- return (getModifiersInternal() & Modifier.SYNTHETIC) != 0;
- }
-
- /**
- * Return true if this field represents an enum constant,
- * false otherwise.
- * @since 1.5
- */
- public boolean isEnumConstant()
- {
- return (getModifiersInternal() & Modifier.ENUM) != 0;
- }
-
- /**
- * Gets the type of this field.
- * @return the type of this field
- */
- public native Class<?> getType();
-
- /**
- * Compare two objects to see if they are semantically equivalent.
- * Two Fields are semantically equivalent if they have the same declaring
- * class, name, and type. Since you can't creat a Field except through
- * the VM, this is just the == relation.
- *
- * @param o the object to compare to
- * @return <code>true</code> if they are equal; <code>false</code> if not
- */
- public boolean equals(Object o)
- {
- if (!(o instanceof Field))
- return false;
- Field that = (Field)o;
- if (this.getDeclaringClass() != that.getDeclaringClass())
- return false;
- if (!this.getName().equals(that.getName()))
- return false;
- if (this.getType() != that.getType())
- return false;
- return true;
- }
-
- /**
- * Get the hash code for the Field. The Field hash code is the hash code
- * of its name XOR'd with the hash code of its class name.
- *
- * @return the hash code for the object.
- */
- public int hashCode()
- {
- return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
- }
-
- /**
- * Get a String representation of the Field. A Field's String
- * representation is "<modifiers> <type>
- * <class>.<fieldname>".<br> Example:
- * <code>public transient boolean gnu.parse.Parser.parseComplete</code>
- *
- * @return the String representation of the Field
- */
- public String toString()
- {
- // 64 is a reasonable buffer initial size for field
- StringBuilder sb = new StringBuilder(64);
- Modifier.toString(getModifiers(), sb).append(' ');
- sb.append(ClassHelper.getUserName(getType())).append(' ');
- sb.append(getDeclaringClass().getName()).append('.');
- sb.append(getName());
- return sb.toString();
- }
-
- public String toGenericString()
- {
- StringBuilder sb = new StringBuilder(64);
- Modifier.toString(getModifiers(), sb).append(' ');
- sb.append(getGenericType()).append(' ');
- sb.append(getDeclaringClass().getName()).append('.');
- sb.append(getName());
- return sb.toString();
- }
-
- /**
- * Get the value of this Field. If it is primitive, it will be wrapped
- * in the appropriate wrapper type (boolean = java.lang.Boolean).<p>
- *
- * If the field is static, <code>o</code> will be ignored. Otherwise, if
- * <code>o</code> is null, you get a <code>NullPointerException</code>,
- * and if it is incompatible with the declaring class of the field, you
- * get an <code>IllegalArgumentException</code>.<p>
- *
- * Next, if this Field enforces access control, your runtime context is
- * evaluated, and you may have an <code>IllegalAccessException</code> if
- * you could not access this field in similar compiled code. If the field
- * is static, and its class is uninitialized, you trigger class
- * initialization, which may end in a
- * <code>ExceptionInInitializerError</code>.<p>
- *
- * Finally, the field is accessed, and primitives are wrapped (but not
- * necessarily in new objects). This method accesses the field of the
- * declaring class, even if the instance passed in belongs to a subclass
- * which declares another field to hide this one.
- *
- * @param o the object to get the value of this Field from
- * @return the value of the Field
- * @throws IllegalAccessException if you could not normally access this field
- * (i.e. it is not public)
- * @throws IllegalArgumentException if <code>o</code> is not an instance of
- * the class or interface declaring this field
- * @throws NullPointerException if <code>o</code> is null and this field
- * requires an instance
- * @throws ExceptionInInitializerError if accessing a static field triggered
- * class initialization, which then failed
- * @see #getBoolean(Object)
- * @see #getByte(Object)
- * @see #getChar(Object)
- * @see #getShort(Object)
- * @see #getInt(Object)
- * @see #getLong(Object)
- * @see #getFloat(Object)
- * @see #getDouble(Object)
- */
- public native Object get(Object o)
- throws IllegalAccessException;
-
- /**
- * Get the value of this boolean Field. If the field is static,
- * <code>o</code> will be ignored.
- *
- * @param o the object to get the value of this Field from
- * @return the value of the Field
- * @throws IllegalAccessException if you could not normally access this field
- * (i.e. it is not public)
- * @throws IllegalArgumentException if this is not a boolean field of
- * <code>o</code>, or if <code>o</code> is not an instance of the
- * declaring class of this field
- * @throws NullPointerException if <code>o</code> is null and this field
- * requires an instance
- * @throws ExceptionInInitializerError if accessing a static field triggered
- * class initialization, which then failed
- * @see #get(Object)
- */
- public native boolean getBoolean(Object o)
- throws IllegalAccessException;
-
- /**
- * Get the value of this byte Field. If the field is static,
- * <code>o</code> will be ignored.
- *
- * @param o the object to get the value of this Field from
- * @return the value of the Field
- * @throws IllegalAccessException if you could not normally access this field
- * (i.e. it is not public)
- * @throws IllegalArgumentException if this is not a byte field of
- * <code>o</code>, or if <code>o</code> is not an instance of the
- * declaring class of this field
- * @throws NullPointerException if <code>o</code> is null and this field
- * requires an instance
- * @throws ExceptionInInitializerError if accessing a static field triggered
- * class initialization, which then failed
- * @see #get(Object)
- */
- public native byte getByte(Object o)
- throws IllegalAccessException;
-
- /**
- * Get the value of this Field as a char. If the field is static,
- * <code>o</code> will be ignored.
- *
- * @throws IllegalAccessException if you could not normally access this field
- * (i.e. it is not public)
- * @throws IllegalArgumentException if this is not a char field of
- * <code>o</code>, or if <code>o</code> is not an instance
- * of the declaring class of this field
- * @throws NullPointerException if <code>o</code> is null and this field
- * requires an instance
- * @throws ExceptionInInitializerError if accessing a static field triggered
- * class initialization, which then failed
- * @see #get(Object)
- */
- public native char getChar(Object o)
- throws IllegalAccessException;
-
- /**
- * Get the value of this Field as a short. If the field is static,
- * <code>o</code> will be ignored.
- *
- * @param o the object to get the value of this Field from
- * @return the value of the Field
- * @throws IllegalAccessException if you could not normally access this field
- * (i.e. it is not public)
- * @throws IllegalArgumentException if this is not a byte or short
- * field of <code>o</code>, or if <code>o</code> is not an instance
- * of the declaring class of this field
- * @throws NullPointerException if <code>o</code> is null and this field
- * requires an instance
- * @throws ExceptionInInitializerError if accessing a static field triggered
- * class initialization, which then failed
- * @see #get(Object)
- */
- public native short getShort(Object o)
- throws IllegalAccessException;
-
- /**
- * Get the value of this Field as an int. If the field is static,
- * <code>o</code> will be ignored.
- *
- * @param o the object to get the value of this Field from
- * @return the value of the Field
- * @throws IllegalAccessException if you could not normally access this field
- * (i.e. it is not public)
- * @throws IllegalArgumentException if this is not a byte, short, char, or
- * int field of <code>o</code>, or if <code>o</code> is not an
- * instance of the declaring class of this field
- * @throws NullPointerException if <code>o</code> is null and this field
- * requires an instance
- * @throws ExceptionInInitializerError if accessing a static field triggered
- * class initialization, which then failed
- * @see #get(Object)
- */
- public native int getInt(Object o)
- throws IllegalAccessException;
-
- /**
- * Get the value of this Field as a long. If the field is static,
- * <code>o</code> will be ignored.
- *
- * @param o the object to get the value of this Field from
- * @return the value of the Field
- * @throws IllegalAccessException if you could not normally access this field
- * (i.e. it is not public)
- * @throws IllegalArgumentException if this is not a byte, short, char, int,
- * or long field of <code>o</code>, or if <code>o</code> is not an
- * instance of the declaring class of this field
- * @throws NullPointerException if <code>o</code> is null and this field
- * requires an instance
- * @throws ExceptionInInitializerError if accessing a static field triggered
- * class initialization, which then failed
- * @see #get(Object)
- */
- public native long getLong(Object o)
- throws IllegalAccessException;
-
- /**
- * Get the value of this Field as a float. If the field is static,
- * <code>o</code> will be ignored.
- *
- * @param o the object to get the value of this Field from
- * @return the value of the Field
- * @throws IllegalAccessException if you could not normally access this field
- * (i.e. it is not public)
- * @throws IllegalArgumentException if this is not a byte, short, char, int,
- * long, or float field of <code>o</code>, or if <code>o</code> is
- * not an instance of the declaring class of this field
- * @throws NullPointerException if <code>o</code> is null and this field
- * requires an instance
- * @throws ExceptionInInitializerError if accessing a static field triggered
- * class initialization, which then failed
- * @see #get(Object)
- */
- public native float getFloat(Object o)
- throws IllegalAccessException;
-
- /**
- * Get the value of this Field as a double. If the field is static,
- * <code>o</code> will be ignored.
- *
- * @param o the object to get the value of this Field from
- * @return the value of the Field
- * @throws IllegalAccessException if you could not normally access this field
- * (i.e. it is not public)
- * @throws IllegalArgumentException if this is not a byte, short, char, int,
- * long, float, or double field of <code>o</code>, or if
- * <code>o</code> is not an instance of the declaring class of this
- * field
- * @throws NullPointerException if <code>o</code> is null and this field
- * requires an instance
- * @throws ExceptionInInitializerError if accessing a static field triggered
- * class initialization, which then failed
- * @see #get(Object)
- */
- public native double getDouble(Object o)
- throws IllegalAccessException;
-
- /**
- * Set the value of this Field. If it is a primitive field, the value
- * will be unwrapped from the passed object (boolean = java.lang.Boolean).<p>
- *
- * If the field is static, <code>o</code> will be ignored. Otherwise, if
- * <code>o</code> is null, you get a <code>NullPointerException</code>,
- * and if it is incompatible with the declaring class of the field, you
- * get an <code>IllegalArgumentException</code>.<p>
- *
- * Next, if this Field enforces access control, your runtime context is
- * evaluated, and you may have an <code>IllegalAccessException</code> if
- * you could not access this field in similar compiled code. This also
- * occurs whether or not there is access control if the field is final.
- * If the field is primitive, and unwrapping your argument fails, you will
- * get an <code>IllegalArgumentException</code>; likewise, this error
- * happens if <code>value</code> cannot be cast to the correct object type.
- * If the field is static, and its class is uninitialized, you trigger class
- * initialization, which may end in a
- * <code>ExceptionInInitializerError</code>.<p>
- *
- * Finally, the field is set with the widened value. This method accesses
- * the field of the declaring class, even if the instance passed in belongs
- * to a subclass which declares another field to hide this one.
- *
- * @param o the object to set this Field on
- * @param value the value to set this Field to
- * @throws IllegalAccessException if you could not normally access this field
- * (i.e. it is not public)
- * @throws IllegalArgumentException if <code>value</code> cannot be
- * converted by a widening conversion to the underlying type of
- * the Field, or if <code>o</code> is not an instance of the class
- * declaring this field
- * @throws NullPointerException if <code>o</code> is null and this field
- * requires an instance
- * @throws ExceptionInInitializerError if accessing a static field triggered
- * class initialization, which then failed
- * @see #setBoolean(Object, boolean)
- * @see #setByte(Object, byte)
- * @see #setChar(Object, char)
- * @see #setShort(Object, short)
- * @see #setInt(Object, int)
- * @see #setLong(Object, long)
- * @see #setFloat(Object, float)
- * @see #setDouble(Object, double)
- */
- public native void set(Object o, Object value)
- throws IllegalAccessException;
-
- /**
- * Set this boolean Field. If the field is static, <code>o</code> will be
- * ignored.
- *
- * @param o the object to set this Field on
- * @param value the value to set this Field to
- * @throws IllegalAccessException if you could not normally access this field
- * (i.e. it is not public)
- * @throws IllegalArgumentException if this is not a boolean field, or if
- * <code>o</code> is not an instance of the class declaring this
- * field
- * @throws NullPointerException if <code>o</code> is null and this field
- * requires an instance
- * @throws ExceptionInInitializerError if accessing a static field triggered
- * class initialization, which then failed
- * @see #set(Object, Object)
- */
- public native void setBoolean(Object o, boolean value)
- throws IllegalAccessException;
-
- /**
- * Set this byte Field. If the field is static, <code>o</code> will be
- * ignored.
- *
- * @param o the object to set this Field on
- * @param value the value to set this Field to
- * @throws IllegalAccessException if you could not normally access this field
- * (i.e. it is not public)
- * @throws IllegalArgumentException if this is not a byte, short, int, long,
- * float, or double field, or if <code>o</code> is not an instance
- * of the class declaring this field
- * @throws NullPointerException if <code>o</code> is null and this field
- * requires an instance
- * @throws ExceptionInInitializerError if accessing a static field triggered
- * class initialization, which then failed
- * @see #set(Object, Object)
- */
- public native void setByte(Object o, byte value)
- throws IllegalAccessException;
-
- /**
- * Set this char Field. If the field is static, <code>o</code> will be
- * ignored.
- *
- * @param o the object to set this Field on
- * @param value the value to set this Field to
- * @throws IllegalAccessException if you could not normally access this field
- * (i.e. it is not public)
- * @throws IllegalArgumentException if this is not a char, int, long,
- * float, or double field, or if <code>o</code> is not an instance
- * of the class declaring this field
- * @throws NullPointerException if <code>o</code> is null and this field
- * requires an instance
- * @throws ExceptionInInitializerError if accessing a static field triggered
- * class initialization, which then failed
- * @see #set(Object, Object)
- */
- public native void setChar(Object o, char value)
- throws IllegalAccessException;
-
- /**
- * Set this short Field. If the field is static, <code>o</code> will be
- * ignored.
- *
- * @param o the object to set this Field on
- * @param value the value to set this Field to
- * @throws IllegalAccessException if you could not normally access this field
- * (i.e. it is not public)
- * @throws IllegalArgumentException if this is not a short, int, long,
- * float, or double field, or if <code>o</code> is not an instance
- * of the class declaring this field
- * @throws NullPointerException if <code>o</code> is null and this field
- * requires an instance
- * @throws ExceptionInInitializerError if accessing a static field triggered
- * class initialization, which then failed
- * @see #set(Object, Object)
- */
- public native void setShort(Object o, short value)
- throws IllegalAccessException;
-
- /**
- * Set this int Field. If the field is static, <code>o</code> will be
- * ignored.
- *
- * @param o the object to set this Field on
- * @param value the value to set this Field to
- * @throws IllegalAccessException if you could not normally access this field
- * (i.e. it is not public)
- * @throws IllegalArgumentException if this is not an int, long, float, or
- * double field, or if <code>o</code> is not an instance of the
- * class declaring this field
- * @throws NullPointerException if <code>o</code> is null and this field
- * requires an instance
- * @throws ExceptionInInitializerError if accessing a static field triggered
- * class initialization, which then failed
- * @see #set(Object, Object)
- */
- public native void setInt(Object o, int value)
- throws IllegalAccessException;
-
- /**
- * Set this long Field. If the field is static, <code>o</code> will be
- * ignored.
- *
- * @param o the object to set this Field on
- * @param value the value to set this Field to
- * @throws IllegalAccessException if you could not normally access this field
- * (i.e. it is not public)
- * @throws IllegalArgumentException if this is not a long, float, or double
- * field, or if <code>o</code> is not an instance of the class
- * declaring this field
- * @throws NullPointerException if <code>o</code> is null and this field
- * requires an instance
- * @throws ExceptionInInitializerError if accessing a static field triggered
- * class initialization, which then failed
- * @see #set(Object, Object)
- */
- public native void setLong(Object o, long value)
- throws IllegalAccessException;
-
- /**
- * Set this float Field. If the field is static, <code>o</code> will be
- * ignored.
- *
- * @param o the object to set this Field on
- * @param value the value to set this Field to
- * @throws IllegalAccessException if you could not normally access this field
- * (i.e. it is not public)
- * @throws IllegalArgumentException if this is not a float or long field, or
- * if <code>o</code> is not an instance of the class declaring this
- * field
- * @throws NullPointerException if <code>o</code> is null and this field
- * requires an instance
- * @throws ExceptionInInitializerError if accessing a static field triggered
- * class initialization, which then failed
- * @see #set(Object, Object)
- */
- public native void setFloat(Object o, float value)
- throws IllegalAccessException;
-
- /**
- * Set this double Field. If the field is static, <code>o</code> will be
- * ignored.
- *
- * @param o the object to set this Field on
- * @param value the value to set this Field to
- * @throws IllegalAccessException if you could not normally access this field
- * (i.e. it is not public)
- * @throws IllegalArgumentException if this is not a double field, or if
- * <code>o</code> is not an instance of the class declaring this
- * field
- * @throws NullPointerException if <code>o</code> is null and this field
- * requires an instance
- * @throws ExceptionInInitializerError if accessing a static field triggered
- * class initialization, which then failed
- * @see #set(Object, Object)
- */
- public native void setDouble(Object o, double value)
- throws IllegalAccessException;
-
- /**
- * Return the generic type of the field. If the field type is not a generic
- * type, the method returns the same as <code>getType()</code>.
- *
- * @throws GenericSignatureFormatError if the generic signature does
- * not conform to the format specified in the Virtual Machine
- * specification, version 3.
- * @since 1.5
- */
- public Type getGenericType()
- {
- String signature = getSignature();
- if (signature == null)
- return getType();
- FieldSignatureParser p = new FieldSignatureParser(getDeclaringClass(),
- signature);
- return p.getFieldType();
- }
-
- /**
- * Return the String in the Signature attribute for this field. If there
- * is no Signature attribute, return null.
- */
- private native String getSignature();
-
- /**
- * @throws NullPointerException {@inheritDoc}
- * @since 1.5
- */
- public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
- if (annotationClass == null)
- throw new NullPointerException();
-
- return (T)declaredAnnotations().get(annotationClass);
- }
-
- /**
- * @since 1.5
- */
- public Annotation[] getDeclaredAnnotations() {
- return declaredAnnotations().values().toArray(EMPTY_ANNOTATIONS_ARRAY);
- }
-
- /**
- * Parses the annotations if they aren't parsed yet and stores them into
- * the declaredAnnotations map and return this map.
- */
- private synchronized native Map<Class<? extends Annotation>, Annotation> declaredAnnotations();
-}
+++ /dev/null
-/* java.lang.reflect.Method - reflection of Java methods
- Copyright (C) 1998, 2001, 2002, 2005, 2007 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.lang.reflect;
-
-import gnu.java.lang.ClassHelper;
-
-import gnu.java.lang.reflect.MethodSignatureParser;
-
-import java.lang.annotation.Annotation;
-import java.util.Map;
-import java.util.Arrays;
-
-/**
- * The Method class represents a member method of a class. It also allows
- * dynamic invocation, via reflection. This works for both static and
- * instance methods. Invocation on Method objects knows how to do
- * widening conversions, but throws {@link IllegalArgumentException} if
- * a narrowing conversion would be necessary. You can query for information
- * on this Method regardless of location, but invocation access may be limited
- * by Java language access controls. If you can't do it in the compiler, you
- * can't normally do it here either.<p>
- *
- * <B>Note:</B> This class returns and accepts types as Classes, even
- * primitive types; there are Class types defined that represent each
- * different primitive type. They are <code>java.lang.Boolean.TYPE,
- * java.lang.Byte.TYPE,</code>, also available as <code>boolean.class,
- * byte.class</code>, etc. These are not to be confused with the
- * classes <code>java.lang.Boolean, java.lang.Byte</code>, etc., which are
- * real classes.<p>
- *
- * Also note that this is not a serializable class. It is entirely feasible
- * to make it serializable using the Externalizable interface, but this is
- * on Sun, not me.
- *
- * @author John Keiser
- * @author Eric Blake <ebb9@email.byu.edu>
- * @see Member
- * @see Class
- * @see java.lang.Class#getMethod(String,Class[])
- * @see java.lang.Class#getDeclaredMethod(String,Class[])
- * @see java.lang.Class#getMethods()
- * @see java.lang.Class#getDeclaredMethods()
- * @since 1.1
- * @status updated to 1.4
- */
-public final class Method
-extends AccessibleObject implements Member, GenericDeclaration
-{
- Class clazz;
- String name;
- int slot;
-
- /**
- * Unparsed annotations.
- */
- private byte[] annotations = null;
-
- /**
- * Unparsed parameter annotations.
- */
- private byte[] parameterAnnotations = null;
-
- /**
- * Unparsed annotation default value.
- */
- private byte[] annotationDefault = null;
-
- /**
- * Annotations get parsed the first time they are
- * accessed and are then cached it this map.
- */
- private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations = null;
-
- private static final int METHOD_MODIFIERS
- = Modifier.ABSTRACT | Modifier.FINAL | Modifier.NATIVE
- | Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC
- | Modifier.STATIC | Modifier.STRICT | Modifier.SYNCHRONIZED;
-
- /**
- * Helper array for creating a new array from a java.util.Container.
- */
- private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY =
- new Annotation[0];
-
- /**
- * This class is uninstantiable.
- */
- private Method(Class declaringClass, String name, int slot)
- {
- this.clazz = declaringClass;
- this.name = name;
- this.slot = slot;
- }
-
- /**
- * Gets the class that declared this method, or the class where this method
- * is a non-inherited member.
- * @return the class that declared this member
- */
- public Class<?> getDeclaringClass()
- {
- return clazz;
- }
-
- /**
- * Gets the name of this method.
- * @return the name of this method
- */
- public String getName()
- {
- return name;
- }
-
- /**
- * Return the raw modifiers for this method.
- * @return the method's modifiers
- */
- private native int getModifiersInternal();
-
- /**
- * Gets the modifiers this method uses. Use the <code>Modifier</code>
- * class to interpret the values. A method can only have a subset of the
- * following modifiers: public, private, protected, abstract, static,
- * final, synchronized, native, and strictfp.
- *
- * @return an integer representing the modifiers to this Member
- * @see Modifier
- */
- public int getModifiers()
- {
- return getModifiersInternal() & METHOD_MODIFIERS;
- }
-
- /**
- * Return true if this method is a bridge method. A bridge method
- * is generated by the compiler in some situations involving
- * generics and inheritance.
- * @since 1.5
- */
- public boolean isBridge()
- {
- return (getModifiersInternal() & Modifier.BRIDGE) != 0;
- }
-
- /**
- * Return true if this method is synthetic, false otherwise.
- * @since 1.5
- */
- public boolean isSynthetic()
- {
- return (getModifiersInternal() & Modifier.SYNTHETIC) != 0;
- }
-
- /**
- * Return true if this is a varargs method, that is if
- * the method takes a variable number of arguments.
- * @since 1.5
- */
- public boolean isVarArgs()
- {
- return (getModifiersInternal() & Modifier.VARARGS) != 0;
- }
-
- /**
- * Gets the return type of this method.
- * @return the type of this method
- */
- public native Class<?> getReturnType();
-
- /**
- * Get the parameter list for this method, in declaration order. If the
- * method takes no parameters, returns a 0-length array (not null).
- *
- * @return a list of the types of the method's parameters
- */
- public native Class<?>[] getParameterTypes();
-
- /**
- * Get the exception types this method says it throws, in no particular
- * order. If the method has no throws clause, returns a 0-length array
- * (not null).
- *
- * @return a list of the types in the method's throws clause
- */
- public native Class<?>[] getExceptionTypes();
-
- /**
- * Compare two objects to see if they are semantically equivalent.
- * Two Methods are semantically equivalent if they have the same declaring
- * class, name, parameter list, and return type.
- *
- * @param o the object to compare to
- * @return <code>true</code> if they are equal; <code>false</code> if not
- */
- public boolean equals(Object o)
- {
- // Implementation note:
- // The following is a correct but possibly slow implementation.
- //
- // This class has a private field 'slot' that could be used by
- // the VM implementation to "link" a particular method to a Class.
- // In that case equals could be simply implemented as:
- //
- // if (o instanceof Method)
- // {
- // Method m = (Method)o;
- // return m.clazz == this.clazz
- // && m.slot == this.slot;
- // }
- // return false;
- //
- // If a VM uses the Method class as their native/internal representation
- // then just using the following would be optimal:
- //
- // return this == o;
- //
- if (!(o instanceof Method))
- return false;
- Method that = (Method)o;
- if (this.getDeclaringClass() != that.getDeclaringClass())
- return false;
- if (!this.getName().equals(that.getName()))
- return false;
- if (this.getReturnType() != that.getReturnType())
- return false;
- if (!Arrays.equals(this.getParameterTypes(), that.getParameterTypes()))
- return false;
- return true;
- }
-
- /**
- * Get the hash code for the Method. The Method hash code is the hash code
- * of its name XOR'd with the hash code of its class name.
- *
- * @return the hash code for the object
- */
- public int hashCode()
- {
- return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
- }
-
- /**
- * Get a String representation of the Method. A Method's String
- * representation is "<modifiers> <returntype>
- * <methodname>(<paramtypes>) throws <exceptions>", where
- * everything after ')' is omitted if there are no exceptions.<br> Example:
- * <code>public static int run(java.lang.Runnable,int)</code>
- *
- * @return the String representation of the Method
- */
- public String toString()
- {
- // 128 is a reasonable buffer initial size for constructor
- StringBuilder sb = new StringBuilder(128);
- Modifier.toString(getModifiers(), sb).append(' ');
- sb.append(ClassHelper.getUserName(getReturnType())).append(' ');
- sb.append(getDeclaringClass().getName()).append('.');
- sb.append(getName()).append('(');
- Class[] c = getParameterTypes();
- if (c.length > 0)
- {
- sb.append(ClassHelper.getUserName(c[0]));
- for (int i = 1; i < c.length; i++)
- sb.append(',').append(ClassHelper.getUserName(c[i]));
- }
- sb.append(')');
- c = getExceptionTypes();
- if (c.length > 0)
- {
- sb.append(" throws ").append(c[0].getName());
- for (int i = 1; i < c.length; i++)
- sb.append(',').append(c[i].getName());
- }
- return sb.toString();
- }
-
- public String toGenericString()
- {
- // 128 is a reasonable buffer initial size for constructor
- StringBuilder sb = new StringBuilder(128);
- Modifier.toString(getModifiers(), sb).append(' ');
- Constructor.addTypeParameters(sb, getTypeParameters());
- sb.append(getGenericReturnType()).append(' ');
- sb.append(getDeclaringClass().getName()).append('.');
- sb.append(getName()).append('(');
- Type[] types = getGenericParameterTypes();
- if (types.length > 0)
- {
- sb.append(types[0]);
- for (int i = 1; i < types.length; i++)
- sb.append(',').append(types[i]);
- }
- sb.append(')');
- types = getGenericExceptionTypes();
- if (types.length > 0)
- {
- sb.append(" throws ").append(types[0]);
- for (int i = 1; i < types.length; i++)
- sb.append(',').append(types[i]);
- }
- return sb.toString();
- }
-
- /**
- * Invoke the method. Arguments are automatically unwrapped and widened,
- * and the result is automatically wrapped, if needed.<p>
- *
- * If the method is static, <code>o</code> will be ignored. Otherwise,
- * the method uses dynamic lookup as described in JLS 15.12.4.4. You cannot
- * mimic the behavior of nonvirtual lookup (as in super.foo()). This means
- * you will get a <code>NullPointerException</code> if <code>o</code> is
- * null, and an <code>IllegalArgumentException</code> if it is incompatible
- * with the declaring class of the method. If the method takes 0 arguments,
- * you may use null or a 0-length array for <code>args</code>.<p>
- *
- * Next, if this Method enforces access control, your runtime context is
- * evaluated, and you may have an <code>IllegalAccessException</code> if
- * you could not acces this method in similar compiled code. If the method
- * is static, and its class is uninitialized, you trigger class
- * initialization, which may end in a
- * <code>ExceptionInInitializerError</code>.<p>
- *
- * Finally, the method is invoked. If it completes normally, the return value
- * will be null for a void method, a wrapped object for a primitive return
- * method, or the actual return of an Object method. If it completes
- * abruptly, the exception is wrapped in an
- * <code>InvocationTargetException</code>.
- *
- * @param o the object to invoke the method on
- * @param args the arguments to the method
- * @return the return value of the method, wrapped in the appropriate
- * wrapper if it is primitive
- * @throws IllegalAccessException if the method could not normally be called
- * by the Java code (i.e. it is not public)
- * @throws IllegalArgumentException if the number of arguments is incorrect;
- * if the arguments types are wrong even with a widening conversion;
- * or if <code>o</code> is not an instance of the class or interface
- * declaring this method
- * @throws InvocationTargetException if the method throws an exception
- * @throws NullPointerException if <code>o</code> is null and this field
- * requires an instance
- * @throws ExceptionInInitializerError if accessing a static method triggered
- * class initialization, which then failed
- */
- public Object invoke(Object o, Object... args)
- throws IllegalAccessException, InvocationTargetException
- {
- return invokeNative(o, args, clazz, slot);
- }
-
- /*
- * NATIVE HELPERS
- */
-
- private native Object invokeNative(Object o, Object[] args,
- Class declaringClass, int slot)
- throws IllegalAccessException, InvocationTargetException;
-
- /**
- * Returns an array of <code>TypeVariable</code> objects that represents
- * the type variables declared by this constructor, in declaration order.
- * An array of size zero is returned if this class has no type
- * variables.
- *
- * @return the type variables associated with this class.
- * @throws GenericSignatureFormatError if the generic signature does
- * not conform to the format specified in the Virtual Machine
- * specification, version 3.
- * @since 1.5
- */
- public TypeVariable<Method>[] getTypeParameters()
- {
- String sig = getSignature();
- if (sig == null)
- return new TypeVariable[0];
- MethodSignatureParser p = new MethodSignatureParser(this, sig);
- return p.getTypeParameters();
- }
-
- /**
- * Return the String in the Signature attribute for this method. If there
- * is no Signature attribute, return null.
- */
- private native String getSignature();
-
- /**
- * Returns an array of <code>Type</code> objects that represents
- * the exception types declared by this method, in declaration order.
- * An array of size zero is returned if this method declares no
- * exceptions.
- *
- * @return the exception types declared by this method.
- * @throws GenericSignatureFormatError if the generic signature does
- * not conform to the format specified in the Virtual Machine
- * specification, version 3.
- * @since 1.5
- */
- public Type[] getGenericExceptionTypes()
- {
- String sig = getSignature();
- if (sig == null)
- return getExceptionTypes();
- MethodSignatureParser p = new MethodSignatureParser(this, sig);
- return p.getGenericExceptionTypes();
- }
-
- /**
- * Returns an array of <code>Type</code> objects that represents
- * the parameter list for this method, in declaration order.
- * An array of size zero is returned if this method takes no
- * parameters.
- *
- * @return a list of the types of the method's parameters
- * @throws GenericSignatureFormatError if the generic signature does
- * not conform to the format specified in the Virtual Machine
- * specification, version 3.
- * @since 1.5
- */
- public Type[] getGenericParameterTypes()
- {
- String sig = getSignature();
- if (sig == null)
- return getParameterTypes();
- MethodSignatureParser p = new MethodSignatureParser(this, sig);
- return p.getGenericParameterTypes();
- }
-
- /**
- * Returns the return type of this method.
- *
- * @return the return type of this method
- * @throws GenericSignatureFormatError if the generic signature does
- * not conform to the format specified in the Virtual Machine
- * specification, version 3.
- * @since 1.5
- */
- public Type getGenericReturnType()
- {
- String sig = getSignature();
- if (sig == null)
- return getReturnType();
- MethodSignatureParser p = new MethodSignatureParser(this, sig);
- return p.getGenericReturnType();
- }
-
- /**
- * If this method is an annotation method, returns the default
- * value for the method. If there is no default value, or if the
- * method is not a member of an annotation type, returns null.
- * Primitive types are wrapped.
- *
- * @throws TypeNotPresentException if the method returns a Class,
- * and the class cannot be found
- *
- * @since 1.5
- */
- public native Object getDefaultValue();
-
- /**
- * @throws NullPointerException {@inheritDoc}
- * @since 1.5
- */
- public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
- if (annotationClass == null)
- throw new NullPointerException();
-
- return (T)declaredAnnotations().get(annotationClass);
- }
-
- /**
- * @since 1.5
- */
- public Annotation[] getDeclaredAnnotations() {
- return declaredAnnotations().values().toArray(EMPTY_ANNOTATIONS_ARRAY);
- }
-
- /**
- * Parses the annotations if they aren't parsed yet and stores them into
- * the declaredAnnotations map and return this map.
- */
- private synchronized native Map<Class<? extends Annotation>, Annotation> declaredAnnotations();
-
- /**
- * Returns an array of arrays that represent the annotations on the formal
- * parameters, in declaration order, of the method represented by
- * this <tt>Method</tt> object. (Returns an array of length zero if the
- * underlying method is parameterless. If the method has one or more
- * parameters, a nested array of length zero is returned for each parameter
- * with no annotations.) The annotation objects contained in the returned
- * arrays are serializable. The caller of this method is free to modify
- * the returned arrays; it will have no effect on the arrays returned to
- * other callers.
- *
- * @return an array of arrays that represent the annotations on the formal
- * parameters, in declaration order, of the method represented by this
- * Method object
- * @since 1.5
- */
- public native Annotation[][] getParameterAnnotations();
-}
+++ /dev/null
-/* VMAccessController.java -- VM-specific access controller methods.
- Copyright (C) 2004, 2005 Free Software Foundation, Inc.
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.security;
-
-import java.util.HashSet;
-import java.util.LinkedList;
-
-final class VMAccessController
-{
-
- // Fields.
- // -------------------------------------------------------------------------
-
- /**
- * This is a per-thread stack of AccessControlContext objects (which can
- * be null) for each call to AccessController.doPrivileged in each thread's
- * call stack. We use this to remember which context object corresponds to
- * which call.
- */
- private static final ThreadLocal contexts = new ThreadLocal();
-
- /**
- * This is a Boolean that, if set, tells getContext that it has already
- * been called once, allowing us to handle recursive permission checks
- * caused by methods getContext calls.
- */
- private static final ThreadLocal inGetContext = new ThreadLocal();
-
- /**
- * And we return this all-permissive context to ensure that privileged
- * methods called from getContext succeed.
- */
- private static final AccessControlContext DEFAULT_CONTEXT;
- static
- {
- CodeSource source = new CodeSource(null, null);
- Permissions permissions = new Permissions();
- permissions.add(new AllPermission());
- ProtectionDomain[] domain = new ProtectionDomain[] {
- new ProtectionDomain(source, permissions)
- };
- DEFAULT_CONTEXT = new AccessControlContext(domain);
- }
-
- private static final boolean DEBUG = gnu.classpath.Configuration.DEBUG;
- private static void debug(String msg)
- {
- System.err.print(">>> VMAccessController: ");
- System.err.println(msg);
- }
-
- // Constructors.
- // -------------------------------------------------------------------------
-
- private VMAccessController() { }
-
- // Class methods.
- // -------------------------------------------------------------------------
-
- /**
- * Relate a class (which should be an instance of {@link PrivilegedAction}
- * with an access control context. This method is used by {@link
- * AccessController#doPrivileged(java.security.PrivilegedAction,java.security.AccessControlContext)}
- * to set up the context that will be returned by {@link #getContext()}.
- * This method relates the class to the current thread, so contexts
- * pushed from one thread will not be available to another.
- *
- * @param acc The access control context.
- */
- static void pushContext (AccessControlContext acc)
- {
- if (DEBUG)
- debug("pushing " + acc);
- LinkedList stack = (LinkedList) contexts.get();
- if (stack == null)
- {
- if (DEBUG)
- debug("no stack... creating ");
- stack = new LinkedList();
- contexts.set(stack);
- }
- stack.addFirst(acc);
- }
-
- /**
- * Removes the relation of a class to an {@link AccessControlContext}.
- * This method is used by {@link AccessController} when exiting from a
- * call to {@link
- * AccessController#doPrivileged(java.security.PrivilegedAction,java.security.AccessControlContext)}.
- */
- static void popContext()
- {
- if (DEBUG)
- debug("popping context");
-
- // Stack should never be null, nor should it be empty, if this method
- // and its counterpart has been called properly.
- LinkedList stack = (LinkedList) contexts.get();
- if (stack != null)
- {
- stack.removeFirst();
- if (stack.isEmpty())
- contexts.set(null);
- }
- else if (DEBUG)
- {
- debug("no stack during pop?????");
- }
- }
-
- /**
- * Examine the method stack of the currently running thread, and create
- * an {@link AccessControlContext} filled in with the appropriate {@link
- * ProtectionDomain} objects given this stack.
- *
- * @return The context.
- */
- static AccessControlContext getContext()
- {
- // If we are already in getContext, but called a method that needs
- // a permission check, return the all-permissive context so methods
- // called from here succeed.
- //
- // XXX is this necessary? We should verify if there are any calls in
- // the stack below this method that require permission checks.
- Boolean inCall = (Boolean) inGetContext.get();
- if (inCall != null && inCall.booleanValue())
- {
- if (DEBUG)
- debug("already in getContext");
- return DEFAULT_CONTEXT;
- }
-
- inGetContext.set(Boolean.TRUE);
-
- Object[][] stack = getStack();
- Class[] classes = (Class[]) stack[0];
- String[] methods = (String[]) stack[1];
-
- if (DEBUG)
- debug("got trace of length " + classes.length);
-
- HashSet domains = new HashSet();
- HashSet seenDomains = new HashSet();
- AccessControlContext context = null;
- int privileged = 0;
-
- // We walk down the stack, adding each ProtectionDomain for each
- // class in the call stack. If we reach a call to doPrivileged,
- // we don't add any more stack frames. We skip the first three stack
- // frames, since they comprise the calls to getStack, getContext,
- // and AccessController.getContext.
- for (int i = 3; i < classes.length && privileged < 2; i++)
- {
- Class clazz = classes[i];
- String method = methods[i];
-
- if (DEBUG)
- {
- debug("checking " + clazz + "." + method);
- // subject to getClassLoader RuntimePermission
- debug("loader = " + clazz.getClassLoader());
- }
-
- // If the previous frame was a call to doPrivileged, then this is
- // the last frame we look at.
- if (privileged == 1)
- privileged = 2;
-
- if (clazz.equals (AccessController.class)
- && method.equals ("doPrivileged"))
- {
- // If there was a call to doPrivileged with a supplied context,
- // return that context. If using JAAS doAs*, it should be
- // a context with a SubjectDomainCombiner
- LinkedList l = (LinkedList) contexts.get();
- if (l != null)
- context = (AccessControlContext) l.getFirst();
- privileged = 1;
- }
-
- // subject to getProtectionDomain RuntimePermission
- ProtectionDomain domain = clazz.getProtectionDomain();
-
- if (domain == null)
- continue;
- if (seenDomains.contains(domain))
- continue;
- seenDomains.add(domain);
-
- // Create a static snapshot of this domain, which may change over time
- // if the current policy changes.
- domains.add(new ProtectionDomain(domain.getCodeSource(),
- domain.getPermissions()));
- }
-
- if (DEBUG)
- debug("created domains: " + domains);
-
- ProtectionDomain[] result = (ProtectionDomain[])
- domains.toArray(new ProtectionDomain[domains.size()]);
-
- if (context != null)
- {
- DomainCombiner dc = context.getDomainCombiner ();
- // If the supplied context had no explicit DomainCombiner, use
- // our private version, which computes the intersection of the
- // context's domains with the derived set.
- if (dc == null)
- context = new AccessControlContext
- (IntersectingDomainCombiner.SINGLETON.combine
- (result, context.getProtectionDomains ()));
- // Use the supplied DomainCombiner. This should be secure,
- // because only trusted code may create an
- // AccessControlContext with a custom DomainCombiner.
- else
- context = new AccessControlContext (result, context, dc);
- }
- // No context was supplied. Return the derived one.
- else
- context = new AccessControlContext (result);
-
- inGetContext.set(Boolean.FALSE);
- return context;
- }
-
- /**
- * Returns a snapshot of the current call stack as a pair of arrays:
- * the first an array of classes in the call stack, the second an array
- * of strings containing the method names in the call stack. The two
- * arrays match up, meaning that method <i>i</i> is declared in class
- * <i>i</i>. The arrays are clean; it will only contain Java methods,
- * and no element of the list should be null.
- *
- * <p>The default implementation returns an empty stack, which will be
- * interpreted as having no permissions whatsoever.
- *
- * @return A pair of arrays describing the current call stack. The first
- * element is an array of Class objects, and the second is an array
- * of Strings comprising the method names.
- */
-// private static Object[][] getStack()
-// {
-// return new Object[][] { new Class[0], new String[0] };
-// }
- private native static Object[][] getStack();
-}
+++ /dev/null
-/*
- * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-package sun.misc;
-
-import java.security.*;
-import java.lang.reflect.*;
-
-
-/**
- * A collection of methods for performing low-level, unsafe operations.
- * Although the class and all methods are public, use of this class is
- * limited because only trusted code can obtain instances of it.
- *
- * @author John R. Rose
- * @version 1.28, 07/06/04
- * @see #getUnsafe
- */
-
-public final class Unsafe {
-
- private static native void registerNatives();
- static {
- registerNatives();
-// sun.reflect.Reflection.registerMethodsToFilter(Unsafe.class, "getUnsafe");
- }
-
- private Unsafe() {}
-
- private static final Unsafe theUnsafe = new Unsafe();
-
- /**
- * Provides the caller with the capability of performing unsafe
- * operations.
- *
- * <p> The returned <code>Unsafe</code> object should be carefully guarded
- * by the caller, since it can be used to read and write data at arbitrary
- * memory addresses. It must never be passed to untrusted code.
- *
- * <p> Most methods in this class are very low-level, and correspond to a
- * small number of hardware instructions (on typical machines). Compilers
- * are encouraged to optimize these methods accordingly.
- *
- * <p> Here is a suggested idiom for using unsafe operations:
- *
- * <blockquote><pre>
- * class MyTrustedClass {
- * private static final Unsafe unsafe = Unsafe.getUnsafe();
- * ...
- * private long myCountAddress = ...;
- * public int getCount() { return unsafe.getByte(myCountAddress); }
- * }
- * </pre></blockquote>
- *
- * (It may assist compilers to make the local variable be
- * <code>final</code>.)
- *
- * @exception SecurityException if a security manager exists and its
- * <code>checkPropertiesAccess</code> method doesn't allow
- * access to the system properties.
- */
- public static Unsafe getUnsafe() {
- Class cc = sun.reflect.Reflection.getCallerClass(2);
- if (cc.getClassLoader() != null)
- throw new SecurityException("Unsafe");
- return theUnsafe;
- }
-
- /// peek and poke operations
- /// (compilers should optimize these to memory ops)
-
- // These work on object fields in the Java heap.
- // They will not work on elements of packed arrays.
-
- /**
- * Fetches a value from a given Java variable.
- * More specifically, fetches a field or array element within the given
- * object <code>o</code> at the given offset, or (if <code>o</code> is
- * null) from the memory address whose numerical value is the given
- * offset.
- * <p>
- * The results are undefined unless one of the following cases is true:
- * <ul>
- * <li>The offset was obtained from {@link #objectFieldOffset} on
- * the {@link java.lang.reflect.Field} of some Java field and the object
- * referred to by <code>o</code> is of a class compatible with that
- * field's class.
- *
- * <li>The offset and object reference <code>o</code> (either null or
- * non-null) were both obtained via {@link #staticFieldOffset}
- * and {@link #staticFieldBase} (respectively) from the
- * reflective {@link Field} representation of some Java field.
- *
- * <li>The object referred to by <code>o</code> is an array, and the offset
- * is an integer of the form <code>B+N*S</code>, where <code>N</code> is
- * a valid index into the array, and <code>B</code> and <code>S</code> are
- * the values obtained by {@link #arrayBaseOffset} and {@link
- * #arrayIndexScale} (respectively) from the array's class. The value
- * referred to is the <code>N</code><em>th</em> element of the array.
- *
- * </ul>
- * <p>
- * If one of the above cases is true, the call references a specific Java
- * variable (field or array element). However, the results are undefined
- * if that variable is not in fact of the type returned by this method.
- * <p>
- * This method refers to a variable by means of two parameters, and so
- * it provides (in effect) a <em>double-register</em> addressing mode
- * for Java variables. When the object reference is null, this method
- * uses its offset as an absolute address. This is similar in operation
- * to methods such as {@link #getInt(long)}, which provide (in effect) a
- * <em>single-register</em> addressing mode for non-Java variables.
- * However, because Java variables may have a different layout in memory
- * from non-Java variables, programmers should not assume that these
- * two addressing modes are ever equivalent. Also, programmers should
- * remember that offsets from the double-register addressing mode cannot
- * be portably confused with longs used in the single-register addressing
- * mode.
- *
- * @param o Java heap object in which the variable resides, if any, else
- * null
- * @param offset indication of where the variable resides in a Java heap
- * object, if any, else a memory address locating the variable
- * statically
- * @return the value fetched from the indicated Java variable
- * @throws RuntimeException No defined exceptions are thrown, not even
- * {@link NullPointerException}
- */
- public native int getInt(Object o, long offset);
-
- /**
- * Stores a value into a given Java variable.
- * <p>
- * The first two parameters are interpreted exactly as with
- * {@link #getInt(Object, long)} to refer to a specific
- * Java variable (field or array element). The given value
- * is stored into that variable.
- * <p>
- * The variable must be of the same type as the method
- * parameter <code>x</code>.
- *
- * @param o Java heap object in which the variable resides, if any, else
- * null
- * @param offset indication of where the variable resides in a Java heap
- * object, if any, else a memory address locating the variable
- * statically
- * @param x the value to store into the indicated Java variable
- * @throws RuntimeException No defined exceptions are thrown, not even
- * {@link NullPointerException}
- */
- public native void putInt(Object o, long offset, int x);
-
- /**
- * Fetches a reference value from a given Java variable.
- * @see #getInt(Object, long)
- */
- public native Object getObject(Object o, long offset);
-
- /**
- * Stores a reference value into a given Java variable.
- * <p>
- * Unless the reference <code>x</code> being stored is either null
- * or matches the field type, the results are undefined.
- * If the reference <code>o</code> is non-null, car marks or
- * other store barriers for that object (if the VM requires them)
- * are updated.
- * @see #putInt(Object, int, int)
- */
- public native void putObject(Object o, long offset, Object x);
-
- /** @see #getInt(Object, long) */
- public native boolean getBoolean(Object o, long offset);
- /** @see #putInt(Object, int, int) */
- public native void putBoolean(Object o, long offset, boolean x);
- /** @see #getInt(Object, long) */
- public native byte getByte(Object o, long offset);
- /** @see #putInt(Object, int, int) */
- public native void putByte(Object o, long offset, byte x);
- /** @see #getInt(Object, long) */
- public native short getShort(Object o, long offset);
- /** @see #putInt(Object, int, int) */
- public native void putShort(Object o, long offset, short x);
- /** @see #getInt(Object, long) */
- public native char getChar(Object o, long offset);
- /** @see #putInt(Object, int, int) */
- public native void putChar(Object o, long offset, char x);
- /** @see #getInt(Object, long) */
- public native long getLong(Object o, long offset);
- /** @see #putInt(Object, int, int) */
- public native void putLong(Object o, long offset, long x);
- /** @see #getInt(Object, long) */
- public native float getFloat(Object o, long offset);
- /** @see #putInt(Object, int, int) */
- public native void putFloat(Object o, long offset, float x);
- /** @see #getInt(Object, long) */
- public native double getDouble(Object o, long offset);
- /** @see #putInt(Object, int, int) */
- public native void putDouble(Object o, long offset, double x);
-
- /**
- * This method, like all others with 32-bit offsets, was native
- * in a previous release but is now a wrapper which simply casts
- * the offset to a long value. It provides backward compatibility
- * with bytecodes compiled against 1.4.
- * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
- * See {@link #staticFieldOffset}.
- */
- @Deprecated
- public int getInt(Object o, int offset) {
- return getInt(o, (long)offset);
- }
-
- /**
- * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
- * See {@link #staticFieldOffset}.
- */
- @Deprecated
- public void putInt(Object o, int offset, int x) {
- putInt(o, (long)offset, x);
- }
-
- /**
- * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
- * See {@link #staticFieldOffset}.
- */
- @Deprecated
- public Object getObject(Object o, int offset) {
- return getObject(o, (long)offset);
- }
-
- /**
- * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
- * See {@link #staticFieldOffset}.
- */
- @Deprecated
- public void putObject(Object o, int offset, Object x) {
- putObject(o, (long)offset, x);
- }
-
- /**
- * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
- * See {@link #staticFieldOffset}.
- */
- @Deprecated
- public boolean getBoolean(Object o, int offset) {
- return getBoolean(o, (long)offset);
- }
-
- /**
- * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
- * See {@link #staticFieldOffset}.
- */
- @Deprecated
- public void putBoolean(Object o, int offset, boolean x) {
- putBoolean(o, (long)offset, x);
- }
-
- /**
- * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
- * See {@link #staticFieldOffset}.
- */
- @Deprecated
- public byte getByte(Object o, int offset) {
- return getByte(o, (long)offset);
- }
-
- /**
- * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
- * See {@link #staticFieldOffset}.
- */
- @Deprecated
- public void putByte(Object o, int offset, byte x) {
- putByte(o, (long)offset, x);
- }
-
- /**
- * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
- * See {@link #staticFieldOffset}.
- */
- @Deprecated
- public short getShort(Object o, int offset) {
- return getShort(o, (long)offset);
- }
-
- /**
- * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
- * See {@link #staticFieldOffset}.
- */
- @Deprecated
- public void putShort(Object o, int offset, short x) {
- putShort(o, (long)offset, x);
- }
-
- /**
- * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
- * See {@link #staticFieldOffset}.
- */
- @Deprecated
- public char getChar(Object o, int offset) {
- return getChar(o, (long)offset);
- }
-
- /**
- * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
- * See {@link #staticFieldOffset}.
- */
- @Deprecated
- public void putChar(Object o, int offset, char x) {
- putChar(o, (long)offset, x);
- }
-
- /**
- * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
- * See {@link #staticFieldOffset}.
- */
- @Deprecated
- public long getLong(Object o, int offset) {
- return getLong(o, (long)offset);
- }
-
- /**
- * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
- * See {@link #staticFieldOffset}.
- */
- @Deprecated
- public void putLong(Object o, int offset, long x) {
- putLong(o, (long)offset, x);
- }
-
- /**
- * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
- * See {@link #staticFieldOffset}.
- */
- @Deprecated
- public float getFloat(Object o, int offset) {
- return getFloat(o, (long)offset);
- }
-
- /**
- * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
- * See {@link #staticFieldOffset}.
- */
- @Deprecated
- public void putFloat(Object o, int offset, float x) {
- putFloat(o, (long)offset, x);
- }
-
- /**
- * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
- * See {@link #staticFieldOffset}.
- */
- @Deprecated
- public double getDouble(Object o, int offset) {
- return getDouble(o, (long)offset);
- }
-
- /**
- * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long.
- * See {@link #staticFieldOffset}.
- */
- @Deprecated
- public void putDouble(Object o, int offset, double x) {
- putDouble(o, (long)offset, x);
- }
-
- // These work on values in the C heap.
-
- /**
- * Fetches a value from a given memory address. If the address is zero, or
- * does not point into a block obtained from {@link #allocateMemory}, the
- * results are undefined.
- *
- * @see #allocateMemory
- */
- public native byte getByte(long address);
-
- /**
- * Stores a value into a given memory address. If the address is zero, or
- * does not point into a block obtained from {@link #allocateMemory}, the
- * results are undefined.
- *
- * @see #getByte(long)
- */
- public native void putByte(long address, byte x);
-
- /** @see #getByte(long) */
- public native short getShort(long address);
- /** @see #putByte(long, byte) */
- public native void putShort(long address, short x);
- /** @see #getByte(long) */
- public native char getChar(long address);
- /** @see #putByte(long, byte) */
- public native void putChar(long address, char x);
- /** @see #getByte(long) */
- public native int getInt(long address);
- /** @see #putByte(long, byte) */
- public native void putInt(long address, int x);
- /** @see #getByte(long) */
- public native long getLong(long address);
- /** @see #putByte(long, byte) */
- public native void putLong(long address, long x);
- /** @see #getByte(long) */
- public native float getFloat(long address);
- /** @see #putByte(long, byte) */
- public native void putFloat(long address, float x);
- /** @see #getByte(long) */
- public native double getDouble(long address);
- /** @see #putByte(long, byte) */
- public native void putDouble(long address, double x);
-
- /**
- * Fetches a native pointer from a given memory address. If the address is
- * zero, or does not point into a block obtained from {@link
- * #allocateMemory}, the results are undefined.
- *
- * <p> If the native pointer is less than 64 bits wide, it is extended as
- * an unsigned number to a Java long. The pointer may be indexed by any
- * given byte offset, simply by adding that offset (as a simple integer) to
- * the long representing the pointer. The number of bytes actually read
- * from the target address maybe determined by consulting {@link
- * #addressSize}.
- *
- * @see #allocateMemory
- */
- public native long getAddress(long address);
-
- /**
- * Stores a native pointer into a given memory address. If the address is
- * zero, or does not point into a block obtained from {@link
- * #allocateMemory}, the results are undefined.
- *
- * <p> The number of bytes actually written at the target address maybe
- * determined by consulting {@link #addressSize}.
- *
- * @see #getAddress(long)
- */
- public native void putAddress(long address, long x);
-
- /// wrappers for malloc, realloc, free:
-
- /**
- * Allocates a new block of native memory, of the given size in bytes. The
- * contents of the memory are uninitialized; they will generally be
- * garbage. The resulting native pointer will never be zero, and will be
- * aligned for all value types. Dispose of this memory by calling {@link
- * #freeMemory}, or resize it with {@link #reallocateMemory}.
- *
- * @throws IllegalArgumentException if the size is negative or too large
- * for the native size_t type
- *
- * @throws OutOfMemoryError if the allocation is refused by the system
- *
- * @see #getByte(long)
- * @see #putByte(long, byte)
- */
- public native long allocateMemory(long bytes);
-
- /**
- * Resizes a new block of native memory, to the given size in bytes. The
- * contents of the new block past the size of the old block are
- * uninitialized; they will generally be garbage. The resulting native
- * pointer will be zero if and only if the requested size is zero. The
- * resulting native pointer will be aligned for all value types. Dispose
- * of this memory by calling {@link #freeMemory}, or resize it with {@link
- * #reallocateMemory}. The address passed to this method may be null, in
- * which case an allocation will be performed.
- *
- * @throws IllegalArgumentException if the size is negative or too large
- * for the native size_t type
- *
- * @throws OutOfMemoryError if the allocation is refused by the system
- *
- * @see #allocateMemory
- */
- public native long reallocateMemory(long address, long bytes);
-
- /**
- * Sets all bytes in a given block of memory to a fixed value
- * (usually zero).
- *
- * <p>This method determines a block's base address by means of two parameters,
- * and so it provides (in effect) a <em>double-register</em> addressing mode,
- * as discussed in {@link #getInt(Object,long)}. When the object reference is null,
- * the offset supplies an absolute base address.
- *
- * <p>The stores are in coherent (atomic) units of a size determined
- * by the address and length parameters. If the effective address and
- * length are all even modulo 8, the stores take place in 'long' units.
- * If the effective address and length are (resp.) even modulo 4 or 2,
- * the stores take place in units of 'int' or 'short'.
- *
- * @since 1.7
- */
- public native void setMemory(Object o, long offset, long bytes, byte value);
-
- /**
- * Sets all bytes in a given block of memory to a fixed value
- * (usually zero). This provides a <em>single-register</em> addressing mode,
- * as discussed in {@link #getInt(Object,long)}.
- *
- * <p>Equivalent to <code>setMemory(null, address, bytes, value)</code>.
- */
- public void setMemory(long address, long bytes, byte value) {
- setMemory(null, address, bytes, value);
- }
-
- /**
- * Sets all bytes in a given block of memory to a copy of another
- * block.
- *
- * <p>This method determines each block's base address by means of two parameters,
- * and so it provides (in effect) a <em>double-register</em> addressing mode,
- * as discussed in {@link #getInt(Object,long)}. When the object reference is null,
- * the offset supplies an absolute base address.
- *
- * <p>The transfers are in coherent (atomic) units of a size determined
- * by the address and length parameters. If the effective addresses and
- * length are all even modulo 8, the transfer takes place in 'long' units.
- * If the effective addresses and length are (resp.) even modulo 4 or 2,
- * the transfer takes place in units of 'int' or 'short'.
- *
- * @since 1.7
- */
- public native void copyMemory(Object srcBase, long srcOffset,
- Object destBase, long destOffset,
- long bytes);
- /**
- * Sets all bytes in a given block of memory to a copy of another
- * block. This provides a <em>single-register</em> addressing mode,
- * as discussed in {@link #getInt(Object,long)}.
- *
- * Equivalent to <code>copyMemory(null, srcAddress, null, destAddress, bytes)</code>.
- */
- public void copyMemory(long srcAddress, long destAddress, long bytes) {
- copyMemory(null, srcAddress, null, destAddress, bytes);
- }
-
- /**
- * Disposes of a block of native memory, as obtained from {@link
- * #allocateMemory} or {@link #reallocateMemory}. The address passed to
- * this method may be null, in which case no action is taken.
- *
- * @see #allocateMemory
- */
- public native void freeMemory(long address);
-
- /// random queries
-
- /**
- * This constant differs from all results that will ever be returned from
- * {@link #staticFieldOffset}, {@link #objectFieldOffset},
- * or {@link #arrayBaseOffset}.
- */
- public static final int INVALID_FIELD_OFFSET = -1;
-
- /**
- * Returns the offset of a field, truncated to 32 bits.
- * This method is implemented as follows:
- * <blockquote><pre>
- * public int fieldOffset(Field f) {
- * if (Modifier.isStatic(f.getModifiers()))
- * return (int) staticFieldOffset(f);
- * else
- * return (int) objectFieldOffset(f);
- * }
- * </pre></blockquote>
- * @deprecated As of 1.4.1, use {@link #staticFieldOffset} for static
- * fields and {@link #objectFieldOffset} for non-static fields.
- */
- @Deprecated
- public int fieldOffset(Field f) {
- if (Modifier.isStatic(f.getModifiers()))
- return (int) staticFieldOffset(f);
- else
- return (int) objectFieldOffset(f);
- }
-
- /**
- * Returns the base address for accessing some static field
- * in the given class. This method is implemented as follows:
- * <blockquote><pre>
- * public Object staticFieldBase(Class c) {
- * Field[] fields = c.getDeclaredFields();
- * for (int i = 0; i < fields.length; i++) {
- * if (Modifier.isStatic(fields[i].getModifiers())) {
- * return staticFieldBase(fields[i]);
- * }
- * }
- * return null;
- * }
- * </pre></blockquote>
- * @deprecated As of 1.4.1, use {@link #staticFieldBase(Field)}
- * to obtain the base pertaining to a specific {@link Field}.
- * This method works only for JVMs which store all statics
- * for a given class in one place.
- */
- @Deprecated
- public Object staticFieldBase(Class c) {
- Field[] fields = c.getDeclaredFields();
- for (int i = 0; i < fields.length; i++) {
- if (Modifier.isStatic(fields[i].getModifiers())) {
- return staticFieldBase(fields[i]);
- }
- }
- return null;
- }
-
- /**
- * Report the location of a given field in the storage allocation of its
- * class. Do not expect to perform any sort of arithmetic on this offset;
- * it is just a cookie which is passed to the unsafe heap memory accessors.
- *
- * <p>Any given field will always have the same offset and base, and no
- * two distinct fields of the same class will ever have the same offset
- * and base.
- *
- * <p>As of 1.4.1, offsets for fields are represented as long values,
- * although the Sun JVM does not use the most significant 32 bits.
- * However, JVM implementations which store static fields at absolute
- * addresses can use long offsets and null base pointers to express
- * the field locations in a form usable by {@link #getInt(Object,long)}.
- * Therefore, code which will be ported to such JVMs on 64-bit platforms
- * must preserve all bits of static field offsets.
- * @see #getInt(Object, long)
- */
- public native long staticFieldOffset(Field f);
-
- /**
- * Report the location of a given static field, in conjunction with {@link
- * #staticFieldBase}.
- * <p>Do not expect to perform any sort of arithmetic on this offset;
- * it is just a cookie which is passed to the unsafe heap memory accessors.
- *
- * <p>Any given field will always have the same offset, and no two distinct
- * fields of the same class will ever have the same offset.
- *
- * <p>As of 1.4.1, offsets for fields are represented as long values,
- * although the Sun JVM does not use the most significant 32 bits.
- * It is hard to imagine a JVM technology which needs more than
- * a few bits to encode an offset within a non-array object,
- * However, for consistency with other methods in this class,
- * this method reports its result as a long value.
- * @see #getInt(Object, long)
- */
- public native long objectFieldOffset(Field f);
-
- /**
- * Report the location of a given static field, in conjunction with {@link
- * #staticFieldOffset}.
- * <p>Fetch the base "Object", if any, with which static fields of the
- * given class can be accessed via methods like {@link #getInt(Object,
- * long)}. This value may be null. This value may refer to an object
- * which is a "cookie", not guaranteed to be a real Object, and it should
- * not be used in any way except as argument to the get and put routines in
- * this class.
- */
- public native Object staticFieldBase(Field f);
-
- /**
- * Ensure the given class has been initialized. This is often
- * needed in conjunction with obtaining the static field base of a
- * class.
- */
- public native void ensureClassInitialized(Class c);
-
- /**
- * Report the offset of the first element in the storage allocation of a
- * given array class. If {@link #arrayIndexScale} returns a non-zero value
- * for the same class, you may use that scale factor, together with this
- * base offset, to form new offsets to access elements of arrays of the
- * given class.
- *
- * @see #getInt(Object, long)
- * @see #putInt(Object, long, int)
- */
- public native int arrayBaseOffset(Class arrayClass);
-
- /** The value of {@code arrayBaseOffset(boolean[].class)} */
- public static final int ARRAY_BOOLEAN_BASE_OFFSET
- = theUnsafe.arrayBaseOffset(boolean[].class);
-
- /** The value of {@code arrayBaseOffset(byte[].class)} */
- public static final int ARRAY_BYTE_BASE_OFFSET
- = theUnsafe.arrayBaseOffset(byte[].class);
-
- /** The value of {@code arrayBaseOffset(short[].class)} */
- public static final int ARRAY_SHORT_BASE_OFFSET
- = theUnsafe.arrayBaseOffset(short[].class);
-
- /** The value of {@code arrayBaseOffset(char[].class)} */
- public static final int ARRAY_CHAR_BASE_OFFSET
- = theUnsafe.arrayBaseOffset(char[].class);
-
- /** The value of {@code arrayBaseOffset(int[].class)} */
- public static final int ARRAY_INT_BASE_OFFSET
- = theUnsafe.arrayBaseOffset(int[].class);
-
- /** The value of {@code arrayBaseOffset(long[].class)} */
- public static final int ARRAY_LONG_BASE_OFFSET
- = theUnsafe.arrayBaseOffset(long[].class);
-
- /** The value of {@code arrayBaseOffset(float[].class)} */
- public static final int ARRAY_FLOAT_BASE_OFFSET
- = theUnsafe.arrayBaseOffset(float[].class);
-
- /** The value of {@code arrayBaseOffset(double[].class)} */
- public static final int ARRAY_DOUBLE_BASE_OFFSET
- = theUnsafe.arrayBaseOffset(double[].class);
-
- /** The value of {@code arrayBaseOffset(Object[].class)} */
- public static final int ARRAY_OBJECT_BASE_OFFSET
- = theUnsafe.arrayBaseOffset(Object[].class);
-
- /**
- * Report the scale factor for addressing elements in the storage
- * allocation of a given array class. However, arrays of "narrow" types
- * will generally not work properly with accessors like {@link
- * #getByte(Object, int)}, so the scale factor for such classes is reported
- * as zero.
- *
- * @see #arrayBaseOffset
- * @see #getInt(Object, long)
- * @see #putInt(Object, long, int)
- */
- public native int arrayIndexScale(Class arrayClass);
-
- /** The value of {@code arrayIndexScale(boolean[].class)} */
- public static final int ARRAY_BOOLEAN_INDEX_SCALE
- = theUnsafe.arrayIndexScale(boolean[].class);
-
- /** The value of {@code arrayIndexScale(byte[].class)} */
- public static final int ARRAY_BYTE_INDEX_SCALE
- = theUnsafe.arrayIndexScale(byte[].class);
-
- /** The value of {@code arrayIndexScale(short[].class)} */
- public static final int ARRAY_SHORT_INDEX_SCALE
- = theUnsafe.arrayIndexScale(short[].class);
-
- /** The value of {@code arrayIndexScale(char[].class)} */
- public static final int ARRAY_CHAR_INDEX_SCALE
- = theUnsafe.arrayIndexScale(char[].class);
-
- /** The value of {@code arrayIndexScale(int[].class)} */
- public static final int ARRAY_INT_INDEX_SCALE
- = theUnsafe.arrayIndexScale(int[].class);
-
- /** The value of {@code arrayIndexScale(long[].class)} */
- public static final int ARRAY_LONG_INDEX_SCALE
- = theUnsafe.arrayIndexScale(long[].class);
-
- /** The value of {@code arrayIndexScale(float[].class)} */
- public static final int ARRAY_FLOAT_INDEX_SCALE
- = theUnsafe.arrayIndexScale(float[].class);
-
- /** The value of {@code arrayIndexScale(double[].class)} */
- public static final int ARRAY_DOUBLE_INDEX_SCALE
- = theUnsafe.arrayIndexScale(double[].class);
-
- /** The value of {@code arrayIndexScale(Object[].class)} */
- public static final int ARRAY_OBJECT_INDEX_SCALE
- = theUnsafe.arrayIndexScale(Object[].class);
-
- /**
- * Report the size in bytes of a native pointer, as stored via {@link
- * #putAddress}. This value will be either 4 or 8. Note that the sizes of
- * other primitive types (as stored in native memory blocks) is determined
- * fully by their information content.
- */
- public native int addressSize();
-
- /** The value of {@code addressSize()} */
- public static final int ADDRESS_SIZE = theUnsafe.addressSize();
-
- /**
- * Report the size in bytes of a native memory page (whatever that is).
- * This value will always be a power of two.
- */
- public native int pageSize();
-
-
- /// random trusted operations from JNI:
-
- /**
- * Tell the VM to define a class, without security checks. By default, the
- * class loader and protection domain come from the caller's class.
- */
- public native Class defineClass(String name, byte[] b, int off, int len,
- ClassLoader loader,
- ProtectionDomain protectionDomain);
-
- public native Class defineClass(String name, byte[] b, int off, int len);
-
- /** Allocate an instance but do not run any constructor.
- Initializes the class if it has not yet been. */
- public native Object allocateInstance(Class cls)
- throws InstantiationException;
-
- /** Lock the object. It must get unlocked via {@link #monitorExit}. */
- public native void monitorEnter(Object o);
-
- /**
- * Unlock the object. It must have been locked via {@link
- * #monitorEnter}.
- */
- public native void monitorExit(Object o);
-
- /**
- * Tries to lock the object. Returns true or false to indicate
- * whether the lock succeeded. If it did, the object must be
- * unlocked via {@link #monitorExit}.
- */
- public native boolean tryMonitorEnter(Object o);
-
- /** Throw the exception without telling the verifier. */
- public native void throwException(Throwable ee);
-
-
- /**
- * Atomically update Java variable to <tt>x</tt> if it is currently
- * holding <tt>expected</tt>.
- * @return <tt>true</tt> if successful
- */
- public final native boolean compareAndSwapObject(Object o, long offset,
- Object expected,
- Object x);
-
- /**
- * Atomically update Java variable to <tt>x</tt> if it is currently
- * holding <tt>expected</tt>.
- * @return <tt>true</tt> if successful
- */
- public final native boolean compareAndSwapInt(Object o, long offset,
- int expected,
- int x);
-
- /**
- * Atomically update Java variable to <tt>x</tt> if it is currently
- * holding <tt>expected</tt>.
- * @return <tt>true</tt> if successful
- */
- public final native boolean compareAndSwapLong(Object o, long offset,
- long expected,
- long x);
-
- /**
- * Fetches a reference value from a given Java variable, with volatile
- * load semantics. Otherwise identical to {@link #getObject(Object, long)}
- */
- public native Object getObjectVolatile(Object o, long offset);
-
- /**
- * Stores a reference value into a given Java variable, with
- * volatile store semantics. Otherwise identical to {@link #putObject(Object, long, Object)}
- */
- public native void putObjectVolatile(Object o, long offset, Object x);
-
- /** Volatile version of {@link #getInt(Object, long)} */
- public native int getIntVolatile(Object o, long offset);
-
- /** Volatile version of {@link #putInt(Object, long, int)} */
- public native void putIntVolatile(Object o, long offset, int x);
-
- /** Volatile version of {@link #getBoolean(Object, long)} */
- public native boolean getBooleanVolatile(Object o, long offset);
-
- /** Volatile version of {@link #putBoolean(Object, long, boolean)} */
- public native void putBooleanVolatile(Object o, long offset, boolean x);
-
- /** Volatile version of {@link #getByte(Object, long)} */
- public native byte getByteVolatile(Object o, long offset);
-
- /** Volatile version of {@link #putByte(Object, long, byte)} */
- public native void putByteVolatile(Object o, long offset, byte x);
-
- /** Volatile version of {@link #getShort(Object, long)} */
- public native short getShortVolatile(Object o, long offset);
-
- /** Volatile version of {@link #putShort(Object, long, short)} */
- public native void putShortVolatile(Object o, long offset, short x);
-
- /** Volatile version of {@link #getChar(Object, long)} */
- public native char getCharVolatile(Object o, long offset);
-
- /** Volatile version of {@link #putChar(Object, long, char)} */
- public native void putCharVolatile(Object o, long offset, char x);
-
- /** Volatile version of {@link #getLong(Object, long)} */
- public native long getLongVolatile(Object o, long offset);
-
- /** Volatile version of {@link #putLong(Object, long, long)} */
- public native void putLongVolatile(Object o, long offset, long x);
-
- /** Volatile version of {@link #getFloat(Object, long)} */
- public native float getFloatVolatile(Object o, long offset);
-
- /** Volatile version of {@link #putFloat(Object, long, float)} */
- public native void putFloatVolatile(Object o, long offset, float x);
-
- /** Volatile version of {@link #getDouble(Object, long)} */
- public native double getDoubleVolatile(Object o, long offset);
-
- /** Volatile version of {@link #putDouble(Object, long, double)} */
- public native void putDoubleVolatile(Object o, long offset, double x);
-
- /**
- * Version of {@link #putObjectVolatile(Object, long, Object)}
- * that does not guarantee immediate visibility of the store to
- * other threads. This method is generally only useful if the
- * underlying field is a Java volatile (or if an array cell, one
- * that is otherwise only accessed using volatile accesses).
- */
- public native void putOrderedObject(Object o, long offset, Object x);
-
- /** Ordered/Lazy version of {@link #putIntVolatile(Object, long, int)} */
- public native void putOrderedInt(Object o, long offset, int x);
-
- /** Ordered/Lazy version of {@link #putLongVolatile(Object, long, long)} */
- public native void putOrderedLong(Object o, long offset, long x);
-
- /**
- * Unblock the given thread blocked on <tt>park</tt>, or, if it is
- * not blocked, cause the subsequent call to <tt>park</tt> not to
- * block. Note: this operation is "unsafe" solely because the
- * caller must somehow ensure that the thread has not been
- * destroyed. Nothing special is usually required to ensure this
- * when called from Java (in which there will ordinarily be a live
- * reference to the thread) but this is not nearly-automatically
- * so when calling from native code.
- * @param thread the thread to unpark.
- *
- */
- public native void unpark(Object thread);
-
- /**
- * Block current thread, returning when a balancing
- * <tt>unpark</tt> occurs, or a balancing <tt>unpark</tt> has
- * already occurred, or the thread is interrupted, or, if not
- * absolute and time is not zero, the given time nanoseconds have
- * elapsed, or if absolute, the given deadline in milliseconds
- * since Epoch has passed, or spuriously (i.e., returning for no
- * "reason"). Note: This operation is in the Unsafe class only
- * because <tt>unpark</tt> is, so it would be strange to place it
- * elsewhere.
- */
- public native void park(boolean isAbsolute, long time);
-
- /**
- * Gets the load average in the system run queue assigned
- * to the available processors averaged over various periods of time.
- * This method retrieves the given <tt>nelem</tt> samples and
- * assigns to the elements of the given <tt>loadavg</tt> array.
- * The system imposes a maximum of 3 samples, representing
- * averages over the last 1, 5, and 15 minutes, respectively.
- *
- * @params loadavg an array of double of size nelems
- * @params nelems the number of samples to be retrieved and
- * must be 1 to 3.
- *
- * @return the number of samples actually retrieved; or -1
- * if the load average is unobtainable.
- */
- public native int getLoadAverage(double[] loadavg, int nelems);
-}
+++ /dev/null
-/*
- * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.*;
-
-/** Provides reflective access to the constant pools of classes.
- Currently this is needed to provide reflective access to annotations
- but may be used by other internal subsystems in the future. */
-
-public class ConstantPool {
- // Number of entries in this constant pool (= maximum valid constant pool index)
- public int getSize() { return getSize0 (constantPoolOop); }
- public Class getClassAt (int index) { return getClassAt0 (constantPoolOop, index); }
- public Class getClassAtIfLoaded (int index) { return getClassAtIfLoaded0 (constantPoolOop, index); }
- // Returns either a Method or Constructor.
- // Static initializers are returned as Method objects.
- public Member getMethodAt (int index) { return getMethodAt0 (constantPoolOop, index); }
- public Member getMethodAtIfLoaded(int index) { return getMethodAtIfLoaded0(constantPoolOop, index); }
- public Field getFieldAt (int index) { return getFieldAt0 (constantPoolOop, index); }
- public Field getFieldAtIfLoaded (int index) { return getFieldAtIfLoaded0 (constantPoolOop, index); }
- // Fetches the class name, member (field, method or interface
- // method) name, and type descriptor as an array of three Strings
- public String[] getMemberRefInfoAt (int index) { return getMemberRefInfoAt0 (constantPoolOop, index); }
- public int getIntAt (int index) { return getIntAt0 (constantPoolOop, index); }
- public long getLongAt (int index) { return getLongAt0 (constantPoolOop, index); }
- public float getFloatAt (int index) { return getFloatAt0 (constantPoolOop, index); }
- public double getDoubleAt (int index) { return getDoubleAt0 (constantPoolOop, index); }
- public String getStringAt (int index) { return getStringAt0 (constantPoolOop, index); }
- public String getUTF8At (int index) { return getUTF8At0 (constantPoolOop, index); }
-
- //---------------------------------------------------------------------------
- // Internals only below this point
- //
-/* This hides this member from being visible through the reflection API in OpenJDK
- * TODO: find out how to do this with GNU Classpath (if it's realy neccesary).
-
- static {
- Reflection.registerFieldsToFilter(ConstantPool.class, new String[] { "constantPoolOop" });
- }
-*/
- // HotSpot-internal constant pool object (set by the VM, name known to the VM)
- private Object constantPoolOop;
-
- private native int getSize0 (Object constantPoolOop);
- private native Class getClassAt0 (Object constantPoolOop, int index);
- private native Class getClassAtIfLoaded0 (Object constantPoolOop, int index);
- private native Member getMethodAt0 (Object constantPoolOop, int index);
- private native Member getMethodAtIfLoaded0(Object constantPoolOop, int index);
- private native Field getFieldAt0 (Object constantPoolOop, int index);
- private native Field getFieldAtIfLoaded0 (Object constantPoolOop, int index);
- private native String[] getMemberRefInfoAt0 (Object constantPoolOop, int index);
- private native int getIntAt0 (Object constantPoolOop, int index);
- private native long getLongAt0 (Object constantPoolOop, int index);
- private native float getFloatAt0 (Object constantPoolOop, int index);
- private native double getDoubleAt0 (Object constantPoolOop, int index);
- private native String getStringAt0 (Object constantPoolOop, int index);
- private native String getUTF8At0 (Object constantPoolOop, int index);
-}
+++ /dev/null
-/*
- * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-package sun.reflect.annotation;
-
-import java.lang.annotation.*;
-import java.util.*;
-import java.nio.ByteBuffer;
-import java.nio.BufferUnderflowException;
-import java.lang.reflect.*;
-import sun.reflect.ConstantPool;
-
-import gnu.java.lang.reflect.FieldSignatureParser;
-
-
-/**
- * Parser for Java programming language annotations. Translates
- * annotation byte streams emitted by compiler into annotation objects.
- *
- * @author Josh Bloch
- * @since 1.5
- */
-public class AnnotationParser {
- /**
- * Parses the annotations described by the passed byte array,
- * but returns Annotation[] so I don't have to do this in C.
- *
- * @author Mathias Panzenböck
- *
- * @param rawAnnotations are the unparsed annotations
- * @param constPool is the constant pool of the declaring class
- * @param container is the containing class
- * @return the parsed annotations in an array
- * @throws AnnotationFormatError if an annotation is found to be
- * malformed.
- */
- public static Annotation[] parseAnnotationsIntoArray(
- byte[] rawAnnotations,
- ConstantPool constPool,
- Class container) {
- Map<Class, Annotation> annotations = parseAnnotations(rawAnnotations, constPool, container);
- return annotations.values().toArray(EMPTY_ANNOTATIONS_ARRAY);
- }
-
- /**
- * Parses parameter annotations.
- *
- * @author Mathias Panzenböck
- *
- * @param parameterAnnotations are the unparsed parameter annotations
- * @param constPool is the constant pool of the declaring class
- * @param container is the containing class
- * @return the parsed parameter annotations in an array 2 dimensional array
- * @throws AnnotationFormatError if an annotation is found to be
- * malformed.
- */
- public static Annotation[][] parseParameterAnnotations(
- byte[] parameterAnnotations,
- ConstantPool constPool,
- Class container,
- int numParameters) {
- if (parameterAnnotations == null)
- return new Annotation[numParameters][0];
-
- Annotation[][] result = parseParameterAnnotations(
- parameterAnnotations, constPool, container);
-
- if (result.length != numParameters)
- throw new AnnotationFormatError(
- "Parameter annotations don't match number of parameters (count was " +
- result.length + " but should be " + numParameters + ").");
- return result;
- }
-
- /**
- * Parses the annotation default value of the supplied method.
- * This method is basically copied from OpenJDKs
- * java.lang.reflect.Method.getAnnotationDefault()
- *
- * @author Mathias Panzenböck
- *
- * @param method represents the method for which the annotation default value has to be parsed
- * @param annotationDefault is the unparsed annotation default value
- * @param constPool is the constant pool of the declaring class
- * @return the parsed annotation default value (boxed, if it's a primitive type)
- * @throws AnnotationFormatError if an annotation is found to be
- * malformed.
- */
- public static Object parseAnnotationDefault(Method method,
- byte[] annotationDefault,
- ConstantPool constPool) {
- if (annotationDefault == null)
- return null;
-
- Class memberType = AnnotationType.invocationHandlerReturnType(
- method.getReturnType());
-
- Object result = AnnotationParser.parseMemberValue(
- memberType, ByteBuffer.wrap(annotationDefault),
- constPool, method.getDeclaringClass());
-
- if (result instanceof sun.reflect.annotation.ExceptionProxy)
- throw new AnnotationFormatError("Invalid default: " + method);
-
- return result;
- }
-
- /**
- * Parses the annotations described by the specified byte array.
- * resolving constant references in the specified constant pool.
- * The array must contain an array of annotations as described
- * in the RuntimeVisibleAnnotations_attribute:
- *
- * u2 num_annotations;
- * annotation annotations[num_annotations];
- *
- * @throws AnnotationFormatError if an annotation is found to be
- * malformed.
- */
- public static Map<Class, Annotation> parseAnnotations(
- byte[] rawAnnotations,
- ConstantPool constPool,
- Class container) {
- if (rawAnnotations == null)
- return Collections.emptyMap();
-
- try {
- return parseAnnotations2(rawAnnotations, constPool, container);
- } catch(BufferUnderflowException e) {
- throw new AnnotationFormatError("Unexpected end of annotations.");
- } catch(IllegalArgumentException e) {
- // Type mismatch in constant pool
- throw new AnnotationFormatError(e);
- }
- }
-
- private static Map<Class, Annotation> parseAnnotations2(
- byte[] rawAnnotations,
- ConstantPool constPool,
- Class container) {
- Map<Class, Annotation> result = new LinkedHashMap<Class, Annotation>();
- ByteBuffer buf = ByteBuffer.wrap(rawAnnotations);
- int numAnnotations = buf.getShort() & 0xFFFF;
- for (int i = 0; i < numAnnotations; i++) {
- Annotation a = parseAnnotation(buf, constPool, container, false);
- if (a != null) {
- Class klass = a.annotationType();
- AnnotationType type = AnnotationType.getInstance(klass);
- if (type.retention() == RetentionPolicy.RUNTIME)
- if (result.put(klass, a) != null)
- throw new AnnotationFormatError(
- "Duplicate annotation for class: "+klass+": " + a);
- }
- }
- return result;
- }
-
- /**
- * Parses the parameter annotations described by the specified byte array.
- * resolving constant references in the specified constant pool.
- * The array must contain an array of annotations as described
- * in the RuntimeVisibleParameterAnnotations_attribute:
- *
- * u1 num_parameters;
- * {
- * u2 num_annotations;
- * annotation annotations[num_annotations];
- * } parameter_annotations[num_parameters];
- *
- * Unlike parseAnnotations, rawAnnotations must not be null!
- * A null value must be handled by the caller. This is so because
- * we cannot determine the number of parameters if rawAnnotations
- * is null. Also, the caller should check that the number
- * of parameters indicated by the return value of this method
- * matches the actual number of method parameters. A mismatch
- * indicates that an AnnotationFormatError should be thrown.
- *
- * @throws AnnotationFormatError if an annotation is found to be
- * malformed.
- */
- public static Annotation[][] parseParameterAnnotations(
- byte[] rawAnnotations,
- ConstantPool constPool,
- Class container) {
- try {
- return parseParameterAnnotations2(rawAnnotations, constPool, container);
- } catch(BufferUnderflowException e) {
- throw new AnnotationFormatError(
- "Unexpected end of parameter annotations.");
- } catch(IllegalArgumentException e) {
- // Type mismatch in constant pool
- throw new AnnotationFormatError(e);
- }
- }
-
- private static Annotation[][] parseParameterAnnotations2(
- byte[] rawAnnotations,
- ConstantPool constPool,
- Class container) {
- ByteBuffer buf = ByteBuffer.wrap(rawAnnotations);
- int numParameters = buf.get() & 0xFF;
- Annotation[][] result = new Annotation[numParameters][];
-
- for (int i = 0; i < numParameters; i++) {
- int numAnnotations = buf.getShort() & 0xFFFF;
- List<Annotation> annotations =
- new ArrayList<Annotation>(numAnnotations);
- for (int j = 0; j < numAnnotations; j++) {
- Annotation a = parseAnnotation(buf, constPool, container, false);
- if (a != null) {
- AnnotationType type = AnnotationType.getInstance(
- a.annotationType());
- if (type.retention() == RetentionPolicy.RUNTIME)
- annotations.add(a);
- }
- }
- result[i] = annotations.toArray(EMPTY_ANNOTATIONS_ARRAY);
- }
- return result;
- }
-
- private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY =
- new Annotation[0];
-
- /**
- * Parses the annotation at the current position in the specified
- * byte buffer, resolving constant references in the specified constant
- * pool. The cursor of the byte buffer must point to an "annotation
- * structure" as described in the RuntimeVisibleAnnotations_attribute:
- *
- * annotation {
- * u2 type_index;
- * u2 num_member_value_pairs;
- * { u2 member_name_index;
- * member_value value;
- * } member_value_pairs[num_member_value_pairs];
- * }
- * }
- *
- * Returns the annotation, or null if the annotation's type cannot
- * be found by the VM, or is not a valid annotation type.
- *
- * @param exceptionOnMissingAnnotationClass if true, throw
- * TypeNotPresentException if a referenced annotation type is not
- * available at runtime
- */
- private static Annotation parseAnnotation(ByteBuffer buf,
- ConstantPool constPool,
- Class container,
- boolean exceptionOnMissingAnnotationClass) {
- int typeIndex = buf.getShort() & 0xFFFF;
- Class annotationClass = null;
- String sig = "[unknown]";
- try {
- try {
- sig = constPool.getUTF8At(typeIndex);
- annotationClass = parseSig(sig, container);
- } catch (IllegalArgumentException ex) {
- // support obsolete early jsr175 format class files
- annotationClass = constPool.getClassAt(typeIndex);
- }
- } catch (NoClassDefFoundError e) {
- if (exceptionOnMissingAnnotationClass)
- // note: at this point sig is "[unknown]" or VM-style
- // name instead of a binary name
- throw new TypeNotPresentException(sig, e);
- skipAnnotation(buf, false);
- return null;
- }
- catch (TypeNotPresentException e) {
- if (exceptionOnMissingAnnotationClass)
- throw e;
- skipAnnotation(buf, false);
- return null;
- }
- AnnotationType type = null;
- try {
- type = AnnotationType.getInstance(annotationClass);
- } catch (IllegalArgumentException e) {
- skipAnnotation(buf, false);
- return null;
- }
-
- Map<String, Class> memberTypes = type.memberTypes();
- Map<String, Object> memberValues =
- new LinkedHashMap<String, Object>(type.memberDefaults());
-
- int numMembers = buf.getShort() & 0xFFFF;
- for (int i = 0; i < numMembers; i++) {
- int memberNameIndex = buf.getShort() & 0xFFFF;
- String memberName = constPool.getUTF8At(memberNameIndex);
- Class memberType = memberTypes.get(memberName);
-
- if (memberType == null) {
- // Member is no longer present in annotation type; ignore it
- skipMemberValue(buf);
- } else {
- Object value = parseMemberValue(memberType, buf, constPool, container);
- if (value instanceof AnnotationTypeMismatchExceptionProxy)
- ((AnnotationTypeMismatchExceptionProxy) value).
- setMember(type.members().get(memberName));
- memberValues.put(memberName, value);
- }
- }
- return annotationForMap(annotationClass, memberValues);
- }
-
- /**
- * Returns an annotation of the given type backed by the given
- * member -> value map.
- */
- public static Annotation annotationForMap(
- Class type, Map<String, Object> memberValues)
- {
- return (Annotation) Proxy.newProxyInstance(
- type.getClassLoader(), new Class[] { type },
- new AnnotationInvocationHandler(type, memberValues));
- }
-
- /**
- * Parses the annotation member value at the current position in the
- * specified byte buffer, resolving constant references in the specified
- * constant pool. The cursor of the byte buffer must point to a
- * "member_value structure" as described in the
- * RuntimeVisibleAnnotations_attribute:
- *
- * member_value {
- * u1 tag;
- * union {
- * u2 const_value_index;
- * {
- * u2 type_name_index;
- * u2 const_name_index;
- * } enum_const_value;
- * u2 class_info_index;
- * annotation annotation_value;
- * {
- * u2 num_values;
- * member_value values[num_values];
- * } array_value;
- * } value;
- * }
- *
- * The member must be of the indicated type. If it is not, this
- * method returns an AnnotationTypeMismatchExceptionProxy.
- */
- public static Object parseMemberValue(Class memberType, ByteBuffer buf,
- ConstantPool constPool,
- Class container) {
- Object result = null;
- int tag = buf.get();
- switch(tag) {
- case 'e':
- return parseEnumValue(memberType, buf, constPool, container);
- case 'c':
- result = parseClassValue(buf, constPool, container);
- break;
- case '@':
- result = parseAnnotation(buf, constPool, container, true);
- break;
- case '[':
- return parseArray(memberType, buf, constPool, container);
- default:
- result = parseConst(tag, buf, constPool);
- }
-
- if (!(result instanceof ExceptionProxy) &&
- !memberType.isInstance(result))
- result = new AnnotationTypeMismatchExceptionProxy(
- result.getClass() + "[" + result + "]");
- return result;
- }
-
- /**
- * Parses the primitive or String annotation member value indicated by
- * the specified tag byte at the current position in the specified byte
- * buffer, resolving constant reference in the specified constant pool.
- * The cursor of the byte buffer must point to an annotation member value
- * of the type indicated by the specified tag, as described in the
- * RuntimeVisibleAnnotations_attribute:
- *
- * u2 const_value_index;
- */
- private static Object parseConst(int tag,
- ByteBuffer buf, ConstantPool constPool) {
- int constIndex = buf.getShort() & 0xFFFF;
- switch(tag) {
- case 'B':
- return Byte.valueOf((byte) constPool.getIntAt(constIndex));
- case 'C':
- return Character.valueOf((char) constPool.getIntAt(constIndex));
- case 'D':
- return Double.valueOf(constPool.getDoubleAt(constIndex));
- case 'F':
- return Float.valueOf(constPool.getFloatAt(constIndex));
- case 'I':
- return Integer.valueOf(constPool.getIntAt(constIndex));
- case 'J':
- return Long.valueOf(constPool.getLongAt(constIndex));
- case 'S':
- return Short.valueOf((short) constPool.getIntAt(constIndex));
- case 'Z':
- return Boolean.valueOf(constPool.getIntAt(constIndex) != 0);
- case 's':
- return constPool.getUTF8At(constIndex);
- default:
- throw new AnnotationFormatError(
- "Invalid member-value tag in annotation: " + tag);
- }
- }
-
- /**
- * Parses the Class member value at the current position in the
- * specified byte buffer, resolving constant references in the specified
- * constant pool. The cursor of the byte buffer must point to a "class
- * info index" as described in the RuntimeVisibleAnnotations_attribute:
- *
- * u2 class_info_index;
- */
- private static Object parseClassValue(ByteBuffer buf,
- ConstantPool constPool,
- Class container) {
- int classIndex = buf.getShort() & 0xFFFF;
- try {
- try {
- String sig = constPool.getUTF8At(classIndex);
- return parseSig(sig, container);
- } catch (IllegalArgumentException ex) {
- // support obsolete early jsr175 format class files
- return constPool.getClassAt(classIndex);
- }
- } catch (NoClassDefFoundError e) {
- return new TypeNotPresentExceptionProxy("[unknown]", e);
- }
- catch (TypeNotPresentException e) {
- return new TypeNotPresentExceptionProxy(e.typeName(), e.getCause());
- }
- }
-
- /**
- * Parses a return type signature and returns the according Class object.
- */
- private static Class<?> parseSig(String sig, Class container) {
- if (sig.equals("V")) {
- return void.class;
- }
- else {
- return toClass(new FieldSignatureParser(container, sig).getFieldType());
- }
- }
-
- static Class<?> toClass(Type o) {
- if (o instanceof GenericArrayType)
- return Array.newInstance(toClass(((GenericArrayType)o).getGenericComponentType()),
- 0)
- .getClass();
- return (Class<?>)o;
- }
-
- /**
- * Parses the enum constant member value at the current position in the
- * specified byte buffer, resolving constant references in the specified
- * constant pool. The cursor of the byte buffer must point to a
- * "enum_const_value structure" as described in the
- * RuntimeVisibleAnnotations_attribute:
- *
- * {
- * u2 type_name_index;
- * u2 const_name_index;
- * } enum_const_value;
- */
- private static Object parseEnumValue(Class enumType, ByteBuffer buf,
- ConstantPool constPool,
- Class container) {
- int typeNameIndex = buf.getShort() & 0xFFFF;
- String typeName = constPool.getUTF8At(typeNameIndex);
- int constNameIndex = buf.getShort() & 0xFFFF;
- String constName = constPool.getUTF8At(constNameIndex);
-
- if (!typeName.endsWith(";")) {
- // support now-obsolete early jsr175-format class files.
- if (!enumType.getName().equals(typeName))
- return new AnnotationTypeMismatchExceptionProxy(
- typeName + "." + constName);
- } else if (enumType != parseSig(typeName, container)) {
- return new AnnotationTypeMismatchExceptionProxy(
- typeName + "." + constName);
- }
-
- try {
- return Enum.valueOf(enumType, constName);
- } catch(IllegalArgumentException e) {
- return new EnumConstantNotPresentExceptionProxy(
- (Class<? extends Enum>)enumType, constName);
- }
- }
-
- /**
- * Parses the array value at the current position in the specified byte
- * buffer, resolving constant references in the specified constant pool.
- * The cursor of the byte buffer must point to an array value struct
- * as specified in the RuntimeVisibleAnnotations_attribute:
- *
- * {
- * u2 num_values;
- * member_value values[num_values];
- * } array_value;
- *
- * If the array values do not match arrayType, an
- * AnnotationTypeMismatchExceptionProxy will be returned.
- */
- private static Object parseArray(Class arrayType,
- ByteBuffer buf,
- ConstantPool constPool,
- Class container) {
- int length = buf.getShort() & 0xFFFF; // Number of array components
- Class componentType = arrayType.getComponentType();
-
- if (componentType == byte.class) {
- return parseByteArray(length, buf, constPool);
- } else if (componentType == char.class) {
- return parseCharArray(length, buf, constPool);
- } else if (componentType == double.class) {
- return parseDoubleArray(length, buf, constPool);
- } else if (componentType == float.class) {
- return parseFloatArray(length, buf, constPool);
- } else if (componentType == int.class) {
- return parseIntArray(length, buf, constPool);
- } else if (componentType == long.class) {
- return parseLongArray(length, buf, constPool);
- } else if (componentType == short.class) {
- return parseShortArray(length, buf, constPool);
- } else if (componentType == boolean.class) {
- return parseBooleanArray(length, buf, constPool);
- } else if (componentType == String.class) {
- return parseStringArray(length, buf, constPool);
- } else if (componentType == Class.class) {
- return parseClassArray(length, buf, constPool, container);
- } else if (componentType.isEnum()) {
- return parseEnumArray(length, componentType, buf,
- constPool, container);
- } else {
- assert componentType.isAnnotation();
- return parseAnnotationArray(length, componentType, buf,
- constPool, container);
- }
- }
-
- private static Object parseByteArray(int length,
- ByteBuffer buf, ConstantPool constPool) {
- byte[] result = new byte[length];
- boolean typeMismatch = false;
- int tag = 0;
-
- for (int i = 0; i < length; i++) {
- tag = buf.get();
- if (tag == 'B') {
- int index = buf.getShort() & 0xFFFF;
- result[i] = (byte) constPool.getIntAt(index);
- } else {
- skipMemberValue(tag, buf);
- typeMismatch = true;
- }
- }
- return typeMismatch ? exceptionProxy(tag) : result;
- }
-
- private static Object parseCharArray(int length,
- ByteBuffer buf, ConstantPool constPool) {
- char[] result = new char[length];
- boolean typeMismatch = false;
- byte tag = 0;
-
- for (int i = 0; i < length; i++) {
- tag = buf.get();
- if (tag == 'C') {
- int index = buf.getShort() & 0xFFFF;
- result[i] = (char) constPool.getIntAt(index);
- } else {
- skipMemberValue(tag, buf);
- typeMismatch = true;
- }
- }
- return typeMismatch ? exceptionProxy(tag) : result;
- }
-
- private static Object parseDoubleArray(int length,
- ByteBuffer buf, ConstantPool constPool) {
- double[] result = new double[length];
- boolean typeMismatch = false;
- int tag = 0;
-
- for (int i = 0; i < length; i++) {
- tag = buf.get();
- if (tag == 'D') {
- int index = buf.getShort() & 0xFFFF;
- result[i] = constPool.getDoubleAt(index);
- } else {
- skipMemberValue(tag, buf);
- typeMismatch = true;
- }
- }
- return typeMismatch ? exceptionProxy(tag) : result;
- }
-
- private static Object parseFloatArray(int length,
- ByteBuffer buf, ConstantPool constPool) {
- float[] result = new float[length];
- boolean typeMismatch = false;
- int tag = 0;
-
- for (int i = 0; i < length; i++) {
- tag = buf.get();
- if (tag == 'F') {
- int index = buf.getShort() & 0xFFFF;
- result[i] = constPool.getFloatAt(index);
- } else {
- skipMemberValue(tag, buf);
- typeMismatch = true;
- }
- }
- return typeMismatch ? exceptionProxy(tag) : result;
- }
-
- private static Object parseIntArray(int length,
- ByteBuffer buf, ConstantPool constPool) {
- int[] result = new int[length];
- boolean typeMismatch = false;
- int tag = 0;
-
- for (int i = 0; i < length; i++) {
- tag = buf.get();
- if (tag == 'I') {
- int index = buf.getShort() & 0xFFFF;
- result[i] = constPool.getIntAt(index);
- } else {
- skipMemberValue(tag, buf);
- typeMismatch = true;
- }
- }
- return typeMismatch ? exceptionProxy(tag) : result;
- }
-
- private static Object parseLongArray(int length,
- ByteBuffer buf, ConstantPool constPool) {
- long[] result = new long[length];
- boolean typeMismatch = false;
- int tag = 0;
-
- for (int i = 0; i < length; i++) {
- tag = buf.get();
- if (tag == 'J') {
- int index = buf.getShort() & 0xFFFF;
- result[i] = constPool.getLongAt(index);
- } else {
- skipMemberValue(tag, buf);
- typeMismatch = true;
- }
- }
- return typeMismatch ? exceptionProxy(tag) : result;
- }
-
- private static Object parseShortArray(int length,
- ByteBuffer buf, ConstantPool constPool) {
- short[] result = new short[length];
- boolean typeMismatch = false;
- int tag = 0;
-
- for (int i = 0; i < length; i++) {
- tag = buf.get();
- if (tag == 'S') {
- int index = buf.getShort() & 0xFFFF;
- result[i] = (short) constPool.getIntAt(index);
- } else {
- skipMemberValue(tag, buf);
- typeMismatch = true;
- }
- }
- return typeMismatch ? exceptionProxy(tag) : result;
- }
-
- private static Object parseBooleanArray(int length,
- ByteBuffer buf, ConstantPool constPool) {
- boolean[] result = new boolean[length];
- boolean typeMismatch = false;
- int tag = 0;
-
- for (int i = 0; i < length; i++) {
- tag = buf.get();
- if (tag == 'Z') {
- int index = buf.getShort() & 0xFFFF;
- result[i] = (constPool.getIntAt(index) != 0);
- } else {
- skipMemberValue(tag, buf);
- typeMismatch = true;
- }
- }
- return typeMismatch ? exceptionProxy(tag) : result;
- }
-
- private static Object parseStringArray(int length,
- ByteBuffer buf, ConstantPool constPool) {
- String[] result = new String[length];
- boolean typeMismatch = false;
- int tag = 0;
-
- for (int i = 0; i < length; i++) {
- tag = buf.get();
- if (tag == 's') {
- int index = buf.getShort() & 0xFFFF;
- result[i] = constPool.getUTF8At(index);
- } else {
- skipMemberValue(tag, buf);
- typeMismatch = true;
- }
- }
- return typeMismatch ? exceptionProxy(tag) : result;
- }
-
- private static Object parseClassArray(int length,
- ByteBuffer buf,
- ConstantPool constPool,
- Class container) {
- Object[] result = new Class[length];
- boolean typeMismatch = false;
- int tag = 0;
-
- for (int i = 0; i < length; i++) {
- tag = buf.get();
- if (tag == 'c') {
- result[i] = parseClassValue(buf, constPool, container);
- } else {
- skipMemberValue(tag, buf);
- typeMismatch = true;
- }
- }
- return typeMismatch ? exceptionProxy(tag) : result;
- }
-
- private static Object parseEnumArray(int length, Class enumType,
- ByteBuffer buf,
- ConstantPool constPool,
- Class container) {
- Object[] result = (Object[]) Array.newInstance(enumType, length);
- boolean typeMismatch = false;
- int tag = 0;
-
- for (int i = 0; i < length; i++) {
- tag = buf.get();
- if (tag == 'e') {
- result[i] = parseEnumValue(enumType, buf, constPool, container);
- } else {
- skipMemberValue(tag, buf);
- typeMismatch = true;
- }
- }
- return typeMismatch ? exceptionProxy(tag) : result;
- }
-
- private static Object parseAnnotationArray(int length,
- Class annotationType,
- ByteBuffer buf,
- ConstantPool constPool,
- Class container) {
- Object[] result = (Object[]) Array.newInstance(annotationType, length);
- boolean typeMismatch = false;
- int tag = 0;
-
- for (int i = 0; i < length; i++) {
- tag = buf.get();
- if (tag == '@') {
- result[i] = parseAnnotation(buf, constPool, container, true);
- } else {
- skipMemberValue(tag, buf);
- typeMismatch = true;
- }
- }
- return typeMismatch ? exceptionProxy(tag) : result;
- }
-
- /**
- * Return an appropriate exception proxy for a mismatching array
- * annotation where the erroneous array has the specified tag.
- */
- private static ExceptionProxy exceptionProxy(int tag) {
- return new AnnotationTypeMismatchExceptionProxy(
- "Array with component tag: " + tag);
- }
-
- /**
- * Skips the annotation at the current position in the specified
- * byte buffer. The cursor of the byte buffer must point to
- * an "annotation structure" OR two bytes into an annotation
- * structure (i.e., after the type index).
- *
- * @parameter complete true if the byte buffer points to the beginning
- * of an annotation structure (rather than two bytes in).
- */
- private static void skipAnnotation(ByteBuffer buf, boolean complete) {
- if (complete)
- buf.getShort(); // Skip type index
- int numMembers = buf.getShort() & 0xFFFF;
- for (int i = 0; i < numMembers; i++) {
- buf.getShort(); // Skip memberNameIndex
- skipMemberValue(buf);
- }
- }
-
- /**
- * Skips the annotation member value at the current position in the
- * specified byte buffer. The cursor of the byte buffer must point to a
- * "member_value structure."
- */
- private static void skipMemberValue(ByteBuffer buf) {
- int tag = buf.get();
- skipMemberValue(tag, buf);
- }
-
- /**
- * Skips the annotation member value at the current position in the
- * specified byte buffer. The cursor of the byte buffer must point
- * immediately after the tag in a "member_value structure."
- */
- private static void skipMemberValue(int tag, ByteBuffer buf) {
- switch(tag) {
- case 'e': // Enum value
- buf.getInt(); // (Two shorts, actually.)
- break;
- case '@':
- skipAnnotation(buf, true);
- break;
- case '[':
- skipArray(buf);
- break;
- default:
- // Class, primitive, or String
- buf.getShort();
- }
- }
-
- /**
- * Skips the array value at the current position in the specified byte
- * buffer. The cursor of the byte buffer must point to an array value
- * struct.
- */
- private static void skipArray(ByteBuffer buf) {
- int length = buf.getShort() & 0xFFFF;
- for (int i = 0; i < length; i++)
- skipMemberValue(buf);
- }
-}
+++ /dev/null
-/*
- * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-package sun.reflect.annotation;
-
-import java.lang.annotation.*;
-import java.lang.reflect.*;
-import java.util.*;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-/**
- * Represents an annotation type at run time. Used to type-check annotations
- * and apply member defaults.
- *
- * @author Josh Bloch
- * @since 1.5
- */
-public class AnnotationType {
- /**
- * Annotation class -> AnnotationType mapping. This emulates
- * sun.misc.SharedSecrets.getJavaLangAccess().getAnnotationType() and
- * sun.misc.SharedSecrets.getJavaLangAccess().setAnnotationType() so
- * this class can be used with gnu classpath.
- *
- * @author Mathias Panzenböck
- */
- private static Map<Class, AnnotationType> annotationTypes =
- new HashMap<Class, AnnotationType>();
-
- /**
- * Member name -> type mapping. Note that primitive types
- * are represented by the class objects for the corresponding wrapper
- * types. This matches the return value that must be used for a
- * dynamic proxy, allowing for a simple isInstance test.
- */
- private final Map<String, Class> memberTypes = new HashMap<String,Class>();
-
- /**
- * Member name -> default value mapping.
- */
- private final Map<String, Object> memberDefaults =
- new HashMap<String, Object>();
-
- /**
- * Member name -> Method object mapping. This (and its assoicated
- * accessor) are used only to generate AnnotationTypeMismatchExceptions.
- */
- private final Map<String, Method> members = new HashMap<String, Method>();
-
- /**
- * The retention policy for this annotation type.
- */
- private RetentionPolicy retention = RetentionPolicy.RUNTIME;;
-
- /**
- * Whether this annotation type is inherited.
- */
- private boolean inherited = false;
-
- /**
- * Returns an AnnotationType instance for the specified annotation type.
- *
- * @throw IllegalArgumentException if the specified class object for
- * does not represent a valid annotation type
- */
- public static synchronized AnnotationType getInstance(
- Class annotationClass)
- {
- /*
- AnnotationType result = sun.misc.SharedSecrets.getJavaLangAccess().
- getAnnotationType(annotationClass);
- */
- // emulating OpenJDKs SharedSecrets in GNU Classpath:
- AnnotationType result = annotationTypes.get(annotationClass);
- if (result == null)
- result = new AnnotationType((Class<?>) annotationClass);
-
- return result;
- }
-
- /**
- * Sole constructor.
- *
- * @param annotationClass the class object for the annotation type
- * @throw IllegalArgumentException if the specified class object for
- * does not represent a valid annotation type
- */
- private AnnotationType(final Class<?> annotationClass) {
- if (!annotationClass.isAnnotation())
- throw new IllegalArgumentException("Not an annotation type");
-
- Method[] methods =
- AccessController.doPrivileged(new PrivilegedAction<Method[]>() {
- public Method[] run() {
- // Initialize memberTypes and defaultValues
- return annotationClass.getDeclaredMethods();
- }
- });
-
-
- for (Method method : methods) {
- if (method.getParameterTypes().length != 0)
- throw new IllegalArgumentException(method + " has params");
- String name = method.getName();
- Class type = method.getReturnType();
- memberTypes.put(name, invocationHandlerReturnType(type));
- members.put(name, method);
-
- Object defaultValue = method.getDefaultValue();
- if (defaultValue != null)
- memberDefaults.put(name, defaultValue);
-
- members.put(name, method);
- }
-
- /*
- sun.misc.SharedSecrets.getJavaLangAccess().
- setAnnotationType(annotationClass, this);
- */
- // emulating OpenJDKs SharedSecrets in GNU Classpath:
- annotationTypes.put(annotationClass, this);
-
- // Initialize retention, & inherited fields. Special treatment
- // of the corresponding annotation types breaks infinite recursion.
- if (annotationClass != Retention.class &&
- annotationClass != Inherited.class) {
- Retention ret = annotationClass.getAnnotation(Retention.class);
- retention = (ret == null ? RetentionPolicy.CLASS : ret.value());
- inherited = annotationClass.isAnnotationPresent(Inherited.class);
- }
- }
-
- /**
- * Returns the type that must be returned by the invocation handler
- * of a dynamic proxy in order to have the dynamic proxy return
- * the specified type (which is assumed to be a legal member type
- * for an annotation).
- */
- public static Class invocationHandlerReturnType(Class type) {
- // Translate primitives to wrappers
- if (type == byte.class)
- return Byte.class;
- if (type == char.class)
- return Character.class;
- if (type == double.class)
- return Double.class;
- if (type == float.class)
- return Float.class;
- if (type == int.class)
- return Integer.class;
- if (type == long.class)
- return Long.class;
- if (type == short.class)
- return Short.class;
- if (type == boolean.class)
- return Boolean.class;
-
- // Otherwise, just return declared type
- return type;
- }
-
- /**
- * Returns member types for this annotation type
- * (member name -> type mapping).
- */
- public Map<String, Class> memberTypes() {
- return memberTypes;
- }
-
- /**
- * Returns members of this annotation type
- * (member name -> associated Method object mapping).
- */
- public Map<String, Method> members() {
- return members;
- }
-
- /**
- * Returns the default values for this annotation type
- * (Member name -> default value mapping).
- */
- public Map<String, Object> memberDefaults() {
- return memberDefaults;
- }
-
- /**
- * Returns the retention policy for this annotation type.
- */
- public RetentionPolicy retention() {
- return retention;
- }
-
- /**
- * Returns true if this this annotation type is inherited.
- */
- public boolean isInherited() {
- return inherited;
- }
-
- /**
- * For debugging.
- */
- public String toString() {
- StringBuffer s = new StringBuffer("Annotation Type:" + "\n");
- s.append(" Member types: " + memberTypes + "\n");
- s.append(" Member defaults: " + memberDefaults + "\n");
- s.append(" Retention policy: " + retention + "\n");
- s.append(" Inherited: " + inherited);
- return s.toString();
- }
-}
+++ /dev/null
-/*
- * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-package sun.reflect.annotation;
-import java.lang.annotation.*;
-import java.lang.reflect.Method;
-
-/**
- * ExceptionProxy for AnnotationTypeMismatchException.
- *
- * @author Josh Bloch
- * @since 1.5
- */
-class AnnotationTypeMismatchExceptionProxy extends ExceptionProxy {
- private Method member;
- private String foundType;
-
- /**
- * It turns out to be convenient to construct these proxies in
- * two stages. Since this is a private implementation class, we
- * permit ourselves this liberty even though it's normally a very
- * bad idea.
- */
- AnnotationTypeMismatchExceptionProxy(String foundType) {
- this.foundType = foundType;
- }
-
- AnnotationTypeMismatchExceptionProxy setMember(Method member) {
- this.member = member;
- return this;
- }
-
- protected RuntimeException generateException() {
- return new AnnotationTypeMismatchException(member, foundType);
- }
-}
+++ /dev/null
-/*
- * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-package sun.reflect.annotation;
-import java.lang.annotation.*;
-
-/**
- * ExceptionProxy for EnumConstantNotPresentException.
- *
- * @author Josh Bloch
- * @since 1.5
- */
-public class EnumConstantNotPresentExceptionProxy extends ExceptionProxy {
- Class<? extends Enum> enumType;
- String constName;
-
- public EnumConstantNotPresentExceptionProxy(Class<? extends Enum> enumType,
- String constName) {
- this.enumType = enumType;
- this.constName = constName;
- }
-
- protected RuntimeException generateException() {
- return new EnumConstantNotPresentException(enumType, constName);
- }
-}
+++ /dev/null
-/*
- * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-package sun.reflect.annotation;
-
-/**
- * An instance of this class is stored in an AnnotationInvocationHandler's
- * "memberValues" map in lieu of a value for an annotation member that
- * cannot be returned due to some exceptional condition (typically some
- * form of illegal evolution of the annotation class). The ExceptionProxy
- * instance describes the exception that the dynamic proxy should throw if
- * it is queried for this member.
- *
- * @author Josh Bloch
- * @since 1.5
- */
-public abstract class ExceptionProxy implements java.io.Serializable {
- protected abstract RuntimeException generateException();
-}
+++ /dev/null
-/*
- * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-package sun.reflect.annotation;
-import java.lang.annotation.*;
-
-/**
- * ExceptionProxy for TypeNotPresentException.
- *
- * @author Josh Bloch
- * @since 1.5
- */
-public class TypeNotPresentExceptionProxy extends ExceptionProxy {
- String typeName;
- Throwable cause;
-
- public TypeNotPresentExceptionProxy(String typeName, Throwable cause) {
- this.typeName = typeName;
- this.cause = cause;
- }
-
- protected RuntimeException generateException() {
- return new TypeNotPresentException(typeName, cause);
- }
-}
## src/native/include/Makefile.am
##
-## Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
-## C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
-## E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
-## J. Wenninger, Institut f. Computersprachen - TU Wien
+## Copyright (C) 1996-2005, 2006, 2007, 2008
+## CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
##
## This file is part of CACAO.
##
## 02110-1301, USA.
+JAVAH = $(CACAOH)
+JAVAHCMD = $(JAVAH) -bootclasspath $(BOOTCLASSPATH)
+
COMMON_HEADER_FILES = \
java_lang_Class.h \
java_lang_Object.h \
endif
if WITH_CLASSPATH_GNU
-CLASSPATH = $(top_builddir)/src/lib/classes/:$(CLASSPATH_CLASSES)
-VM_ZIP = $(top_builddir)/src/lib/vm.zip
-endif
-
-if WITH_CLASSPATH_SUN
-CLASSPATH = $(CLASSPATH_CLASSES)
+VM_ZIP = $(top_builddir)/src/classes/vm.zip
endif
if WITH_CLASSPATH_CLDC1_1
-CLASSPATH = $(top_builddir)/src/lib/classes/:$(CLASSPATH_CLASSES)
-VM_ZIP = $(top_builddir)/src/lib/vm.zip
+VM_ZIP = $(top_builddir)/src/classes/vm.zip
endif
noinst_DATA = $(DO_HEADER_FILES)
$(DO_HEADER_FILES): $(CACAOH) $(VM_ZIP) $(CLASSPATH_CLASSES)
@class=`echo $@ | sed -e 's/\.h$$//' -e 's/_/\./g'`; \
- echo "$(CACAOH) -bootclasspath $(CLASSPATH) -d . $$class"; \
- $(CACAOH) -bootclasspath $(CLASSPATH) -d . $$class
+ echo "$(JAVAHCMD) -d . $$class"; \
+ $(JAVAHCMD) -d . $$class
## Local variables: