IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
IKVM.Java.Externs.java.lang.Class Class Reference

Implements the native methods for 'java.lang.Class'. More...

Static Public Member Functions

static global::java.lang.Class forName0 (string name, bool initialize, global::java.lang.ClassLoader loader, global::java.lang.Class caller)
 Implements the native method 'forName0'.
 
static byte[] getRawTypeAnnotations (global::java.lang.Class thisClass)
 Implements the native method 'getRawTypeAnnotations'.
 
static object getConstantPool (global::java.lang.Class self)
 Implements the native method 'getConstantPool'.
 
static bool isInstance (global::java.lang.Class self, object obj)
 Implements the native method 'isInstance'.
 
static bool isAssignableFrom (global::java.lang.Class self, global::java.lang.Class otherClass)
 Implements the native method 'isAssignableFrom'.
 
static bool isInterface (global::java.lang.Class self)
 Implements the native method 'isInterface'.
 
static bool isArray (global::java.lang.Class thisClass)
 
static bool isPrimitive (global::java.lang.Class thisClass)
 
static string getName0 (global::java.lang.Class thisClass)
 
static string getSigName (global::java.lang.Class thisClass)
 
static global::java.lang.ClassLoader getClassLoader0 (global::java.lang.Class thisClass)
 
static global::java.lang.Class getSuperclass (global::java.lang.Class thisClass)
 
static global::java.lang.Class[] getInterfaces0 (global::java.lang.Class thisClass)
 
static global::java.lang.Class getComponentType (global::java.lang.Class thisClass)
 
static int getModifiers (global::java.lang.Class thisClass)
 
static object[] getSigners (global::java.lang.Class thisClass)
 
static void setSigners (global::java.lang.Class thisClass, object[] signers)
 
static object[] getEnclosingMethod0 (global::java.lang.Class thisClass)
 
static global::java.lang.Class getDeclaringClass0 (global::java.lang.Class thisClass)
 
static global::java.security.ProtectionDomain getProtectionDomain0 (global::java.lang.Class thisClass)
 
static global::java.lang.Class getPrimitiveClass (string name)
 Implements the native method for 'getPrimitiveClass'.
 
static string getGenericSignature0 (global::java.lang.Class thisClass)
 
static object getDeclaredAnnotationsImpl (global::java.lang.Class thisClass)
 
static object getDeclaredFields0 (global::java.lang.Class thisClass, bool publicOnly)
 
static object getDeclaredMethods0 (global::java.lang.Class thisClass, bool publicOnly)
 
static object getDeclaredConstructors0 (global::java.lang.Class thisClass, bool publicOnly)
 
static global::java.lang.Class[] getDeclaredClasses0 (global::java.lang.Class thisClass)
 
static bool desiredAssertionStatus0 (global::java.lang.Class clazz)
 

Detailed Description

Implements the native methods for 'java.lang.Class'.

Definition at line 36 of file Class.cs.

Member Function Documentation

◆ desiredAssertionStatus0()

static bool IKVM.Java.Externs.java.lang.Class.desiredAssertionStatus0 ( global.java.lang.Class clazz)
static

Definition at line 662 of file Class.cs.

663 {
664 return IKVM.Runtime.Assertions.IsEnabled(RuntimeJavaType.FromClass(clazz));
665 }

◆ forName0()

static global.java.lang.Class IKVM.Java.Externs.java.lang.Class.forName0 ( string name,
bool initialize,
global.java.lang.ClassLoader loader,
global.java.lang.Class caller )
static

Implements the native method 'forName0'.

Parameters
name
initialize
loader
caller
Returns
Exceptions
global::java.lang.NullPointerException
global::java.lang.ClassNotFoundException

Definition at line 57 of file Class.cs.

