// private static native String getSystemPackage0(String name); // (Ljava/lang/String;)Ljava/lang/String; func getSystemPackage0(frame *rtda.Frame) { // vars := frame.LocalVars() // name := vars.GetRef(0) sysPkg := frame.ClassLoader().JLObjectClass().LoadedFrom().String() sysPkgObj := rtda.JString(sysPkg) stack := frame.OperandStack() stack.PushRef(sysPkgObj) }
// static native Class<?> getPrimitiveClass(String name); // (Ljava/lang/String;)Ljava/lang/Class; func getPrimitiveClass(frame *rtda.Frame) { vars := frame.LocalVars() nameObj := vars.GetRef(0) name := rtda.GoString(nameObj) classLoader := frame.ClassLoader() class := classLoader.GetPrimitiveClass(name) classObj := class.JClass() stack := frame.OperandStack() stack.PushRef(classObj) }
// private native Object[] getEnclosingMethod0(); // ()[Ljava/lang/Object; func getEnclosingMethod0(frame *rtda.Frame) { class := _popClass(frame) if class.IsPrimitive() { frame.OperandStack().PushNull() } else { emInfo := class.EnclosingMethod() emInfoObj := _createEnclosintMethodInfo(frame.ClassLoader(), emInfo) if emInfoObj == nil || rtc.ArrayLength(emInfoObj) == 0 { frame.OperandStack().PushNull() } else { frame.OperandStack().PushRef(emInfoObj) } } }
// public native ByteBuffer createLong(String name, int variability, int units, long value); // (Ljava/lang/String;IIJ)Ljava/nio/ByteBuffer; func createLong(frame *rtda.Frame) { bbClass := frame.ClassLoader().LoadClass("java/nio/ByteBuffer") if bbClass.InitializationNotStarted() { frame.RevertNextPC() frame.Thread().InitClass(bbClass) return } stack := frame.OperandStack() stack.PushInt(8) allocate := bbClass.GetStaticMethod("allocate", "(I)Ljava/nio/ByteBuffer;") frame.Thread().InvokeMethod(allocate) }
// public static native FileSystem getFileSystem() // ()Ljava/io/FileSystem; func getFileSystem(frame *rtda.Frame) { thread := frame.Thread() unixFsClass := frame.ClassLoader().LoadClass("java/io/UnixFileSystem") if unixFsClass.InitializationNotStarted() { frame.SetNextPC(thread.PC()) // undo getFileSystem thread.InitClass(unixFsClass) return } stack := frame.OperandStack() unixFsObj := unixFsClass.NewObj() stack.PushRef(unixFsObj) // call <init> stack.PushRef(unixFsObj) // this constructor := unixFsClass.GetDefaultConstructor() thread.InvokeMethod(constructor) }
// private native Class<?> getDeclaringClass0(); // ()Ljava/lang/Class; func getDeclaringClass0(frame *rtda.Frame) { class := _popClass(frame) if class.IsArray() || class.IsPrimitive() { frame.OperandStack().PushRef(nil) return } lastDollerIndex := strings.LastIndex(class.Name(), "$") if lastDollerIndex < 0 { frame.OperandStack().PushRef(nil) return } // todo declaringClassName := class.Name()[:lastDollerIndex] declaringClass := frame.ClassLoader().LoadClass(declaringClassName) frame.OperandStack().PushRef(declaringClass.JClass()) }
func _loadClass(frame *rtda.Frame) { vars := frame.LocalVars() //loader := vars.GetRef(0) nameObj := vars.GetRef(1) byteArr := vars.GetRef(2) off := vars.GetInt(3) _len := vars.GetInt(4) name := rtda.GoString(nameObj) name = heap.DotToSlash(name) data := byteArr.GoBytes() data = data[off : off+_len] // todo class := frame.ClassLoader().DefineClass(name, data) stack := frame.OperandStack() stack.PushRef(class.JClass()) }
func createStackTraceElementObj(ste *StackTraceElement, frame *rtda.Frame) *heap.Object { declaringClass := rtda.JString(ste.declaringClass) methodName := rtda.JString(ste.methodName) fileName := rtda.JString(ste.fileName) lineNumber := int32(ste.lineNumber) /* public StackTraceElement(String declaringClass, String methodName, String fileName, int lineNumber) */ steClass := frame.ClassLoader().LoadClass("java/lang/StackTraceElement") steObj := steClass.NewObj() // todo: call <init> steObj.SetFieldValue("declaringClass", "Ljava/lang/String;", declaringClass) steObj.SetFieldValue("methodName", "Ljava/lang/String;", methodName) steObj.SetFieldValue("fileName", "Ljava/lang/String;", fileName) steObj.SetFieldValue("lineNumber", "I", lineNumber) return steObj }
// private static native Class<?> forName0(String name, boolean initialize, // ClassLoader loader, // Class<?> caller) // throws ClassNotFoundException; // (Ljava/lang/String;ZLjava/lang/ClassLoader;Ljava/lang/Class;)Ljava/lang/Class; func forName0(frame *rtda.Frame) { vars := frame.LocalVars() jName := vars.GetRef(0) initialize := vars.GetBoolean(1) //jLoader := vars.GetRef(2) goName := rtda.GoString(jName) goName = jutil.ReplaceAll(goName, ".", "/") goClass := frame.ClassLoader().LoadClass(goName) jClass := goClass.JClass() if initialize && goClass.InitializationNotStarted() { // undo forName0 thread := frame.Thread() frame.SetNextPC(thread.PC()) // init class thread.InitClass(goClass) } else { stack := frame.OperandStack() stack.PushRef(jClass) } }