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/pkg (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
117 java.lang.reflect.GenericDeclaration,117 java.lang.reflect.GenericDeclaration,
118 java.lang.reflect.Type,118 java.lang.reflect.Type,
119 java.lang.reflect.AnnotatedElement {119 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
120 private static final int ANNOTATION= 0x00002000;128 private static final int ANNOTATION= 0x00002000;
121 private static final int ENUM = 0x00004000;129 private static final int ENUM = 0x00004000;
122 private static final int SYNTHETIC = 0x00001000;130 private static final int SYNTHETIC = 0x00001000;
@@ -254,16 +262,19 @@ public final · 131 unmodified lines
254 ClassLoader loader)262 ClassLoader loader)
255 throws ClassNotFoundException263 throws ClassNotFoundException
256 {264 {
257 if (loader == null) {265 // [Inferno] <
258 SecurityManager sm = System.getSecurityManager();266 //if (loader == null) {
259 if (sm != null) {267 // SecurityManager sm = System.getSecurityManager();
260 ClassLoader ccl = ClassLoader.getCallerClassLoader();268 // if (sm != null) {
261 if (ccl != null) {269 // ClassLoader ccl = ClassLoader.getCallerClassLoader();
262 sm.checkPermission(270 // if (ccl != null) {
263 SecurityConstants.GET_CLASSLOADER_PERMISSION);271 // sm.checkPermission(
264 }272 // SecurityConstants.GET_CLASSLOADER_PERMISSION);
265 }273 // }
266 }274 // }
275 //}
276 // [Inferno] =
277 // [Inferno] >
267 return forName0(name, initialize, loader);278 return forName0(name, initialize, loader);
268 }279 }
269 280
@@ -328,57 +339,61 @@ public final · 58 unmodified lines
328 return newInstance0();339 return newInstance0();
329 }340 }
330 341
331 private T newInstance0()342 // [Inferno] <
332 throws InstantiationException, IllegalAccessException343 //private T newInstance0()
333 {344 // throws InstantiationException, IllegalAccessException
334 // NOTE: the following code may not be strictly correct under345 //{
335 // the current Java memory model.346 // // NOTE: the following code may not be strictly correct under
336 347 // // the current Java memory model.
337 // Constructor lookup348//
338 if (cachedConstructor == null) {349 // // Constructor lookup
339 if (this == Class.class) {350 // if (cachedConstructor == null) {
340 throw new IllegalAccessException(351 // if (this == Class.class) {
341 "Can not call newInstance() on the Class for java.lang.Class"352 // throw new IllegalAccessException(
342 );353 // "Can not call newInstance() on the Class for java.lang.Class"
343 }354 // );
344 try {355 // }
345 Class<?>[] empty = {};356 // try {
346 final Constructor<T> c = getConstructor0(empty, Member.DECLARED);357 // Class<?>[] empty = {};
347 // Disable accessibility checks on the constructor358 // final Constructor<T> c = getConstructor0(empty, Member.DECLARED);
348 // since we have to do the security check here anyway359 // // Disable accessibility checks on the constructor
349 // (the stack depth is wrong for the Constructor's360 // // since we have to do the security check here anyway
350 // security check to work)361 // // (the stack depth is wrong for the Constructor's
351 java.security.AccessController.doPrivileged(362 // // security check to work)
352 new java.security.PrivilegedAction<Void>() {363 // java.security.AccessController.doPrivileged(
353 public Void run() {364 // new java.security.PrivilegedAction<Void>() {
354 c.setAccessible(true);365 // public Void run() {
355 return null;366 // c.setAccessible(true);
356 }367 // return null;
357 });368 // }
358 cachedConstructor = c;369 // });
359 } catch (NoSuchMethodException e) {370 // cachedConstructor = c;
360 throw new InstantiationException(getName());371 // } catch (NoSuchMethodException e) {
361 }372 // throw new InstantiationException(getName());
362 }373 // }
363 Constructor<T> tmpConstructor = cachedConstructor;374 // }
364 // Security check (same as in java.lang.reflect.Constructor)375 // Constructor<T> tmpConstructor = cachedConstructor;
365 int modifiers = tmpConstructor.getModifiers();376 // // Security check (same as in java.lang.reflect.Constructor)
366 if (!Reflection.quickCheckMemberAccess(this, modifiers)) {377 // int modifiers = tmpConstructor.getModifiers();
367 Class<?> caller = Reflection.getCallerClass(3);378 // if (!Reflection.quickCheckMemberAccess(this, modifiers)) {
368 if (newInstanceCallerCache != caller) {379 // Class<?> caller = Reflection.getCallerClass(3);
369 Reflection.ensureMemberAccess(caller, this, null, modifiers);380 // if (newInstanceCallerCache != caller) {
370 newInstanceCallerCache = caller;381 // Reflection.ensureMemberAccess(caller, this, null, modifiers);
371 }382 // newInstanceCallerCache = caller;
372 }383 // }
373 // Run constructor384 // }
374 try {385 // // Run constructor
375 return tmpConstructor.newInstance((Object[])null);386 // try {
376 } catch (InvocationTargetException e) {387 // return tmpConstructor.newInstance((Object[])null);
377 Unsafe.getUnsafe().throwException(e.getTargetException());388 // } catch (InvocationTargetException e) {
378 // Not reached389 // Unsafe.getUnsafe().throwException(e.getTargetException());
379 return null;390 // // Not reached
380 }391 // return null;
381 }392 // }
393 //}
394 // [Inferno] =
395 private native T newInstance0();
396 // [Inferno] >
382 private volatile transient Constructor<T> cachedConstructor;397 private volatile transient Constructor<T> cachedConstructor;
383 private volatile transient Class<?> newInstanceCallerCache;398 private volatile transient Class<?> newInstanceCallerCache;
384 399
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
54 if (p0.str != nil && p0.str[0] == '[')54 if (p0.str != nil && p0.str[0] == '[')
55 return jni->LookupArrayClass(p0.str);55 return jni->LookupArrayClass(p0.str);
56 else56 else
57 return jni->GetClassObject(jni->FindClass(p0.str));57 return jni->NewClassObject(jni->FindClass(p0.str));
58 }58 }
59 exception e {59 exception e {
60 "JLD:e0*" =>60 "JLD:e0*" =>
@@ -316,6 +316,11 @@ desiredAssertionStatus0_rClass_Z( p0 : JClass) : int · 255 unmodified lines
316 return int 0;316 return int 0;
317}#<<317}#<<
318 318
319newInstance0_rObject( this : JClass) : JObject
320{#>>
321 return jni->NewObject(this.class);
322}#<<
323
319#324#
320# getPublicStaticFields() and doInterfaces() are helper325# getPublicStaticFields() and doInterfaces() are helper
321# functions for getFields().326# functions for getFields().
java/pkg/java/lang/Class_L.m+1−0
@@ -32,5 +32,6 @@ Class_L : module · 31 unmodified lines
32 getDeclaredConstructors0_Z_aConstructor : fn( this : JClass, p0 : int) : JArrayJObject;32 getDeclaredConstructors0_Z_aConstructor : fn( this : JClass, p0 : int) : JArrayJObject;
33 getDeclaredClasses0_aClass : fn( this : JClass) : JArrayJClass;33 getDeclaredClasses0_aClass : fn( this : JClass) : JArrayJClass;
34 desiredAssertionStatus0_rClass_Z : fn( p0 : JClass) : int;34 desiredAssertionStatus0_rClass_Z : fn( p0 : JClass) : int;
35 newInstance0_rObject : fn( this : JClass) : JObject;
35 36
36};37};