58 {
59#if FIRST_PASS
60 throw new NotImplementedException();
61#else
62 if (name == null)
63 throw new global::java.lang.NullPointerException();
64
65 RuntimeJavaType javaType = null;
66 if (name.IndexOf(',') > 0)
67 {
68 // we essentially require full trust before allowing arbitrary types to be loaded,
69 // hence we do the "createClassLoader" permission check
70 var sm = global::java.lang.System.getSecurityManager();
71 sm?.checkPermission(new global::java.lang.RuntimePermission("createClassLoader"));
72
73 var type = Type.GetType(name);
74 if (type != null)
75 javaType = JVM.Context.ClassLoaderFactory.GetJavaTypeFromType(type);
76
77 if (javaType == null)
78 {
79 global::java.lang.Throwable.suppressFillInStackTrace = true;
80 throw new global::java.lang.ClassNotFoundException(name);
81 }
82 }
83 else
84 {
85 try
86 {
87 javaType = JVM.Context.ClassLoaderFactory.GetClassLoaderWrapper(loader).LoadClassByName(name);
88 }
90 {
91 global::java.lang.Throwable.suppressFillInStackTrace = true;
92 throw new global::java.lang.ClassNotFoundException(e.Message);
93 }
94 catch (ClassLoadingException e)
95 {
96 throw e.InnerException;
97 }
99 {
100 throw e.ToJava();
101 }
102 }
103
104 if (loader != null && caller != null && getProtectionDomain0(caller) is global::java.security.ProtectionDomain pd)
105 ClassLoaderAccessor.InvokeCheckPackageAccess(loader, javaType.ClassObject, pd);
106
107 if (initialize && javaType.IsArray == false)
108 {
109 try
110 {
111 javaType.Finish();
112 }
114 {
115 throw e.ToJava();
116 }
117
118 javaType.RunClassInit();
119 }
120
121 return javaType.ClassObject;
122#endif
123 }
IKVM.Reflection.Type Type
static global::java.security.ProtectionDomain getProtectionDomain0(global::java.lang.Class thisClass)
Definition Class.cs:389
This is not a Java exception, but instead it wraps a Java exception that was thrown by a class loader...
Main state of the running JVM.
.NET exception that corresponds to a Java exception.
RuntimeClassLoaderFactory ClassLoaderFactory
Gets the RuntimeClassLoaderFactory associated with this instance of the runtime.

◆ getClassLoader0()

static global.java.lang.ClassLoader IKVM.Java.Externs.java.lang.Class.getClassLoader0 ( global.java.lang.Class thisClass)
static

Definition at line 287 of file Class.cs.

288 {
289 return RuntimeJavaType.FromClass(thisClass).ClassLoader.GetJavaClassLoader();
290 }

◆ getComponentType()

static global.java.lang.Class IKVM.Java.Externs.java.lang.Class.getComponentType ( global.java.lang.Class thisClass)
static

Definition at line 311 of file Class.cs.

312 {
313 var type = RuntimeJavaType.FromClass(thisClass);
314 return type.IsArray ? type.ElementTypeWrapper.ClassObject : null;
315 }

◆ getConstantPool()

static object IKVM.Java.Externs.java.lang.Class.getConstantPool ( global.java.lang.Class self)
static

Implements the native method 'getConstantPool'.

Parameters
self
Returns

Definition at line 184 of file Class.cs.

185 {
186#if FIRST_PASS
187 throw new NotImplementedException();
188#else
189 return new ConstantPoolImpl(RuntimeJavaType.FromClass(self).GetConstantPool());
190#endif
191 }

◆ getDeclaredAnnotationsImpl()

static object IKVM.Java.Externs.java.lang.Class.getDeclaredAnnotationsImpl ( global.java.lang.Class thisClass)
static

Definition at line 504 of file Class.cs.

505 {
506#if FIRST_PASS
507 throw new NotImplementedException();
508#else
509 var type = RuntimeJavaType.FromClass(thisClass);
510
511 try
512 {
513 type.Finish();
514 }
516 {
517 throw x.ToJava();
518 }
519
520 return AnnotationsToMap(type.ClassLoader, type.GetDeclaredAnnotations());
521#endif
522 }

◆ getDeclaredClasses0()

static global.java.lang.Class[] IKVM.Java.Externs.java.lang.Class.getDeclaredClasses0 ( global.java.lang.Class thisClass)
static

Definition at line 631 of file Class.cs.

