示例#1
0
文件: thread.go 项目: Rearcher/jvm.go
func (self *Thread) InvokeMethod(method *heap.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 *heap.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)
		})
	}
}