// private static native void setIn0(InputStream in); // (Ljava/io/InputStream;)V func setIn0(frame *rtda.Frame) { vars := frame.LocalVars() in := vars.GetRef(0) sysClass := frame.Method().Class() sysClass.SetStaticValue("in", "Ljava/io/InputStream;", in) }
// private static native void setOut0(PrintStream out); // (Ljava/io/PrintStream;)V func setOut0(frame *rtda.Frame) { vars := frame.LocalVars() out := vars.GetRef(0) sysClass := frame.Method().Class() sysClass.SetStaticValue("out", "Ljava/io/PrintStream;", out) }
func (self *ATHROW) Execute(frame *rtda.Frame) { ex := frame.OperandStack().PopRef() if ex == nil { frame.Thread().ThrowNPE() return } thread := frame.Thread() for { frame := thread.CurrentFrame() pc := frame.NextPC() - 1 handler := frame.Method().FindExceptionHandler(ex.Class(), pc) if handler != nil { stack := frame.OperandStack() stack.Clear() stack.PushRef(ex) frame.SetNextPC(handler.HandlerPc()) return } thread.PopFrame() if thread.IsStackEmpty() { break } } thread.HandleUncaughtException(ex) }
// private static native void setErr0(PrintStream err); // (Ljava/io/PrintStream;)V func setErr0(frame *rtda.Frame) { vars := frame.LocalVars() err := vars.GetRef(0) sysClass := frame.Method().Class() sysClass.SetStaticValue("err", "Ljava/io/PrintStream;", err) }
func (self *INVOKE_SPECIAL) Execute(frame *rtda.Frame) { cp := frame.Method().Class().ConstantPool() k := cp.GetConstant(self.Index) if kMethodRef, ok := k.(*heap.ConstantMethodref); ok { method := kMethodRef.SpecialMethod() frame.Thread().InvokeMethod(method) } else { method := k.(*heap.ConstantInterfaceMethodref).SpecialMethod() frame.Thread().InvokeMethod(method) } }
func (self *INVOKE_DYNAMIC) resolveCallSiteSpecifier(frame *rtda.Frame) { cp := frame.Method().Class().ConstantPool() kIndy := cp.GetConstant(uint(self.index)).(*rtc.ConstantInvokeDynamic) //bmSpec := kIndy.BootstrapMethodSpecifier() // Method Type and Method Handle Resolution // todo fmt.Printf("kIndy: %v\n", kIndy) kIndy.MethodHandle() }
func _logInstruction(frame *rtda.Frame, inst base.Instruction) { thread := frame.Thread() method := frame.Method() className := method.Class().Name() methodName := method.Name() pc := thread.PC() if method.IsStatic() { fmt.Printf("[instruction] thread:%p %v.%v() #%v %T %v\n", thread, className, methodName, pc, inst, inst) } else { fmt.Printf("[instruction] thread:%p %v#%v() #%v %T %v\n", thread, className, methodName, pc, inst, inst) } }
func (self *INVOKE_INTERFACE) Execute(frame *rtda.Frame) { if self.kMethodRef == nil { cp := frame.Method().ConstantPool() self.kMethodRef = cp.GetConstant(self.index).(*rtc.ConstantInterfaceMethodref) self.argSlotCount = self.kMethodRef.ArgSlotCount() } stack := frame.OperandStack() ref := stack.TopRef(self.argSlotCount) if ref == nil { panic("NPE") // todo } method := self.kMethodRef.FindInterfaceMethod(ref) frame.Thread().InvokeMethod(method) }
func (self *PUT_STATIC) Execute(frame *rtda.Frame) { if self.field == nil { cp := frame.Method().Class().ConstantPool() kFieldRef := cp.GetConstant(self.Index).(*rtc.ConstantFieldref) self.field = kFieldRef.StaticField() } class := self.field.Class() if class.InitializationNotStarted() { frame.RevertNextPC() frame.Thread().InitClass(class) return } val := frame.OperandStack().PopField(self.field.IsLongOrDouble) self.field.PutStaticValue(val) }
func (self *INVOKE_VIRTUAL) Execute(frame *rtda.Frame) { if self.kMethodRef == nil { cp := frame.Method().ConstantPool() self.kMethodRef = cp.GetConstant(self.Index).(*heap.ConstantMethodref) self.argSlotCount = self.kMethodRef.ArgSlotCount() } stack := frame.OperandStack() ref := stack.TopRef(self.argSlotCount) if ref == nil { frame.Thread().ThrowNPE() return } method := self.kMethodRef.GetVirtualMethod(ref) frame.Thread().InvokeMethod(method) }
func (self *PUT_FIELD) Execute(frame *rtda.Frame) { if self.field == nil { cp := frame.Method().Class().ConstantPool() kFieldRef := cp.GetConstant(self.Index).(*heap.ConstantFieldref) self.field = kFieldRef.InstanceField() } stack := frame.OperandStack() val := stack.PopField(self.field.IsLongOrDouble) ref := stack.PopRef() if ref == nil { frame.Thread().ThrowNPE() return } self.field.PutValue(ref, val) }
func (self *GET_STATIC) Execute(frame *rtda.Frame) { if self.field == nil { cp := frame.Method().Class().ConstantPool() kFieldRef := cp.GetConstant(self.Index).(*heap.ConstantFieldref) self.field = kFieldRef.StaticField() } class := self.field.Class() if class.InitializationNotStarted() { frame.RevertNextPC() // undo getstatic frame.Thread().InitClass(class) return } val := self.field.GetStaticValue() stack := frame.OperandStack() stack.PushField(val, self.field.IsLongOrDouble) }
func (self *CHECK_CAST) Execute(frame *rtda.Frame) { if self.class == nil { cp := frame.Method().Class().ConstantPool() kClass := cp.GetConstant(self.Index).(*heap.ConstantClass) self.class = kClass.Class() } stack := frame.OperandStack() ref := stack.PopRef() stack.PushRef(ref) if ref == nil { return } if !ref.IsInstanceOf(self.class) { frame.Thread().ThrowClassCastException(ref.Class(), self.class) } }
func (self *INVOKE_STATIC) Execute(frame *rtda.Frame) { if self.method == nil { cp := frame.Method().Class().ConstantPool() k := cp.GetConstant(self.Index) if kMethodRef, ok := k.(*rtc.ConstantMethodref); ok { self.method = kMethodRef.StaticMethod() } else { self.method = k.(*rtc.ConstantInterfaceMethodref).StaticMethod() } } // init class class := self.method.Class() if class.InitializationNotStarted() { frame.RevertNextPC() frame.Thread().InitClass(class) return } frame.Thread().InvokeMethod(self.method) }
func (self *INVOKE_NATIVE) Execute(frame *rtda.Frame) { nativeMethod := frame.Method().NativeMethod().(func(*rtda.Frame)) nativeMethod(frame) }