632 {
633#if FIRST_PASS
634 throw new NotImplementedException();
635#else
636 try
637 {
638 var type = RuntimeJavaType.FromClass(thisClass);
639 type.Finish();
640
641 var innerTypes = type.InnerClasses;
642 var list = new global::java.lang.Class[innerTypes.Length];
643 for (int i = 0; i < list.Length; i++)
644 {
645 var innerType = innerTypes[i].EnsureLoadable(type.ClassLoader);
646 if (innerType.IsAccessibleFrom(type) == false)
647 throw new IllegalAccessError(string.Format("tried to access class {0} from class {1}", innerType.Name, type.Name));
648
649 innerType.Finish();
650 list[i] = innerType.ClassObject;
651 }
652
653 return list;
654 }
656 {
657 throw x.ToJava();
658 }
659#endif
660 }

◆ getDeclaredConstructors0()

static object IKVM.Java.Externs.java.lang.Class.getDeclaredConstructors0 ( global.java.lang.Class thisClass,
bool publicOnly )
static

Definition at line 596 of file Class.cs.

597 {
598#if FIRST_PASS
599 throw new NotImplementedException();
600#else
601 try
602 {
603 var type = RuntimeJavaType.FromClass(thisClass);
604 type.Finish();
605
606 if (type.HasVerifyError)
607 throw new VerifyError();
608
609 if (type.HasClassFormatError)
610 throw new ClassFormatError(type.Name);
611
612 var methods = type.GetMethods();
613 var list = new List<global::java.lang.reflect.Constructor>(methods.Length);
614 foreach (var method in methods)
615 {
616 // we don't want to expose "hideFromReflection" methods (one reason is that it would mess up the serialVersionUID computation)
617 if (method.IsHideFromReflection == false && method.IsConstructor)
618 if (publicOnly == false || method.IsPublic)
619 list.Add((global::java.lang.reflect.Constructor)method.ToMethodOrConstructor(false));
620 }
621
622 return list.ToArray();
623 }
625 {
626 throw x.ToJava();
627 }
628#endif
629 }

◆ getDeclaredFields0()

static object IKVM.Java.Externs.java.lang.Class.getDeclaredFields0 ( global.java.lang.Class thisClass,
bool publicOnly )
static

Definition at line 524 of file Class.cs.

525 {
526#if FIRST_PASS
527 throw new NotImplementedException();
528#else
529 try
530 {
531 var type = RuntimeJavaType.FromClass(thisClass);
532 type.Finish();
533
534 var fields = type.GetFields();
535 var list = new List<global::java.lang.reflect.Field>(fields.Length);
536
537 for (int i = 0; i < fields.Length; i++)
538 {
539 if (fields[i].IsHideFromReflection)
540 {
541 // skip
542 }
543 else if (publicOnly && !fields[i].IsPublic)
544 {
545 // caller is only asking for public field, so we don't return this non-public field
546 }
547 else
548 {
549 list.Add((global::java.lang.reflect.Field)fields[i].ToField(false, i));
550 }
551 }
552
553 return list.ToArray();
554 }
556 {
557 throw x.ToJava();
558 }
559#endif
560 }

◆ getDeclaredMethods0()

static object IKVM.Java.Externs.java.lang.Class.getDeclaredMethods0 ( global.java.lang.Class thisClass,
bool publicOnly )
static

Definition at line 562 of file Class.cs.

563 {
564#if FIRST_PASS
565 throw new NotImplementedException();
566#else
567 try
568 {
569 var type = RuntimeJavaType.FromClass(thisClass);
570 type.Finish();
571
572 if (type.HasVerifyError)
573 throw new VerifyError();
574
575 if (type.HasClassFormatError)
576 throw new ClassFormatError(type.Name);
577
578 var methods = type.GetMethods();
579 var list = new List<global::java.lang.reflect.Method>(methods.Length);
580 foreach (var method in methods)
581 {
582 // we don't want to expose "hideFromReflection" methods (one reason is that it would mess up the serialVersionUID computation)
583 if (!method.IsHideFromReflection && !method.IsConstructor && !method.IsClassInitializer && (!publicOnly || method.IsPublic))
584 list.Add((global::java.lang.reflect.Method)method.ToMethodOrConstructor(false));
585 }
586
587 return list.ToArray();
588 }
590 {
591 throw x.ToJava();
592 }
593#endif
594 }

