vmtype.java
来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 1,918 行 · 第 1/4 页
JAVA
1,918 行
case 'J':
return LongArrayClass;
case 'D':
return DoubleArrayClass;
default:
throw new IllegalArgumentException("Unknown type " + type);
}
}
/**
* Gets the primitive array class corresponding to the given (newarray)
* type.
*
* @param type
* @return VmClass
*/
public final static VmArrayClass getPrimitiveArrayClass(int type) {
switch (type) {
case 4:
return BooleanArrayClass;
case 8:
return ByteArrayClass;
case 5:
return CharArrayClass;
case 9:
return ShortArrayClass;
case 10:
return IntArrayClass;
case 6:
return FloatArrayClass;
case 11:
return LongArrayClass;
case 7:
return DoubleArrayClass;
default:
throw new IllegalArgumentException("Unknown type " + type);
}
}
/**
* Gets the size in bytes of instances of this object on the stack.
*
* @return 0..8
*/
public final int getTypeSize() {
return typeSize;
}
/**
* Return the corresponding java.lang.Class for this VmClass. During build
* environment the Class will be loaded by Class.forName
*
* @return The class
*/
public final Class asClass() {
return asClass(false);
}
/**
* Return the corresponding java.lang.Class for this VmClass. During build
* environment the Class will be loaded by Class.forName
*
* @return The class
*/
public final Class asClassDuringBootstrap() {
return asClass(true);
}
/**
* Return the corresponding java.lang.Class for this VmClass. During build
* environment the Class will be loaded by Class.forName
*
* @param isBuildEnv
* @return The class
*/
private final Class asClass(boolean isBuildEnv) {
if (javaClass == null) {
if (isBuildEnv) {
try {
javaClass = Class.forName(getName());
} catch (ClassNotFoundException ex) { /* ignore */
}
} else {
javaClass = new Class(this);
}
}
return javaClass;
}
/**
* Return the super class of this class or return null for java.lang.Object
*
* @return The class
*/
public final VmNormalClass getSuperClass() {
if (superClass != null) {
return superClass;
} else if (superClassName == null) {
// java.lang.Object
return null;
} else {
throw new RuntimeException(
"getSuperClass called too early in class " + name);
}
}
/**
* Return the name of this class
*
* @return The name of this class
*/
public final String getName() {
return name;
}
/**
* Convert myself into a String representation
*
* @return The mangled name
*/
public final String getMangledName() {
if (mangledName == null) {
mangledName = mangleClassName(name);
}
return mangledName;
}
/**
* Returns the second character of the name of this class
*
* @return char
*/
public char getSecondNameChar() {
return name.charAt(1);
}
/**
* Is my name equal to the given array of characters?
*
* @param otherName
* @return boolean
*/
public boolean nameEquals(char[] otherName) {
return name.equals(otherName);
}
/**
* Is my name equal to the given String?
*
* @param otherName
* @return boolean
*/
public boolean nameEquals(String otherName) {
return name.equals(otherName);
}
/**
* Is my name equal to the given array of characters?
*
* @param classRef
* @return boolean
*/
public boolean nameEquals(VmConstClass classRef) {
return name.equals(classRef.getClassName());
}
public final String toString() {
return "_CL_" + mangleClassName(getName());
}
/**
* Return the number of fields declared in this class
*
* @return int
*/
public final int getNoDeclaredFields() {
return (fieldTable == null) ? 0 : fieldTable.length;
}
/**
* Return the declared field with a given index (0..getNoFields()-1)
*
* @param index
* @return The field
*/
public final VmField getDeclaredField(int index) {
return fieldTable[ index];
}
/**
* Determines if the class or interface represented by this Class object is
* either the same as, or is a superclass or superinterface of, the class
* or interface represented by the specified Class parameter. It returns
* true if so; otherwise it returns false. If this Class object represents
* a primitive type, this method returns true if the specified Class
* parameter is exactly this Class object; otherwise it returns false.
* Specifically, this method tests whether the type represented by the
* specified Class parameter can be converted to the type represented by
* this Class object via an identity conversion or via a widening reference
* conversion. See The Java Language Specification, sections 5.1.1 and
* 5.1.4, for details.
*
* @param S
* @return boolean
*/
public boolean isAssignableFrom(VmType S) {
final VmType[] superClassesArray = S.superClassesArray;
final int length = superClassesArray.length;
for (int i = 0; i < length; i++) {
if (superClassesArray[ i] == this) { return true; }
}
return false;
}
/**
* Is this type public.
*
* @return boolean
*/
public final boolean isPublic() {
return Modifier.isPublic(modifiers);
}
/**
* Is this type public.
*
* @return boolean
*/
public final boolean isProtected() {
return Modifier.isProtected(modifiers);
}
/**
* Is this type public.
*
* @return boolean
*/
public final boolean isPrivate() {
return Modifier.isPrivate(modifiers);
}
/**
* Is this type public.
*
* @return boolean
*/
public final boolean isStatic() {
return Modifier.isStatic(modifiers);
}
/**
* Is this type public.
*
* @return boolean
*/
public final boolean isFinal() {
return Modifier.isFinal(modifiers);
}
/**
* Is this type an interface.
*
* @return boolean
*/
public final boolean isInterface() {
return Modifier.isInterface(modifiers);
}
/**
* Is this type abstract.
*
* @return boolean
*/
public final boolean isAbstract() {
return Modifier.isAbstract(modifiers);
}
/**
* Is this type loaded.
*
* @return boolean
*/
final boolean isLoaded() {
return ((state & VmTypeState.ST_LOADED) != 0);
}
/**
* Is this type invalid.
*
* @return boolean
*/
public final boolean isInvalid() {
return ((state & VmTypeState.ST_INVALID) != 0);
}
/**
* Is this type verifying.
*
* @return boolean
*/
public final boolean isVerifying() {
return ((state & VmTypeState.ST_VERIFYING) != 0);
}
/**
* Is this type verified.
*
* @return boolean
*/
public final boolean isVerified() {
return ((state & VmTypeState.ST_VERIFIED) != 0);
}
/**
* Is this type preparing.
*
* @return boolean
*/
private final boolean isPreparing() {
return ((state & VmTypeState.ST_PREPARING) != 0);
}
/**
* Is this type prepared.
*
* @return boolean
*/
final boolean isPrepared() {
return ((state & VmTypeState.ST_PREPARED) != 0);
}
/**
* Is this type compiling.
*
* @return boolean
*/
final boolean isCompiling() {
return ((state & VmTypeState.ST_COMPILING) != 0);
}
/**
* Is this type compiled.
*
* @return boolean
*/
public final boolean isCompiled() {
return ((state & VmTypeState.ST_COMPILED) != 0);
}
/**
* Is this type initializing.
*
* @return boolean
*/
final boolean isInitializing() {
return ((state & VmTypeState.ST_INITIALIZING) != 0);
}
/**
* Is this type initialized.
*
* @return boolean
*/
public final boolean isInitialized() {
return ((state & VmTypeState.ST_INITIALIZED) != 0);
}
/**
* Is this type an array.
*
* @return boolean
*/
public boolean isArray() {
return false;
}
/**
* Does this class have a finalize method other then in java.lang.Object.
*
* @return boolean
*/
public final boolean hasFinalizer() {
return ((modifiers & Modifier.ACC_FINALIZER) != 0);
}
/**
* Gets the finalize method of this class.
*/
public final VmMethod getFinalizeMethod() {
return finalizeMethod;
}
/**
* Get the number of interfaces implemented by this class, or its
* super-classes.
*
* @return int
*/
public final int getNoInterfaces() {
return (allInterfaceTable == null) ? 0 : allInterfaceTable.length;
}
/**
* Get on of the list of interfaces implemented by this class, or its
* super-classes.
*
* @param index
* @return class
*/
public final VmInterfaceClass getInterface(int index) {
return allInterfaceTable[ index];
}
/**
* Get the number of implementing interfaces declared in this class
*
* @return int
*/
public final int getNoDeclaredInterfaces() {
return (interfaceTable == null) ? 0 : interfaceTable.length;
}
/**
* Get the number of methods declared in this class
*
* @return int
*/
public final int getNoDeclaredMethods() {
return (methodTable == null) ? 0 : methodTable.length;
}
/**
* Return the declared method with a given index (0..getNoMethods()-1)
*
* @param index
* @return The method
*/
public final VmMethod getDeclaredMethod(int index) {
return methodTable[ index];
}
/**
* Gets the index of the given method within this class.
*
* @param method
* @return The index of the given method within this class or -1 if not
* found.
*/
public final int indexOf(VmMethod method) {
final int max = getNoDeclaredMethods();
for (int i = 0; i < max; i++) {
if (methodTable[ i] == method) { return i; }
}
return -1;
}
/**
* Return the constants pool of this class
*
* @return The constant pool
*/
public final VmCP getCP() {
return cp;
}
/**
* Return the loader of this class
*
* @return The loader
*/
public final VmClassLoader getLoader() {
return loader;
}
/**
* Return the accessflags of this class
*
* @return The modifiers
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?