예제 #1
0
파일: thread.go 프로젝트: cretz/jvm.go
func (self *Thread) InvokeMethod(method *rtc.Method) {
	//self._logInvoke(self.stack.size, method)
	currentFrame := self.CurrentFrame()
	newFrame := self.NewFrame(method)
	self.PushFrame(newFrame)
	argSlotsCount := method.ArgSlotCount()
	if argSlotsCount > 0 {
		_passArgs(currentFrame.operandStack, newFrame.localVars, argSlotsCount)
	}

	if method.IsSynchronized() {
		var monitor *rtc.Monitor
		if method.IsStatic() {
			classObj := method.Class().JClass()
			monitor = classObj.Monitor()
		} else {
			thisObj := newFrame.LocalVars().GetThis()
			monitor = thisObj.Monitor()
		}

		monitor.Enter(self)
		newFrame.SetOnPopAction(func() {
			monitor.Exit(self)
		})
	}
}
예제 #2
0
파일: helper.go 프로젝트: cretz/jvm.go
// Object[] -> []Any
func convertArgs(this, argArr *rtc.Obj, method *rtc.Method) []Any {
	if method.ArgSlotCount() == 0 {
		return nil
	}
	if method.ArgSlotCount() == 1 && !method.IsStatic() {
		return []Any{this}
	}

	argObjs := argArr.Refs()
	argTypes := method.ParsedDescriptor().ParameterTypes()

	args := make([]Any, method.ArgSlotCount())
	j := 0
	if !method.IsStatic() {
		args[0] = this
		j = 1
	}

	for i, argType := range argTypes {
		argObj := argObjs[i]

		if argType.IsBaseType() {
			// todo
			unboxed := box.Unbox(argObj, argType.Descriptor())
			args[i+j] = unboxed
			if argType.IsLongOrDouble() {
				j++
			}
		} else {
			args[i+j] = argObj
		}
	}

	return args
}
예제 #3
0
파일: thread.go 프로젝트: cretz/jvm.go
func (self *Thread) _logInvoke(stackSize uint, method *rtc.Method) {
	space := strings.Repeat(" ", int(stackSize))
	className := method.Class().Name()
	methodName := method.Name()

	if method.IsStatic() {
		fmt.Printf("[method]%v thread:%p %v.%v()\n", space, self, className, methodName)
	} else {
		fmt.Printf("[method]%v thread:%p %v#%v()\n", space, self, className, methodName)
	}
}