◆ getDeclaringClass0()

static global.java.lang.Class IKVM.Java.Externs.java.lang.Class.getDeclaringClass0 ( global.java.lang.Class thisClass)
static

Definition at line 360 of file Class.cs.

361 {
362 try
363 {
364 var type = RuntimeJavaType.FromClass(thisClass);
365 type.Finish();
366
367 var declaringType = type.DeclaringTypeWrapper;
368 if (declaringType == null)
369 return null;
370
371 declaringType = declaringType.EnsureLoadable(type.ClassLoader);
372 if (declaringType.IsAccessibleFrom(type) == false)
373 throw new IllegalAccessError(string.Format("tried to access class {0} from class {1}", declaringType.Name, type.Name));
374
375 declaringType.Finish();
376
377 foreach (var declaringTypeInnerType in declaringType.InnerClasses)
378 if (declaringTypeInnerType.Name == type.Name && declaringTypeInnerType.EnsureLoadable(declaringType.ClassLoader) == type)
379 return declaringType.ClassObject;
380
381 throw new IncompatibleClassChangeError(string.Format("{0} and {1} disagree on InnerClasses attribute", declaringType.Name, type.Name));
382 }
384 {
385 throw x.ToJava();
386 }
387 }

◆ getEnclosingMethod0()

static object[] IKVM.Java.Externs.java.lang.Class.getEnclosingMethod0 ( global.java.lang.Class thisClass)
static

Definition at line 341 of file Class.cs.

342 {
343 try
344 {
345 var type = RuntimeJavaType.FromClass(thisClass);
346 type.Finish();
347
348 var enc = type.GetEnclosingMethod();
349 if (enc == null)
350 return null;
351
352 return [type.ClassLoader.LoadClassByName(enc[0]).ClassObject, enc[1], enc[2]?.Replace('.', '/')];
353 }
355 {
356 throw x.ToJava();
357 }
358 }

◆ getGenericSignature0()

static string IKVM.Java.Externs.java.lang.Class.getGenericSignature0 ( global.java.lang.Class thisClass)
static

Definition at line 450 of file Class.cs.

451 {
452 var type = RuntimeJavaType.FromClass(thisClass);
453 type.Finish();
454 return type.GetGenericSignature();
455 }

◆ getInterfaces0()

static global.java.lang.Class[] IKVM.Java.Externs.java.lang.Class.getInterfaces0 ( global.java.lang.Class thisClass)
static

Definition at line 297 of file Class.cs.

298 {
299#if FIRST_PASS
300 throw new NotImplementedException();
301#else
302 var ifaces = RuntimeJavaType.FromClass(thisClass).Interfaces;
303 var interfaces = new global::java.lang.Class[ifaces.Length];
304 for (int i = 0; i < ifaces.Length; i++)
305 interfaces[i] = ifaces[i].ClassObject;
306
307 return interfaces;
308#endif
309 }

◆ getModifiers()

static int IKVM.Java.Externs.java.lang.Class.getModifiers ( global.java.lang.Class thisClass)
static

Definition at line 317 of file Class.cs.

318 {
319 // the 0x7FFF mask comes from JVM_ACC_WRITTEN_FLAGS in hotspot\src\share\vm\utilities\accessFlags.hpp
320 // masking out ACC_SUPER comes from instanceKlass::compute_modifier_flags() in hotspot\src\share\vm\oops\instanceKlass.cpp
321 const int mask = 0x7FFF & (int)~IKVM.Attributes.Modifiers.Super;
322 return (int)RuntimeJavaType.FromClass(thisClass).ReflectiveModifiers & mask;
323 }

◆ getName0()

static string IKVM.Java.Externs.java.lang.Class.getName0 ( global.java.lang.Class thisClass)
static

Definition at line 243 of file Class.cs.

