text stringlengths 9 39.2M | dir stringlengths 25 226 | lang stringclasses 163
values | created_date timestamp[s] | updated_date timestamp[s] | repo_name stringclasses 751
values | repo_full_name stringclasses 752
values | star int64 1.01k 183k | len_tokens int64 1 18.5M |
|---|---|---|---|---|---|---|---|---|
```go
package classfile
// Constant pool tags
const (
CONSTANT_Class = 7
CONSTANT_Fieldref = 9
CONSTANT_Methodref = 10
CONSTANT_InterfaceMethodref = 11
CONSTANT_String = 8
CONSTANT_Integer = 3
CONSTANT_Float = 4
CONSTANT_Long = 5... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classfile/constant_info.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 468 |
```go
package classfile
import "math"
/*
CONSTANT_Integer_info {
u1 tag;
u4 bytes;
}
*/
type ConstantIntegerInfo struct {
val int32
}
func (self *ConstantIntegerInfo) readInfo(reader *ClassReader) {
bytes := reader.readUint32()
self.val = int32(bytes)
}
func (self *ConstantIntegerInfo) Value() int32 {
re... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classfile/cp_numeric.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 341 |
```go
package classfile
/*
SourceFile_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 sourcefile_index;
}
*/
type SourceFileAttribute struct {
cp ConstantPool
sourceFileIndex uint16
}
func (self *SourceFileAttribute) readInfo(reader *ClassReader) {
self.sourceFileIndex = reade... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classfile/attr_source_file.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 101 |
```go
package classfile
import "fmt"
/*
ClassFile {
u4 magic;
u2 minor_version;
u2 major_version;
u2 constant_pool_count;
cp_info constant_pool[constant_pool_count-1];
u2 access_flags;
u2 this_class;
u2 ... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classfile/class_file.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 787 |
```go
package classfile
/*
ConstantValue_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 constantvalue_index;
}
*/
type ConstantValueAttribute struct {
constantValueIndex uint16
}
func (self *ConstantValueAttribute) readInfo(reader *ClassReader) {
self.constantValueIndex = reader.readUint16... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classfile/attr_constant_value.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 95 |
```go
package classfile
/*
LocalVariableTable_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 local_variable_table_length;
{ u2 start_pc;
u2 length;
u2 name_index;
u2 descriptor_index;
u2 index;
} local_variable_table[local_variable_table_length];
}
*/... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classfile/attr_local_variable_table.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 251 |
```go
package classfile
import "encoding/binary"
type ClassReader struct {
data []byte
}
// u1
func (self *ClassReader) readUint8() uint8 {
val := self.data[0]
self.data = self.data[1:]
return val
}
// u2
func (self *ClassReader) readUint16() uint16 {
val := binary.BigEndian.Uint16(self.data)
self.data = self... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classfile/class_reader.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 262 |
```go
package classfile
/*
InnerClasses_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 number_of_classes;
{ u2 inner_class_info_index;
u2 outer_class_info_index;
u2 inner_name_index;
u2 inner_class_access_flags;
} classes[number_of_classes];
}
*/
type InnerCl... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classfile/attr_inner_classes.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 238 |
```go
package classfile
/*
Signature_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 signature_index;
}
*/
type SignatureAttribute struct {
cp ConstantPool
signatureIndex uint16
}
func (self *SignatureAttribute) readInfo(reader *ClassReader) {
self.signatureIndex = reader.readU... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classfile/attr_signature.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 94 |
```go
package classfile
import "fmt"
import "unicode/utf16"
/*
CONSTANT_Utf8_info {
u1 tag;
u2 length;
u1 bytes[length];
}
*/
type ConstantUtf8Info struct {
str string
}
func (self *ConstantUtf8Info) readInfo(reader *ClassReader) {
length := uint32(reader.readUint16())
bytes := reader.readBytes(length... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classfile/cp_utf8.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 702 |
```go
package classfile
/*
Code_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 max_stack;
u2 max_locals;
u4 code_length;
u1 code[code_length];
u2 exception_table_length;
{ u2 start_pc;
u2 end_pc;
u2 handler_pc;
u2 catch_type;
} exception_table... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classfile/attr_code.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 524 |
```go
package classfile
/*
CONSTANT_Fieldref_info {
u1 tag;
u2 class_index;
u2 name_and_type_index;
}
CONSTANT_Methodref_info {
u1 tag;
u2 class_index;
u2 name_and_type_index;
}
CONSTANT_InterfaceMethodref_info {
u1 tag;
u2 class_index;
u2 name_and_type_index;
}
*/
type ConstantFiel... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classfile/cp_member_ref.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 241 |
```go
package classfile
/*
CONSTANT_String_info {
u1 tag;
u2 string_index;
}
*/
type ConstantStringInfo struct {
cp ConstantPool
stringIndex uint16
}
func (self *ConstantStringInfo) readInfo(reader *ClassReader) {
self.stringIndex = reader.readUint16()
}
func (self *ConstantStringInfo) String() st... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classfile/cp_string.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 90 |
```go
package classfile
var (
_attrDeprecated = &DeprecatedAttribute{}
_attrSynthetic = &SyntheticAttribute{}
)
/*
attribute_info {
u2 attribute_name_index;
u4 attribute_length;
u1 info[attribute_length];
}
*/
type AttributeInfo interface {
readInfo(reader *ClassReader)
}
func readAttributes(reader *... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classfile/attribute_info.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 496 |
```go
package rtda
import "jvmgo/ch07/rtda/heap"
/*
JVM
Thread
pc
Stack
Frame
LocalVars
OperandStack
*/
type Thread struct {
pc int // the address of the instruction currently being executed
stack *Stack
// todo
}
func NewThread() *Thread {
return &Thread{
stack: newStack(102... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/thread.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 241 |
```go
package classfile
/*
LocalVariableTypeTable_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 local_variable_type_table_length;
{ u2 start_pc;
u2 length;
u2 name_index;
u2 signature_index;
u2 index;
} local_variable_type_table[local_variable_type_t... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classfile/attr_local_variable_type_table.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 267 |
```go
package rtda
import "math"
import "jvmgo/ch07/rtda/heap"
type LocalVars []Slot
func newLocalVars(maxLocals uint) LocalVars {
if maxLocals > 0 {
return make([]Slot, maxLocals)
}
return nil
}
func (self LocalVars) SetInt(index uint, val int32) {
self[index].num = val
}
func (self LocalVars) GetInt(index u... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/local_vars.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 415 |
```go
package rtda
import "math"
import "jvmgo/ch07/rtda/heap"
type OperandStack struct {
size uint
slots []Slot
}
func newOperandStack(maxStack uint) *OperandStack {
if maxStack > 0 {
return &OperandStack{
slots: make([]Slot, maxStack),
}
}
return nil
}
func (self *OperandStack) PushInt(val int32) {
... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/operand_stack.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 547 |
```go
package rtda
import "jvmgo/ch07/rtda/heap"
type Slot struct {
num int32
ref *heap.Object
}
``` | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/slot.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 33 |
```go
package rtda
// jvm stack
type Stack struct {
maxSize uint
size uint
_top *Frame // stack is implemented as linked list
}
func newStack(maxSize uint) *Stack {
return &Stack{
maxSize: maxSize,
}
}
func (self *Stack) push(frame *Frame) {
if self.size >= self.maxSize {
panic("java.lang.StackOverfl... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/jvm_stack.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 225 |
```go
package rtda
import "jvmgo/ch07/rtda/heap"
// stack frame
type Frame struct {
lower *Frame // stack is implemented as linked list
localVars LocalVars
operandStack *OperandStack
thread *Thread
method *heap.Method
nextPC int // the next instruction after the call
}
func newFrame... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/frame.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 272 |
```go
package heap
// symbolic reference
type SymRef struct {
cp *ConstantPool
className string
class *Class
}
func (self *SymRef) ResolvedClass() *Class {
if self.class == nil {
self.resolveClassRef()
}
return self.class
}
// jvms8 5.4.3.1
func (self *SymRef) resolveClassRef() {
d := self.cp.cla... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/heap/cp_symref.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 129 |
```go
package heap
import "jvmgo/ch07/classfile"
type MethodRef struct {
MemberRef
method *Method
}
func newMethodRef(cp *ConstantPool, refInfo *classfile.ConstantMethodrefInfo) *MethodRef {
ref := &MethodRef{}
ref.cp = cp
ref.copyMemberRefInfo(&refInfo.ConstantMemberrefInfo)
return ref
}
func (self *MethodRe... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/heap/cp_methodref.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 277 |
```go
package heap
import "strings"
import "jvmgo/ch07/classfile"
// name, superClassName and interfaceNames are all binary names(jvms8-4.2.1)
type Class struct {
accessFlags uint16
name string // thisClassName
superClassName string
interfaceNames []string
constantPool *ConstantPool... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/heap/class.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 761 |
```go
package heap
import "fmt"
import "jvmgo/ch07/classfile"
type Constant interface{}
type ConstantPool struct {
class *Class
consts []Constant
}
func newConstantPool(class *Class, cfCp classfile.ConstantPool) *ConstantPool {
cpCount := len(cfCp)
consts := make([]Constant, cpCount)
rtCp := &ConstantPool{cla... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/heap/constant_pool.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 517 |
```go
package heap
import "jvmgo/ch07/classfile"
type FieldRef struct {
MemberRef
field *Field
}
func newFieldRef(cp *ConstantPool, refInfo *classfile.ConstantFieldrefInfo) *FieldRef {
ref := &FieldRef{}
ref.cp = cp
ref.copyMemberRefInfo(&refInfo.ConstantMemberrefInfo)
return ref
}
func (self *FieldRef) Resol... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/heap/cp_fieldref.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 308 |
```go
package heap
// jvms8 6.5.instanceof
// jvms8 6.5.checkcast
func (self *Class) isAssignableFrom(other *Class) bool {
s, t := other, self
if s == t {
return true
}
if !t.IsInterface() {
return s.IsSubClassOf(t)
} else {
return s.IsImplements(t)
}
}
// self extends c
func (self *Class) IsSubClassOf(... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/heap/class_hierarchy.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 316 |
```go
package heap
import "jvmgo/ch07/classfile"
type ClassRef struct {
SymRef
}
func newClassRef(cp *ConstantPool, classInfo *classfile.ConstantClassInfo) *ClassRef {
ref := &ClassRef{}
ref.cp = cp
ref.className = classInfo.Name()
return ref
}
``` | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/heap/cp_classref.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 68 |
```go
package heap
import "strings"
type MethodDescriptorParser struct {
raw string
offset int
parsed *MethodDescriptor
}
func parseMethodDescriptor(descriptor string) *MethodDescriptor {
parser := &MethodDescriptorParser{}
return parser.parse(descriptor)
}
func (self *MethodDescriptorParser) parse(descript... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/heap/method_descriptor_parser.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 675 |
```go
package heap
import "jvmgo/ch07/classfile"
type ClassMember struct {
accessFlags uint16
name string
descriptor string
class *Class
}
func (self *ClassMember) copyMemberInfo(memberInfo *classfile.MemberInfo) {
self.accessFlags = memberInfo.AccessFlags()
self.name = memberInfo.Name()
self.de... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/heap/class_member.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 387 |
```go
package heap
type Object struct {
class *Class
fields Slots
}
func newObject(class *Class) *Object {
return &Object{
class: class,
fields: newSlots(class.instanceSlotCount),
}
}
// getters
func (self *Object) Class() *Class {
return self.class
}
func (self *Object) Fields() Slots {
return self.fiel... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/heap/object.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 106 |
```go
package heap
import "jvmgo/ch07/classfile"
type MemberRef struct {
SymRef
name string
descriptor string
}
func (self *MemberRef) copyMemberRefInfo(refInfo *classfile.ConstantMemberrefInfo) {
self.className = refInfo.ClassName()
self.name, self.descriptor = refInfo.NameAndDescriptor()
}
func (self *... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/heap/cp_memberref.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 107 |
```go
package heap
type MethodDescriptor struct {
parameterTypes []string
returnType string
}
func (self *MethodDescriptor) addParameterType(t string) {
pLen := len(self.parameterTypes)
if pLen == cap(self.parameterTypes) {
s := make([]string, pLen, pLen+4)
copy(s, self.parameterTypes)
self.parameterTyp... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/heap/method_descriptor.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 97 |
```go
package heap
import "jvmgo/ch07/classfile"
type Method struct {
ClassMember
maxStack uint
maxLocals uint
code []byte
argSlotCount uint
}
func newMethods(class *Class, cfMethods []*classfile.MemberInfo) []*Method {
methods := make([]*Method, len(cfMethods))
for i, cfMethod := range cfMetho... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/heap/method.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 510 |
```go
package heap
const (
ACC_PUBLIC = 0x0001 // class field method
ACC_PRIVATE = 0x0002 // field method
ACC_PROTECTED = 0x0004 // field method
ACC_STATIC = 0x0008 // field method
ACC_FINAL = 0x0010 // class field method
ACC_SUPER = 0x0020 // class
ACC_SYNCHR... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/heap/access_flags.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 278 |
```go
package heap
func LookupMethodInClass(class *Class, name, descriptor string) *Method {
for c := class; c != nil; c = c.superClass {
for _, method := range c.methods {
if method.name == name && method.descriptor == descriptor {
return method
}
}
}
return nil
}
func lookupMethodInInterfaces(iface... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/heap/method_lookup.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 164 |
```go
package heap
import "fmt"
import "jvmgo/ch07/classfile"
import "jvmgo/ch07/classpath"
/*
class names:
- primitive types: boolean, byte, int ...
- primitive arrays: [Z, [B, [I ...
- non-array classes: java/lang/Object ...
- array classes: [Ljava/lang/Object; ...
*/
type ClassLoader struct {
cp ... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/heap/class_loader.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 1,035 |
```go
package heap
import "jvmgo/ch07/classfile"
type InterfaceMethodRef struct {
MemberRef
method *Method
}
func newInterfaceMethodRef(cp *ConstantPool, refInfo *classfile.ConstantInterfaceMethodrefInfo) *InterfaceMethodRef {
ref := &InterfaceMethodRef{}
ref.cp = cp
ref.copyMemberRefInfo(&refInfo.ConstantMembe... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/heap/cp_interface_methodref.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 300 |
```go
package heap
import "math"
type Slot struct {
num int32
ref *Object
}
type Slots []Slot
func newSlots(slotCount uint) Slots {
if slotCount > 0 {
return make([]Slot, slotCount)
}
return nil
}
func (self Slots) SetInt(index uint, val int32) {
self[index].num = val
}
func (self Slots) GetInt(index uint)... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/heap/slots.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 373 |
```go
package heap
import "jvmgo/ch07/classfile"
type Field struct {
ClassMember
constValueIndex uint
slotId uint
}
func newFields(class *Class, cfFields []*classfile.MemberInfo) []*Field {
fields := make([]*Field, len(cfFields))
for i, cfField := range cfFields {
fields[i] = &Field{}
fields[i].cla... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/rtda/heap/field.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 296 |
```go
package classpath
import "os"
import "strings"
// :(linux/unix) or ;(windows)
const pathListSeparator = string(os.PathListSeparator)
type Entry interface {
// className: fully/qualified/ClassName.class
readClass(className string) ([]byte, Entry, error)
String() string
}
func newEntry(path string) Entry {
... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classpath/entry.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 168 |
```go
package classpath
import "errors"
import "strings"
type CompositeEntry []Entry
func newCompositeEntry(pathList string) CompositeEntry {
compositeEntry := []Entry{}
for _, path := range strings.Split(pathList, pathListSeparator) {
entry := newEntry(path)
compositeEntry = append(compositeEntry, entry)
}
... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classpath/entry_composite.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 202 |
```go
package classpath
import "os"
import "path/filepath"
type Classpath struct {
bootClasspath Entry
extClasspath Entry
userClasspath Entry
}
func Parse(jreOption, cpOption string) *Classpath {
cp := &Classpath{}
cp.parseBootAndExtClasspath(jreOption)
cp.parseUserClasspath(cpOption)
return cp
}
func (self... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classpath/classpath.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 476 |
```go
package classpath
import "archive/zip"
import "errors"
import "io/ioutil"
import "path/filepath"
type ZipEntry struct {
absPath string
zipRC *zip.ReadCloser
}
func newZipEntry(path string) *ZipEntry {
absPath, err := filepath.Abs(path)
if err != nil {
panic(err)
}
return &ZipEntry{absPath, nil}
}
f... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classpath/entry_zip.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 374 |
```go
package classpath
import "os"
import "path/filepath"
import "strings"
func newWildcardEntry(path string) CompositeEntry {
baseDir := path[:len(path)-1] // remove *
compositeEntry := []Entry{}
walkFn := func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classpath/entry_wildcard.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 168 |
```go
package classpath
import "io/ioutil"
import "path/filepath"
type DirEntry struct {
absDir string
}
func newDirEntry(path string) *DirEntry {
absDir, err := filepath.Abs(path)
if err != nil {
panic(err)
}
return &DirEntry{absDir}
}
func (self *DirEntry) readClass(className string) ([]byte, Entry, error)... | /content/code_sandbox/v1/code/go/src/jvmgo/ch07/classpath/entry_dir.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 131 |
```go
package main
import "flag"
import "fmt"
import "os"
// java [-options] class [args...]
type Cmd struct {
helpFlag bool
versionFlag bool
cpOption string
XjreOption string
class string
args []string
}
func parseCmd() *Cmd {
cmd := &Cmd{}
flag.Usage = printUsage
flag.BoolVar(&cmd.hel... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/cmd.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 254 |
```go
package main
import "fmt"
import "strings"
import "jvmgo/ch05/classfile"
import "jvmgo/ch05/classpath"
func main() {
cmd := parseCmd()
if cmd.versionFlag {
fmt.Println("version 0.0.1")
} else if cmd.helpFlag || cmd.class == "" {
printUsage()
} else {
startJVM(cmd)
}
}
func startJVM(cmd *Cmd) {
cp ... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/main.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 305 |
```go
package main
import "fmt"
import "jvmgo/ch05/classfile"
import "jvmgo/ch05/instructions"
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
func interpret(methodInfo *classfile.MemberInfo) {
codeAttr := methodInfo.CodeAttribute()
maxLocals := codeAttr.MaxLocals()
maxStack := codeAttr.MaxStack()
... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/interpreter.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 309 |
```go
package math
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Boolean AND int
type IAND struct{ base.NoOperandsInstruction }
func (self *IAND) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
v2 := stack.PopInt()
v1 := stack.PopInt()
result := v1 & v2
stack.PushInt(result)
}
//... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/math/and.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 158 |
```go
package math
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Add double
type DADD struct{ base.NoOperandsInstruction }
func (self *DADD) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
v1 := stack.PopDouble()
v2 := stack.PopDouble()
result := v1 + v2
stack.PushDouble(result)
}... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/math/add.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 290 |
```go
package math
import "math"
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Remainder double
type DREM struct{ base.NoOperandsInstruction }
func (self *DREM) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
v2 := stack.PopDouble()
v1 := stack.PopDouble()
result := math.Mod(v1, v2... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/math/rem.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 358 |
```go
package math
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Shift left int
type ISHL struct{ base.NoOperandsInstruction }
func (self *ISHL) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
v2 := stack.PopInt()
v1 := stack.PopInt()
s := uint32(v2) & 0x1f
result := v1 << s
stac... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/math/sh.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 526 |
```go
package math
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Boolean OR int
type IOR struct{ base.NoOperandsInstruction }
func (self *IOR) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
v2 := stack.PopInt()
v1 := stack.PopInt()
result := v1 | v2
stack.PushInt(result)
}
// Bo... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/math/or.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 159 |
```go
package math
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Divide double
type DDIV struct{ base.NoOperandsInstruction }
func (self *DDIV) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
v2 := stack.PopDouble()
v1 := stack.PopDouble()
result := v1 / v2
stack.PushDouble(result... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/math/div.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 334 |
```go
package math
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Subtract double
type DSUB struct{ base.NoOperandsInstruction }
func (self *DSUB) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
v2 := stack.PopDouble()
v1 := stack.PopDouble()
result := v1 - v2
stack.PushDouble(resu... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/math/sub.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 290 |
```go
package instructions
import "fmt"
import "jvmgo/ch05/instructions/base"
import . "jvmgo/ch05/instructions/comparisons"
import . "jvmgo/ch05/instructions/constants"
import . "jvmgo/ch05/instructions/control"
import . "jvmgo/ch05/instructions/conversions"
import . "jvmgo/ch05/instructions/extended"
import . "jvmgo... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/factory.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 4,403 |
```go
package math
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Negate double
type DNEG struct{ base.NoOperandsInstruction }
func (self *DNEG) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
val := stack.PopDouble()
stack.PushDouble(-val)
}
// Negate float
type FNEG struct{ base.N... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/math/neg.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 234 |
```go
package math
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Increment local variable by constant
type IINC struct {
Index uint
Const int32
}
func (self *IINC) FetchOperands(reader *base.BytecodeReader) {
self.Index = uint(reader.ReadUint8())
self.Const = int32(reader.ReadInt8())
}
func ... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/math/iinc.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 132 |
```go
package math
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Boolean XOR int
type IXOR struct{ base.NoOperandsInstruction }
func (self *IXOR) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
v1 := stack.PopInt()
v2 := stack.PopInt()
result := v1 ^ v2
stack.PushInt(result)
}
//... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/math/xor.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 161 |
```go
package math
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Multiply double
type DMUL struct{ base.NoOperandsInstruction }
func (self *DMUL) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
v2 := stack.PopDouble()
v1 := stack.PopDouble()
result := v1 * v2
stack.PushDouble(resu... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/math/mul.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 290 |
```go
package stores
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Store float into local variable
type FSTORE struct{ base.Index8Instruction }
func (self *FSTORE) Execute(frame *rtda.Frame) {
_fstore(frame, uint(self.Index))
}
type FSTORE_0 struct{ base.NoOperandsInstruction }
func (self *FST... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/stores/fstore.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 265 |
```go
package stores
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Store double into local variable
type DSTORE struct{ base.Index8Instruction }
func (self *DSTORE) Execute(frame *rtda.Frame) {
_dstore(frame, uint(self.Index))
}
type DSTORE_0 struct{ base.NoOperandsInstruction }
func (self *DS... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/stores/dstore.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 265 |
```go
package stores
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Store reference into local variable
type ASTORE struct{ base.Index8Instruction }
func (self *ASTORE) Execute(frame *rtda.Frame) {
_astore(frame, uint(self.Index))
}
type ASTORE_0 struct{ base.NoOperandsInstruction }
func (self ... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/stores/astore.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 265 |
```go
package stores
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Store long into local variable
type LSTORE struct{ base.Index8Instruction }
func (self *LSTORE) Execute(frame *rtda.Frame) {
_lstore(frame, uint(self.Index))
}
type LSTORE_0 struct{ base.NoOperandsInstruction }
func (self *LSTO... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/stores/lstore.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 265 |
```go
package stores
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Store int into local variable
type ISTORE struct{ base.Index8Instruction }
func (self *ISTORE) Execute(frame *rtda.Frame) {
_istore(frame, uint(self.Index))
}
type ISTORE_0 struct{ base.NoOperandsInstruction }
func (self *ISTOR... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/stores/istore.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 270 |
```go
package base
import "jvmgo/ch05/rtda"
func Branch(frame *rtda.Frame, offset int) {
pc := frame.Thread().PC()
nextPC := pc + offset
frame.SetNextPC(nextPC)
}
``` | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/base/branch_logic.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 50 |
```go
package base
type BytecodeReader struct {
code []byte // bytecodes
pc int
}
func (self *BytecodeReader) Reset(code []byte, pc int) {
self.code = code
self.pc = pc
}
func (self *BytecodeReader) PC() int {
return self.pc
}
func (self *BytecodeReader) ReadInt8() int8 {
return int8(self.ReadUint8())
}
fun... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/base/bytecode_reader.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 376 |
```go
package loads
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Load reference from local variable
type ALOAD struct{ base.Index8Instruction }
func (self *ALOAD) Execute(frame *rtda.Frame) {
_aload(frame, self.Index)
}
type ALOAD_0 struct{ base.NoOperandsInstruction }
func (self *ALOAD_0) Ex... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/loads/aload.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 262 |
```go
package base
import "jvmgo/ch05/rtda"
type Instruction interface {
FetchOperands(reader *BytecodeReader)
Execute(frame *rtda.Frame)
}
type NoOperandsInstruction struct {
// empty
}
func (self *NoOperandsInstruction) FetchOperands(reader *BytecodeReader) {
// nothing to do
}
type BranchInstruction struct ... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/base/instruction.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 191 |
```go
package loads
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Load double from local variable
type DLOAD struct{ base.Index8Instruction }
func (self *DLOAD) Execute(frame *rtda.Frame) {
_dload(frame, self.Index)
}
type DLOAD_0 struct{ base.NoOperandsInstruction }
func (self *DLOAD_0) Execu... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/loads/dload.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 263 |
```go
package loads
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Load float from local variable
type FLOAD struct{ base.Index8Instruction }
func (self *FLOAD) Execute(frame *rtda.Frame) {
_fload(frame, self.Index)
}
type FLOAD_0 struct{ base.NoOperandsInstruction }
func (self *FLOAD_0) Execut... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/loads/fload.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 263 |
```go
package loads
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Load int from local variable
type ILOAD struct{ base.Index8Instruction }
func (self *ILOAD) Execute(frame *rtda.Frame) {
_iload(frame, self.Index)
}
type ILOAD_0 struct{ base.NoOperandsInstruction }
func (self *ILOAD_0) Execute(... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/loads/iload.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 262 |
```go
package loads
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Load long from local variable
type LLOAD struct{ base.Index8Instruction }
func (self *LLOAD) Execute(frame *rtda.Frame) {
_lload(frame, self.Index)
}
type LLOAD_0 struct{ base.NoOperandsInstruction }
func (self *LLOAD_0) Execute... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/loads/lload.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 263 |
```go
package extended
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Branch if reference is null
type IFNULL struct{ base.BranchInstruction }
func (self *IFNULL) Execute(frame *rtda.Frame) {
ref := frame.OperandStack().PopRef()
if ref == nil {
base.Branch(frame, self.Offset)
}
}
// Branch i... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/extended/ifnull.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 144 |
```go
package extended
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Branch always (wide index)
type GOTO_W struct {
offset int
}
func (self *GOTO_W) FetchOperands(reader *base.BytecodeReader) {
self.offset = int(reader.ReadInt32())
}
func (self *GOTO_W) Execute(frame *rtda.Frame) {
base.Branc... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/extended/goto_w.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 96 |
```go
package extended
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/instructions/loads"
import "jvmgo/ch05/instructions/math"
import "jvmgo/ch05/instructions/stores"
import "jvmgo/ch05/rtda"
// Extend local variable index by additional bytes
type WIDE struct {
modifiedInstruction base.Instruction
}
func... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/extended/wide.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 511 |
```go
package comparisons
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Compare long
type LCMP struct{ base.NoOperandsInstruction }
func (self *LCMP) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
v2 := stack.PopLong()
v1 := stack.PopLong()
if v1 > v2 {
stack.PushInt(1)
} else ... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/comparisons/lcmp.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 123 |
```go
package comparisons
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Compare float
type FCMPG struct{ base.NoOperandsInstruction }
func (self *FCMPG) Execute(frame *rtda.Frame) {
_fcmp(frame, true)
}
type FCMPL struct{ base.NoOperandsInstruction }
func (self *FCMPL) Execute(frame *rtda.Fram... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/comparisons/fcmp.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 217 |
```go
package comparisons
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Branch if int comparison with zero succeeds
type IFEQ struct{ base.BranchInstruction }
func (self *IFEQ) Execute(frame *rtda.Frame) {
val := frame.OperandStack().PopInt()
if val == 0 {
base.Branch(frame, self.Offset)
}
}... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/comparisons/ifcond.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 348 |
```go
package comparisons
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Compare double
type DCMPG struct{ base.NoOperandsInstruction }
func (self *DCMPG) Execute(frame *rtda.Frame) {
_dcmp(frame, true)
}
type DCMPL struct{ base.NoOperandsInstruction }
func (self *DCMPL) Execute(frame *rtda.Fra... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/comparisons/dcmp.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 217 |
```go
package comparisons
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Branch if reference comparison succeeds
type IF_ACMPEQ struct{ base.BranchInstruction }
func (self *IF_ACMPEQ) Execute(frame *rtda.Frame) {
if _acmp(frame) {
base.Branch(frame, self.Offset)
}
}
type IF_ACMPNE struct{ bas... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/comparisons/if_acmp.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 173 |
```go
package constants
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Do nothing
type NOP struct{ base.NoOperandsInstruction }
func (self *NOP) Execute(frame *rtda.Frame) {
// really do nothing
}
``` | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/constants/nop.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 62 |
```go
package comparisons
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Branch if int comparison succeeds
type IF_ICMPEQ struct{ base.BranchInstruction }
func (self *IF_ICMPEQ) Execute(frame *rtda.Frame) {
if val1, val2 := _icmpPop(frame); val1 == val2 {
base.Branch(frame, self.Offset)
}
}
t... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/comparisons/if_icmp.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 430 |
```go
package constants
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Push byte
type BIPUSH struct {
val int8
}
func (self *BIPUSH) FetchOperands(reader *base.BytecodeReader) {
self.val = reader.ReadInt8()
}
func (self *BIPUSH) Execute(frame *rtda.Frame) {
i := int32(self.val)
frame.OperandSt... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/constants/ipush.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 177 |
```go
package constants
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Push null
type ACONST_NULL struct{ base.NoOperandsInstruction }
func (self *ACONST_NULL) Execute(frame *rtda.Frame) {
frame.OperandStack().PushRef(nil)
}
// Push double
type DCONST_0 struct{ base.NoOperandsInstruction }
func... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/constants/const.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 688 |
```go
package stack
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Swap the top two operand stack values
type SWAP struct{ base.NoOperandsInstruction }
/*
bottom -> top
[...][c][b][a]
\/
/\
V V
[...][c][a][b]
*/
func (self *SWAP) Execute(frame *rtda.Frame) {
stack :=... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/stack/swap.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 131 |
```go
package stack
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Pop the top operand stack value
type POP struct{ base.NoOperandsInstruction }
/*
bottom -> top
[...][c][b][a]
|
V
[...][c][b]
*/
func (self *POP) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/stack/pop.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 181 |
```go
package conversions
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Convert double to float
type D2F struct{ base.NoOperandsInstruction }
func (self *D2F) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
d := stack.PopDouble()
f := float32(d)
stack.PushFloat(f)
}
// Convert dou... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/conversions/d2x.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 206 |
```go
package stack
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Duplicate the top operand stack value
type DUP struct{ base.NoOperandsInstruction }
/*
bottom -> top
[...][c][b][a]
\_
|
V
[...][c][b][a][a]
*/
func (self *DUP) Execute(frame *rtda.Frame) ... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/stack/dup.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 819 |
```go
package conversions
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Convert int to byte
type I2B struct{ base.NoOperandsInstruction }
func (self *I2B) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
i := stack.PopInt()
b := int32(int8(i))
stack.PushInt(b)
}
// Convert int to c... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/conversions/i2x.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 392 |
```go
package conversions
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Convert long to double
type L2D struct{ base.NoOperandsInstruction }
func (self *L2D) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
l := stack.PopLong()
d := float64(l)
stack.PushDouble(d)
}
// Convert long ... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/conversions/l2x.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 206 |
```go
package conversions
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Convert float to double
type F2D struct{ base.NoOperandsInstruction }
func (self *F2D) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
f := stack.PopFloat()
d := float64(f)
stack.PushDouble(d)
}
// Convert flo... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/conversions/f2x.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 206 |
```go
package control
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
// Branch always
type GOTO struct{ base.BranchInstruction }
func (self *GOTO) Execute(frame *rtda.Frame) {
base.Branch(frame, self.Offset)
}
``` | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/control/goto.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 63 |
```go
package control
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
/*
tableswitch
<0-3 byte pad>
defaultbyte1
defaultbyte2
defaultbyte3
defaultbyte4
lowbyte1
lowbyte2
lowbyte3
lowbyte4
highbyte1
highbyte2
highbyte3
highbyte4
jump offsets...
*/
// Access jump table by index and jump
type TABLE_SWITCH... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/control/tableswitch.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 274 |
```go
package control
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"
/*
lookupswitch
<0-3 byte pad>
defaultbyte1
defaultbyte2
defaultbyte3
defaultbyte4
npairs1
npairs2
npairs3
npairs4
match-offset pairs...
*/
// Access jump table by key match and jump
type LOOKUP_SWITCH struct {
defaultOffset int32
... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/instructions/control/lookupswitch.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 259 |
```go
package classfile
/*
EnclosingMethod_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 class_index;
u2 method_index;
}
*/
type EnclosingMethodAttribute struct {
cp ConstantPool
classIndex uint16
methodIndex uint16
}
func (self *EnclosingMethodAttribute) readInfo(reader *C... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/classfile/attr_enclosing_method.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 170 |
```go
package classfile
/*
field_info {
u2 access_flags;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
attribute_info attributes[attributes_count];
}
method_info {
u2 access_flags;
u2 name_index;
u2 ... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/classfile/member_info.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 380 |
```go
package classfile
/*
CONSTANT_MethodHandle_info {
u1 tag;
u1 reference_kind;
u2 reference_index;
}
*/
type ConstantMethodHandleInfo struct {
referenceKind uint8
referenceIndex uint16
}
func (self *ConstantMethodHandleInfo) readInfo(reader *ClassReader) {
self.referenceKind = reader.readUint8()
... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/classfile/cp_invoke_dynamic.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 241 |
```go
package classfile
/*
BootstrapMethods_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 num_bootstrap_methods;
{ u2 bootstrap_method_ref;
u2 num_bootstrap_arguments;
u2 bootstrap_arguments[num_bootstrap_arguments];
} bootstrap_methods[num_bootstrap_methods];
}
*/
... | /content/code_sandbox/v1/code/go/src/jvmgo/ch05/classfile/attr_bootstrap_methods.go | go | 2016-01-06T13:13:45 | 2024-08-16T13:42:58 | jvmgo-book | zxh0/jvmgo-book | 1,605 | 184 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.