|
From: <ls...@us...> - 2007-01-28 20:52:04
|
Revision: 3096
http://jnode.svn.sourceforge.net/jnode/?rev=3096&view=rev
Author: lsantha
Date: 2007-01-28 12:52:02 -0800 (Sun, 28 Jan 2007)
Log Message:
-----------
Classpath patches.
Modified Paths:
--------------
trunk/core/src/classpath/java/java/lang/reflect/Array.java
Added Paths:
-----------
trunk/core/src/classpath/vm/java/lang/reflect/VMArray.java
Modified: trunk/core/src/classpath/java/java/lang/reflect/Array.java
===================================================================
--- trunk/core/src/classpath/java/java/lang/reflect/Array.java 2007-01-27 21:52:45 UTC (rev 3095)
+++ trunk/core/src/classpath/java/java/lang/reflect/Array.java 2007-01-28 20:52:02 UTC (rev 3096)
@@ -35,19 +35,9 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
+
package java.lang.reflect;
-import org.jnode.vm.Vm;
-import org.jnode.vm.memmgr.VmHeapManager;
-import org.jnode.vm.classmgr.VmType;
-import org.jnode.vm.classmgr.VmClassLoader;
-import org.jnode.vm.classmgr.VmArrayClass;
-
-import gnu.java.security.action.InvokeAction;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
/**
* Array holds static helper functions that allow you to create and
* manipulate arrays by reflection. Operations know how to perform widening
@@ -105,10 +95,10 @@
* @throws NegativeArraySizeException when length is less than 0
* @throws OutOfMemoryError if memory allocation fails
*/
- public static Object newInstance(Class componentType, int length)
+ public static Object newInstance(Class<?> componentType, int length)
{
- if (!componentType.isPrimitive())
- return createObjectArray(componentType, length);
+ if (! componentType.isPrimitive())
+ return VMArray.createObjectArray(componentType, length);
if (componentType == boolean.class)
return new boolean[length];
if (componentType == byte.class)
@@ -153,10 +143,10 @@
* than 0
* @throws OutOfMemoryError if memory allocation fails
*/
- public static Object newInstance(Class componentType, int[] dimensions)
+ public static Object newInstance(Class<?> componentType, int[] dimensions)
{
if (dimensions.length <= 0)
- throw new IllegalArgumentException("Empty dimensions array.");
+ throw new IllegalArgumentException ("Empty dimensions array.");
return createMultiArray(componentType, dimensions,
dimensions.length - 1);
}
@@ -175,7 +165,7 @@
if (array instanceof boolean[])
return ((boolean[]) array).length;
if (array instanceof byte[])
- return ((byte[]) array).length;
+ return ((byte[]) array). length;
if (array instanceof char[])
return ((char[]) array).length;
if (array instanceof short[])
@@ -654,7 +644,7 @@
Object toAdd = createMultiArray(type, dimensions, index - 1);
Class thisType = toAdd.getClass();
Object[] retval
- = (Object[]) createObjectArray(thisType, dimensions[index]);
+ = (Object[]) VMArray.createObjectArray(thisType, dimensions[index]);
if (dimensions[index] > 0)
retval[0] = toAdd;
int i = dimensions[index];
@@ -663,49 +653,4 @@
return retval;
}
-
- // LS
- // @classpath-bugfix-22923 should be placed in VMArray
- /**
- * Dynamically create an array of objects.
- *
- * @param type guaranteed to be a valid object type
- * @param dim the length of the array
- * @return the new array
- * @throws NegativeArraySizeException if dim is negative
- * @throws OutOfMemoryError if memory allocation fails
- */
- private static Object createObjectArray(final Class type, int dim) {
- final VmType vmClass = (VmType) AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
- return type.getVmClass();
- }
- });
-
- final String arrClsName = vmClass.getArrayClassName();
- final VmType arrCls;
- try {
- final VmClassLoader curLoader = vmClass.getLoader();
- arrCls = curLoader.loadClass(arrClsName, true);
- //Screen.debug("an cls{");
- //Screen.debug(vmClass.getName());
- if (arrCls == null) {
- throw new NoClassDefFoundError(arrClsName);
- }
- } catch (ClassNotFoundException ex) {
- throw new NoClassDefFoundError(arrClsName);
- }
-
- VmHeapManager hm = heapManager;
- if (hm == null) {
- heapManager = hm = Vm.getVm().getHeapManager();
- }
- final Object result = hm.newArray((VmArrayClass) arrCls, dim);
-
- //Screen.debug("}");
- return result;
- }
- private static VmHeapManager heapManager;
- // @classpath-bugfix-end
}
Added: trunk/core/src/classpath/vm/java/lang/reflect/VMArray.java
===================================================================
--- trunk/core/src/classpath/vm/java/lang/reflect/VMArray.java (rev 0)
+++ trunk/core/src/classpath/vm/java/lang/reflect/VMArray.java 2007-01-28 20:52:02 UTC (rev 3096)
@@ -0,0 +1,91 @@
+/* java.lang.reflect.VMArray - VM class for array manipulation by reflection.
+ Copyright (C) 1998, 1999, 2001, 2003, 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.classpath.Configuration;
+import org.jnode.vm.classmgr.VmType;
+import org.jnode.vm.classmgr.VmClassLoader;
+import org.jnode.vm.classmgr.VmArrayClass;
+import org.jnode.vm.Vm;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+class VMArray
+{
+
+ static
+ {
+ if (Configuration.INIT_LOAD_LIBRARY)
+ {
+ System.loadLibrary("javalangreflect");
+ }
+ }
+
+ /**
+ * Dynamically create an array of objects.
+ *
+ * @param type guaranteed to be a valid object type
+ * @param dim the length of the array
+ * @return the new array
+ * @throws NegativeArraySizeException if dim is negative
+ * @throws OutOfMemoryError if memory allocation fails
+ */
+ static Object createObjectArray(final Class type, int dim) {
+ final VmType vmClass = AccessController.doPrivileged(
+ new PrivilegedAction<VmType>() {
+ public VmType run() {
+ return type.getVmClass();
+ }
+ });
+
+ final String arrClsName = vmClass.getArrayClassName();
+ final VmType arrCls;
+ try {
+ final VmClassLoader curLoader = vmClass.getLoader();
+ arrCls = curLoader.loadClass(arrClsName, true);
+ if (arrCls == null) {
+ throw new NoClassDefFoundError(arrClsName);
+ }
+ } catch (ClassNotFoundException ex) {
+ throw new NoClassDefFoundError(arrClsName);
+ }
+
+ return Vm.getHeapManager().newArray((VmArrayClass) arrCls, dim);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|