244 {
245#if FIRST_PASS
246 throw new NotImplementedException();
247#else
248 var type = RuntimeJavaType.FromClass(thisClass);
249 if (type.IsPrimitive)
250 {
251 if (type == JVM.Context.PrimitiveJavaTypeFactory.BYTE)
252 return "byte";
253 else if (type == JVM.Context.PrimitiveJavaTypeFactory.CHAR)
254 return "char";
255 else if (type == JVM.Context.PrimitiveJavaTypeFactory.DOUBLE)
256 return "double";
257 else if (type == JVM.Context.PrimitiveJavaTypeFactory.FLOAT)
258 return "float";
259 else if (type == JVM.Context.PrimitiveJavaTypeFactory.INT)
260 return "int";
261 else if (type == JVM.Context.PrimitiveJavaTypeFactory.LONG)
262 return "long";
263 else if (type == JVM.Context.PrimitiveJavaTypeFactory.SHORT)
264 return "short";
265 else if (type == JVM.Context.PrimitiveJavaTypeFactory.BOOLEAN)
266 return "boolean";
267 else if (type == JVM.Context.PrimitiveJavaTypeFactory.VOID)
268 return "void";
269 }
270
271 if (type.IsUnsafeAnonymous)
272 {
273 // for OpenJDK compatibility and debugging convenience we modify the class name to
274 // include the identity hashcode of the class object
275 return type.Name + "/" + global::java.lang.System.identityHashCode(thisClass);
276 }
277
278 return type.Name;
279#endif
280 }
RuntimePrimitiveJavaTypeFactory PrimitiveJavaTypeFactory
Gets the RuntimePrimitiveJavaTypeFactory associated with this instance of the runtime.

◆ getPrimitiveClass()

static global.java.lang.Class IKVM.Java.Externs.java.lang.Class.getPrimitiveClass ( string name)
static

Implements the native method for 'getPrimitiveClass'.

This method isn't used anymore (because it is an intrinsic (during core class library compilation)) it still remains for compat because it might be invoked through reflection by evil code

Parameters
name
Returns
Exceptions
ArgumentException

Definition at line 429 of file Class.cs.

430 {
431#if FIRST_PASS
432 throw new NotImplementedException();
433#else
434 return name switch
435 {
436 "byte" => JVM.Context.PrimitiveJavaTypeFactory.BYTE.ClassObject,
437 "char" => JVM.Context.PrimitiveJavaTypeFactory.CHAR.ClassObject,
438 "double" => JVM.Context.PrimitiveJavaTypeFactory.DOUBLE.ClassObject,
439 "float" => JVM.Context.PrimitiveJavaTypeFactory.FLOAT.ClassObject,
440 "int" => JVM.Context.PrimitiveJavaTypeFactory.INT.ClassObject,
441 "long" => JVM.Context.PrimitiveJavaTypeFactory.LONG.ClassObject,
442 "short" => JVM.Context.PrimitiveJavaTypeFactory.SHORT.ClassObject,
443 "boolean" => JVM.Context.PrimitiveJavaTypeFactory.BOOLEAN.ClassObject,
444 "void" => JVM.Context.PrimitiveJavaTypeFactory.VOID.ClassObject,
445 _ => throw new ArgumentException(name),
446 };
447#endif
448 }

◆ getProtectionDomain0()

static global.java.security.ProtectionDomain IKVM.Java.Externs.java.lang.Class.getProtectionDomain0 ( global.java.lang.Class thisClass)
static

Definition at line 389 of file Class.cs.

390 {
391#if FIRST_PASS
392 throw new NotImplementedException();
393#else
394 var type = RuntimeJavaType.FromClass(thisClass);
395 if (type.IsArray)
396 return null;
397
398 var pd = type.ClassObject.pd;
399 if (pd == null)
400 {
401 // The protection domain for statically compiled code is created lazily (not at global::java.lang.Class creation time),
402 // to work around boot strap issues.
403 if (type.ClassLoader is RuntimeAssemblyClassLoader acl)
404 {
405 pd = acl.GetProtectionDomain();
406 }
407 else if (type is RuntimeAnonymousJavaType)
408 {
409 // dynamically compiled intrinsified lamdba anonymous types end up here and should get their
410 // protection domain from the host class
411 pd = JVM.Context.ClassLoaderFactory.GetJavaTypeFromType(type.TypeAsTBD.DeclaringType).ClassObject.pd;
412 }
413 }
414
415 return pd;
416#endif
417 }
Represents an intrinsified anonymous class. Currently only used by LambdaMetafactory.

