예제 #1
0
파일: swap.go 프로젝트: Rearcher/jvm.go
func (self *SWAP) Execute(frame *rtda.Frame) {
	stack := frame.OperandStack()
	val1 := stack.PopSlot()
	val2 := stack.PopSlot()
	stack.PushSlot(val1)
	stack.PushSlot(val2)
}
예제 #2
0
// private native String getUTF8At0(Object o, int i);
// (Ljava/lang/Object;I)Ljava/lang/String;
func getUTF8At0(frame *rtda.Frame) {
	cp, index := _getPop(frame)
	kUtf8 := cp.GetConstant(index).(*rtc.ConstantUtf8)
	goStr := kUtf8.Str()
	jStr := rtda.JString(goStr)
	frame.OperandStack().PushRef(jStr)
}
예제 #3
0
파일: TimeZone.go 프로젝트: b-xiang/jvm.go
// private static native String getSystemTimeZoneID(String javaHome, String country);
// (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
func getSystemTimeZoneID(frame *rtda.Frame) {
	vars := frame.LocalVars()
	//javaHomeObj := vars.GetRef(0)
	countryObj := vars.GetRef(1)

	//for osx read system timezone
	file, err := os.Open("/usr/share/zoneinfo/zone.tab")

	if err != nil {
		panic(err)
	}

	scanner := bufio.NewScanner(file)
	var timezone string
	for scanner.Scan() {
		line := scanner.Text()
		if line[0] == '#' {
			continue
		}
		zone := strings.Split(line, "\t")
		if zone[0] == rtda.GoString(countryObj) {
			timezone = zone[2]
			break
		}
	}

	location, _ := time.LoadLocation(timezone)
	zoneID := rtda.JString(location.String())
	stack := frame.OperandStack()
	stack.PushRef(zoneID)
}
예제 #4
0
파일: athrow.go 프로젝트: Rearcher/jvm.go
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)
}
예제 #5
0
파일: mul.go 프로젝트: Rearcher/jvm.go
func (self *FMUL) Execute(frame *rtda.Frame) {
	stack := frame.OperandStack()
	v2 := stack.PopFloat()
	v1 := stack.PopFloat()
	result := v1 * v2
	stack.PushFloat(result)
}
예제 #6
0
//(Ljava/lang/String;)[Ljava/net/InetAddress;
func i6di_lookupAllHostAddr(frame *rtda.Frame) {
	vars := frame.LocalVars()
	host := rtda.GoString(vars.GetRef(1))
	address, _ := net.LookupHost(host)
	constructorCount := uint(len(address))

	inetAddress := heap.BootLoader().LoadClass("java/net/InetAddress")
	inetAddressArr := inetAddress.NewArray(constructorCount)

	stack := frame.OperandStack()
	stack.PushRef(inetAddressArr)

	//TODO
	//getByName descriptor:(Ljava/lang/String;)Ljava/net/InetAddress;
	//if constructorCount > 0 {
	//	thread := frame.Thread()
	//	constructorObjs := inetAddressArr.Refs()
	//	inetAddressGetByNameMethod := inetAddress.GetStaticMethod("getByName", "(Ljava/lang/String;)Ljava/net/InetAddress;")

	//	fmt.Println(constructorObjs[0])
	//	fmt.Println(inetAddressGetByNameMethod)
	//	fmt.Println(thread)
	//	thread.InvokeMethodWithShim(inetAddressGetByNameMethod, []interface{}{
	//		constructorObjs[0],
	//		rtda.JString(host),
	//	})
	//}
}
예제 #7
0
// public native int addressSize();
// ()I
func addressSize(frame *rtda.Frame) {
	// vars := frame.LocalVars()
	// vars.GetRef(0) // this

	stack := frame.OperandStack()
	stack.PushInt(8) // todo unsafe.Sizeof(int)
}
예제 #8
0
// private static native long getEntryCrc(long jzentry);
// (J)J
func getEntryCrc(frame *rtda.Frame) {
	entry := _getEntryPop(frame)
	crc := int64(entry.CRC32)

	stack := frame.OperandStack()
	stack.PushLong(crc)
}
예제 #9
0
파일: rem.go 프로젝트: b-xiang/jvm.go
func (self *DREM) Execute(frame *rtda.Frame) {
	stack := frame.OperandStack()
	v2 := stack.PopDouble()
	v1 := stack.PopDouble()
	result := math.Mod(v1, v2) // todo
	stack.PushDouble(result)
}
예제 #10
0
//private native int socketRead0(FileDescriptor fd, byte b[], int off, int len, int timeout)
// java/net/SocketInputStream~socketRead0~(Ljava/io/FileDescriptor;[BIII)I
func sis_socketRead0(frame *rtda.Frame) {
	vars := frame.LocalVars()
	//this := vars.GetThis()
	fd := vars.GetRef(1)
	buf := vars.GetRef(2)
	off := vars.GetInt(3)
	_len := vars.GetInt(4)

	conn := fd.Extra().(net.Conn)

	_timeout := vars.GetInt(5)
	if _timeout > 0 {
		conn.SetDeadline(time.Now().Add(time.Duration(_timeout) * time.Millisecond))
	}

	goBuf := buf.GoBytes()
	goBuf = goBuf[off : off+_len]

	n, err := conn.Read(goBuf)
	if err == nil || n > 0 || err == io.EOF {
		frame.OperandStack().PushInt(int32(n))
	} else {
		// todo
		panic(err.Error())
		//frame.Thread().ThrowIOException(err.Error())
	}

}
예제 #11
0
// private static native long getEntrySize(long jzentry);
// (J)J
func getEntrySize(frame *rtda.Frame) {
	entry := _getEntryPop(frame)
	size := int64(entry.UncompressedSize64)

	stack := frame.OperandStack()
	stack.PushLong(size)
}
예제 #12
0
// private native long getUptime0();
// ()J
func getUptime0(frame *rtda.Frame) {
	// todo
	uptime := int64(0)

	stack := frame.OperandStack()
	stack.PushLong(uptime)
}
예제 #13
0
// public native long getStartupTime();
// ()J
func getStartupTime(frame *rtda.Frame) {
	// todo
	startupTime := int64(0)

	stack := frame.OperandStack()
	stack.PushLong(startupTime)
}
예제 #14
0
파일: Class.go 프로젝트: zaishihuang/jvm.go
// public native int getModifiers();
// ()I
func getModifiers(frame *rtda.Frame) {
	class := _popClass(frame)
	modifiers := class.GetAccessFlags()

	stack := frame.OperandStack()
	stack.PushInt(int32(modifiers))
}
예제 #15
0
파일: Signal.go 프로젝트: Rearcher/jvm.go
// private static native int findSignal(String string);
// (Ljava/lang/String;)I
func findSignal(frame *rtda.Frame) {
	vars := frame.LocalVars()
	vars.GetRef(0) // name

	stack := frame.OperandStack()
	stack.PushInt(0) // todo
}
예제 #16
0
파일: add.go 프로젝트: Rearcher/jvm.go
func (self *DADD) Execute(frame *rtda.Frame) {
	stack := frame.OperandStack()
	v1 := stack.PopDouble()
	v2 := stack.PopDouble()
	result := v1 + v2
	stack.PushDouble(result)
}
예제 #17
0
파일: rem.go 프로젝트: b-xiang/jvm.go
func (self *FREM) Execute(frame *rtda.Frame) {
	stack := frame.OperandStack()
	v2 := stack.PopFloat()
	v1 := stack.PopFloat()
	result := float32(math.Mod(float64(v1), float64(v2))) // todo
	stack.PushFloat(result)
}
예제 #18
0
// private static native int getEntryFlag(long jzentry);
// (J)I
func getEntryFlag(frame *rtda.Frame) {
	entry := _getEntryPop(frame)
	flag := int32(entry.Flags)

	stack := frame.OperandStack()
	stack.PushInt(flag)
}
예제 #19
0
파일: add.go 프로젝트: Rearcher/jvm.go
func (self *LADD) Execute(frame *rtda.Frame) {
	stack := frame.OperandStack()
	v2 := stack.PopLong()
	v1 := stack.PopLong()
	result := v1 + v2
	stack.PushLong(result)
}
예제 #20
0
파일: add.go 프로젝트: Rearcher/jvm.go
func (self *IADD) Execute(frame *rtda.Frame) {
	stack := frame.OperandStack()
	v2 := stack.PopInt()
	v1 := stack.PopInt()
	result := v1 + v2
	stack.PushInt(result)
}
예제 #21
0
// private static native String getVersion0();
// ()Ljava/lang/String;
func getVersion0(frame *rtda.Frame) {
	// todo
	version := rtda.JString("0")

	stack := frame.OperandStack()
	stack.PushRef(version)
}
예제 #22
0
파일: Class.go 프로젝트: zaishihuang/jvm.go
// public native Class<?> getComponentType();
// ()Ljava/lang/Class;
func getComponentType(frame *rtda.Frame) {
	class := _popClass(frame)
	componentClass := class.ComponentClass()
	componentClassObj := componentClass.JClass()

	stack := frame.OperandStack()
	stack.PushRef(componentClassObj)
}
예제 #23
0
파일: Class.go 프로젝트: zaishihuang/jvm.go
// private native String getName0();
// ()Ljava/lang/String;
func getName0(frame *rtda.Frame) {
	class := _popClass(frame)
	name := class.NameJlsFormat()
	nameObj := rtda.JString(name)

	stack := frame.OperandStack()
	stack.PushRef(nameObj)
}
예제 #24
0
// private static native int getEntryMethod(long jzentry);
// (J)I
func getEntryMethod(frame *rtda.Frame) {
	// entry := _getEntryPop(frame)
	// method := int32(entry.Method)

	// todo
	stack := frame.OperandStack()
	stack.PushInt(0)
}
예제 #25
0
파일: Runtime.go 프로젝트: b-xiang/jvm.go
// public native long freeMemory();
// ()J
func freeMemory(frame *rtda.Frame) {
	var memStats runtime.MemStats
	runtime.ReadMemStats(&memStats)
	frees := memStats.Frees

	stack := frame.OperandStack()
	stack.PushLong(int64(frees))
}
예제 #26
0
파일: Object.go 프로젝트: kingljl/jvm.go
// public native int hashCode();
// ()I
func hashCode(frame *rtda.Frame) {
	vars := frame.LocalVars()
	this := vars.GetThis()

	hash := int32(uintptr(unsafe.Pointer(this)))
	stack := frame.OperandStack()
	stack.PushInt(hash)
}
예제 #27
0
파일: Object.go 프로젝트: kingljl/jvm.go
// protected native Object clone() throws CloneNotSupportedException;
// ()Ljava/lang/Object;
func clone(frame *rtda.Frame) {
	vars := frame.LocalVars()
	this := vars.GetThis()

	// todo
	stack := frame.OperandStack()
	stack.PushRef(this.Clone())
}
예제 #28
0
파일: Net.go 프로젝트: Rearcher/jvm.go
// Due to oddities SO_REUSEADDR on windows reuse is ignored
// private static native int socket0(boolean preferIPv6, boolean stream, boolean reuse);
func net_socket0(frame *rtda.Frame) {
	//vars := frame.LocalVars()
	//preferIPv6 := vars.GetBoolean(0)
	//stream := vars.GetBoolean(1)
	//reuse := vars.GetBoolean(2)

	frame.OperandStack().PushInt(100)
}
예제 #29
0
파일: sh.go 프로젝트: b-xiang/jvm.go
func (self *LUSHR) Execute(frame *rtda.Frame) {
	stack := frame.OperandStack()
	v2 := stack.PopInt()
	v1 := stack.PopLong()
	s := uint32(v2) & 0x3f
	result := int64(uint64(v1) >> s)
	stack.PushLong(result)
}
예제 #30
0
파일: Object.go 프로젝트: kingljl/jvm.go
// public final native Class<?> getClass();
// ()Ljava/lang/Class;
func getClass(frame *rtda.Frame) {
	vars := frame.LocalVars()
	this := vars.GetThis()

	class := this.Class().JClass()
	stack := frame.OperandStack()
	stack.PushRef(class)
}