History

Fixed java/lang/Class, to match Inferno's jvm

Dmitry Kabak (userdima committed 13 years ago

Commit ab9ed8e1 parent 816a4f43 files · +83 −62Browse files

Showing the changes to java (3 of 3 files). Show all

Unified · Split

3 files
  1. java/pkg/java/lang/Class.java +76 −61
  2. java/pkg/java/lang/Class_L.b +6 −1
  3. java/pkg/java/lang/Class_L.m +1 −0
java/pkg/java/lang/Class.java+76−61
@@ -117,6 +117,14 @@ public final · 116 unmodified lines
117117 java.lang.reflect.GenericDeclaration,
118118 java.lang.reflect.Type,
119119 java.lang.reflect.AnnotatedElement {
120+
121+ // [Inferno] <
122+ /** A field that is used by jvm to store internal data */
123+ private transient Object classData;
124+ /** A field that is used by jvm to store internal data */
125+ private transient Object arrayName;
126+ // [Inferno] >
127+
120128 private static final int ANNOTATION= 0x00002000;
121129 private static final int ENUM = 0x00004000;
122130 private static final int SYNTHETIC = 0x00001000;
@@ -254,16 +262,19 @@ public final · 131 unmodified lines
254262 ClassLoader loader)
255263 throws ClassNotFoundException
256264 {
257− if (loader == null) {
258− SecurityManager sm = System.getSecurityManager();
259− if (sm != null) {
260− ClassLoader ccl = ClassLoader.getCallerClassLoader();
261− if (ccl != null) {
262− sm.checkPermission(
263− SecurityConstants.GET_CLASSLOADER_PERMISSION);
264− }
265− }
266− }
265+ // [Inferno] <
266+ //if (loader == null) {
267+ // SecurityManager sm = System.getSecurityManager();
268+ // if (sm != null) {
269+ // ClassLoader ccl = ClassLoader.getCallerClassLoader();
270+ // if (ccl != null) {
271+ // sm.checkPermission(
272+ // SecurityConstants.GET_CLASSLOADER_PERMISSION);
273+ // }
274+ // }
275+ //}
276+ // [Inferno] =
277+ // [Inferno] >
267278 return forName0(name, initialize, loader);
268279 }
269280
@@ -328,57 +339,61 @@ public final · 58 unmodified lines
328339 return newInstance0();
329340 }
330341
331− private T newInstance0()
332− throws InstantiationException, IllegalAccessException
333− {
334− // NOTE: the following code may not be strictly correct under
335− // the current Java memory model.
336−
337− // Constructor lookup
338− if (cachedConstructor == null) {
339− if (this == Class.class) {
340− throw new IllegalAccessException(
341− "Can not call newInstance() on the Class for java.lang.Class"
342− );
343− }
344− try {
345− Class<?>[] empty = {};
346− final Constructor<T> c = getConstructor0(empty, Member.DECLARED);
347− // Disable accessibility checks on the constructor
348− // since we have to do the security check here anyway
349− // (the stack depth is wrong for the Constructor's
350− // security check to work)
351− java.security.AccessController.doPrivileged(
352− new java.security.PrivilegedAction<Void>() {
353− public Void run() {
354− c.setAccessible(true);
355− return null;
356− }
357− });
358− cachedConstructor = c;
359− } catch (NoSuchMethodException e) {
360− throw new InstantiationException(getName());
361− }
362− }
363− Constructor<T> tmpConstructor = cachedConstructor;
364− // Security check (same as in java.lang.reflect.Constructor)
365− int modifiers = tmpConstructor.getModifiers();
366− if (!Reflection.quickCheckMemberAccess(this, modifiers)) {
367− Class<?> caller = Reflection.getCallerClass(3);
368− if (newInstanceCallerCache != caller) {
369− Reflection.ensureMemberAccess(caller, this, null, modifiers);
370− newInstanceCallerCache = caller;
371− }
372− }
373− // Run constructor
374− try {
375− return tmpConstructor.newInstance((Object[])null);
376− } catch (InvocationTargetException e) {
377− Unsafe.getUnsafe().throwException(e.getTargetException());
378− // Not reached
379− return null;
380− }
381− }
342+ // [Inferno] <
343+ //private T newInstance0()
344+ // throws InstantiationException, IllegalAccessException
345+ //{
346+ // // NOTE: the following code may not be strictly correct under
347+ // // the current Java memory model.
348+//
349+ // // Constructor lookup
350+ // if (cachedConstructor == null) {
351+ // if (this == Class.class) {
352+ // throw new IllegalAccessException(
353+ // "Can not call newInstance() on the Class for java.lang.Class"
354+ // );
355+ // }
356+ // try {
357+ // Class<?>[] empty = {};
358+ // final Constructor<T> c = getConstructor0(empty, Member.DECLARED);
359+ // // Disable accessibility checks on the constructor
360+ // // since we have to do the security check here anyway
361+ // // (the stack depth is wrong for the Constructor's
362+ // // security check to work)
363+ // java.security.AccessController.doPrivileged(
364+ // new java.security.PrivilegedAction<Void>() {
365+ // public Void run() {
366+ // c.setAccessible(true);
367+ // return null;
368+ // }
369+ // });
370+ // cachedConstructor = c;
371+ // } catch (NoSuchMethodException e) {
372+ // throw new InstantiationException(getName());
373+ // }
374+ // }
375+ // Constructor<T> tmpConstructor = cachedConstructor;
376+ // // Security check (same as in java.lang.reflect.Constructor)
377+ // int modifiers = tmpConstructor.getModifiers();
378+ // if (!Reflection.quickCheckMemberAccess(this, modifiers)) {
379+ // Class<?> caller = Reflection.getCallerClass(3);
380+ // if (newInstanceCallerCache != caller) {
381+ // Reflection.ensureMemberAccess(caller, this, null, modifiers);
382+ // newInstanceCallerCache = caller;
383+ // }
384+ // }
385+ // // Run constructor
386+ // try {
387+ // return tmpConstructor.newInstance((Object[])null);
388+ // } catch (InvocationTargetException e) {
389+ // Unsafe.getUnsafe().throwException(e.getTargetException());
390+ // // Not reached
391+ // return null;
392+ // }
393+ //}
394+ // [Inferno] =
395+ private native T newInstance0();
396+ // [Inferno] >
382397 private volatile transient Constructor<T> cachedConstructor;
383398 private volatile transient Class<?> newInstanceCallerCache;
384399
java/pkg/java/lang/Class_L.b+6−1
@@ -54,7 +54,7 @@ forName0_rString_Z_rClassLoader_rClass( p0 : JString,p1 : int,p2 : JObject) : JC · 53 unmodified lines
5454 if (p0.str != nil && p0.str[0] == '[')
5555 return jni->LookupArrayClass(p0.str);
5656 else
57− return jni->GetClassObject(jni->FindClass(p0.str));
57+ return jni->NewClassObject(jni->FindClass(p0.str));
5858 }
5959 exception e {
6060 "JLD:e0*" =>
@@ -316,6 +316,11 @@ desiredAssertionStatus0_rClass_Z( p0 : JClass) : int · 255 unmodified lines
316316 return int 0;
317317 }#<<
318318
319+newInstance0_rObject( this : JClass) : JObject
320+{#>>
321+ return jni->NewObject(this.class);
322+}#<<
323+
319324 #
320325 # getPublicStaticFields() and doInterfaces() are helper
321326 # functions for getFields().
java/pkg/java/lang/Class_L.m+1−0
@@ -32,5 +32,6 @@ Class_L : module · 31 unmodified lines
3232 getDeclaredConstructors0_Z_aConstructor : fn( this : JClass, p0 : int) : JArrayJObject;
3333 getDeclaredClasses0_aClass : fn( this : JClass) : JArrayJClass;
3434 desiredAssertionStatus0_rClass_Z : fn( p0 : JClass) : int;
35+ newInstance0_rObject : fn( this : JClass) : JObject;
3536
3637 };