◆ getRawTypeAnnotations()

static byte[] IKVM.Java.Externs.java.lang.Class.getRawTypeAnnotations ( global.java.lang.Class thisClass)
static

Implements the native method 'getRawTypeAnnotations'.

Parameters
thisClass
Returns

Definition at line 130 of file Class.cs.

131 {
132 return RuntimeJavaType.FromClass(thisClass).GetRawTypeAnnotations();
133 }

◆ getSigName()

static string IKVM.Java.Externs.java.lang.Class.getSigName ( global.java.lang.Class thisClass)
static

Definition at line 282 of file Class.cs.

283 {
284 return RuntimeJavaType.FromClass(thisClass).SigName;
285 }

◆ getSigners()

static object[] IKVM.Java.Externs.java.lang.Class.getSigners ( global.java.lang.Class thisClass)
static

Definition at line 325 of file Class.cs.

326 {
327#if FIRST_PASS
328 throw new NotImplementedException();
329#else
330 return thisClass.signers;
331#endif
332 }

◆ getSuperclass()

static global.java.lang.Class IKVM.Java.Externs.java.lang.Class.getSuperclass ( global.java.lang.Class thisClass)
static

Definition at line 292 of file Class.cs.

293 {
294 return RuntimeJavaType.FromClass(thisClass).BaseTypeWrapper?.ClassObject;
295 }

◆ isArray()

static bool IKVM.Java.Externs.java.lang.Class.isArray ( global.java.lang.Class thisClass)
static

Definition at line 233 of file Class.cs.

234 {
235 return RuntimeJavaType.FromClass(thisClass).IsArray;
236 }

◆ isAssignableFrom()

static bool IKVM.Java.Externs.java.lang.Class.isAssignableFrom ( global.java.lang.Class self,
global.java.lang.Class otherClass )
static

Implements the native method 'isAssignableFrom'.

Parameters
self
otherClass
Returns
Exceptions
global::java.lang.NullPointerException

Definition at line 211 of file Class.cs.

212 {
213#if FIRST_PASS
214 throw new NotImplementedException();
215#else
216 if (otherClass == null)
217 throw new global::java.lang.NullPointerException();
218
219 return RuntimeJavaType.FromClass(otherClass).IsAssignableTo(RuntimeJavaType.FromClass(self));
220#endif
221 }

◆ isInstance()

static bool IKVM.Java.Externs.java.lang.Class.isInstance ( global.java.lang.Class self,
object obj )
static

Implements the native method 'isInstance'.

Parameters
self
obj
Returns

Definition at line 199 of file Class.cs.

200 {
201 return RuntimeJavaType.FromClass(self).IsInstance(obj);
202 }

◆ isInterface()

static bool IKVM.Java.Externs.java.lang.Class.isInterface ( global.java.lang.Class self)
static

Implements the native method 'isInterface'.

Parameters
self
Returns

Definition at line 228 of file Class.cs.

229 {
230 return RuntimeJavaType.FromClass(self).IsInterface;
231 }

◆ isPrimitive()

static bool IKVM.Java.Externs.java.lang.Class.isPrimitive ( global.java.lang.Class thisClass)
static

Definition at line 238 of file Class.cs.

239 {
240 return RuntimeJavaType.FromClass(thisClass).IsPrimitive;
241 }

◆ setSigners()

static void IKVM.Java.Externs.java.lang.Class.setSigners ( global.java.lang.Class thisClass,
object[] signers )
static

Definition at line 334 of file Class.cs.

335 {
336#if !FIRST_PASS
337 thisClass.signers = signers;
338#endif
339 }

The documentation for this class was generated from the following file: