![](/media/cache/profiles/98c39996bf1543e974747a2549b3107c.50x50_q85.png)
JVM test
ravem.h@7:2a384a077520, 2013-08-29 (annotated)
- Committer:
- lynxeyed_atsu
- Date:
- Thu Aug 29 13:31:23 2013 +0000
- Revision:
- 7:2a384a077520
- Parent:
- 6:b9d0d96b052f
- Child:
- 9:4ea7773ea2b0
fixed memory pool manager to re-use freed memory
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lynxeyed_atsu | 5:047542b65d00 | 1 | /* |
lynxeyed_atsu | 5:047542b65d00 | 2 | * RAVEM.h |
lynxeyed_atsu | 5:047542b65d00 | 3 | * |
lynxeyed_atsu | 5:047542b65d00 | 4 | * Created on: 2013/07/18 |
lynxeyed_atsu | 5:047542b65d00 | 5 | * Author: lynxeyed |
lynxeyed_atsu | 5:047542b65d00 | 6 | */ |
lynxeyed_atsu | 5:047542b65d00 | 7 | |
lynxeyed_atsu | 5:047542b65d00 | 8 | #ifndef RAVEM_H_ |
lynxeyed_atsu | 5:047542b65d00 | 9 | #define RAVEM_H_ |
lynxeyed_atsu | 5:047542b65d00 | 10 | |
lynxeyed_atsu | 5:047542b65d00 | 11 | //#include "type.h" |
lynxeyed_atsu | 5:047542b65d00 | 12 | #include "pool.h" |
lynxeyed_atsu | 5:047542b65d00 | 13 | #include "device_depend.h" |
lynxeyed_atsu | 5:047542b65d00 | 14 | #include <stdlib.h> |
lynxeyed_atsu | 5:047542b65d00 | 15 | |
lynxeyed_atsu | 5:047542b65d00 | 16 | // constant_pool |
lynxeyed_atsu | 5:047542b65d00 | 17 | //#define Constant_Type Value length (in bytes) |
lynxeyed_atsu | 6:b9d0d96b052f | 18 | #define CONSTANT_Class 7 // 3 |
lynxeyed_atsu | 6:b9d0d96b052f | 19 | #define CONSTANT_Fieldref 9 // 5 |
lynxeyed_atsu | 6:b9d0d96b052f | 20 | #define CONSTANT_Methodref 10 // 5 |
lynxeyed_atsu | 6:b9d0d96b052f | 21 | #define CONSTANT_InterfaceMethodref 11 // 5 |
lynxeyed_atsu | 6:b9d0d96b052f | 22 | #define CONSTANT_String 8 // 3 |
lynxeyed_atsu | 6:b9d0d96b052f | 23 | #define CONSTANT_Integer 3 // 5 |
lynxeyed_atsu | 6:b9d0d96b052f | 24 | #define CONSTANT_Float 4 // 5 |
lynxeyed_atsu | 6:b9d0d96b052f | 25 | #define CONSTANT_Long 5 // 9 |
lynxeyed_atsu | 6:b9d0d96b052f | 26 | #define CONSTANT_Double 6 // 9 |
lynxeyed_atsu | 5:047542b65d00 | 27 | #define CONSTANT_NameAndType 12 // 5 |
lynxeyed_atsu | 6:b9d0d96b052f | 28 | #define CONSTANT_Utf8 1 // 4 or more (see 'length') |
lynxeyed_atsu | 5:047542b65d00 | 29 | #define CONSTANT_MethodHandle 15 // 5 |
lynxeyed_atsu | 5:047542b65d00 | 30 | #define CONSTANT_MethodType 16 // 3 |
lynxeyed_atsu | 6:b9d0d96b052f | 31 | #define CONSTANT_InvokeDynamic 18 // 3 |
lynxeyed_atsu | 5:047542b65d00 | 32 | |
lynxeyed_atsu | 5:047542b65d00 | 33 | //stack type |
lynxeyed_atsu | 6:b9d0d96b052f | 34 | #define Stack_Nothing 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 35 | #define Stack_CharType 1 |
lynxeyed_atsu | 6:b9d0d96b052f | 36 | #define Stack_IntType 2 |
lynxeyed_atsu | 6:b9d0d96b052f | 37 | #define Stack_DoubleType 3 |
lynxeyed_atsu | 5:047542b65d00 | 38 | #define Stack_ConstantPool 4 |
lynxeyed_atsu | 5:047542b65d00 | 39 | |
lynxeyed_atsu | 5:047542b65d00 | 40 | //Thread State and Command |
lynxeyed_atsu | 6:b9d0d96b052f | 41 | #define Thread_returned 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 42 | #define Thread_Active 1 |
lynxeyed_atsu | 6:b9d0d96b052f | 43 | #define Thread_getStartMethod 2 |
lynxeyed_atsu | 6:b9d0d96b052f | 44 | #define Thread_getInitMethod 3 |
lynxeyed_atsu | 5:047542b65d00 | 45 | #define Thread_getInitMethodWithStack 4 |
lynxeyed_atsu | 6:b9d0d96b052f | 46 | #define Thread_init 5 |
lynxeyed_atsu | 6:b9d0d96b052f | 47 | #define Thread_initIsDone 6 |
lynxeyed_atsu | 6:b9d0d96b052f | 48 | #define Thread_inSleep 7 |
lynxeyed_atsu | 5:047542b65d00 | 49 | |
lynxeyed_atsu | 6:b9d0d96b052f | 50 | // instruction code mnemonic code number of arguments |
lynxeyed_atsu | 6:b9d0d96b052f | 51 | #define JAVA_nop 0x00 // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 52 | #define JAVA_iconst_0 0x03 // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 53 | #define JAVA_iconst_1 0x04 // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 54 | #define JAVA_iconst_2 0x05 // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 55 | #define JAVA_iconst_3 0x06 // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 56 | #define JAVA_iconst_4 0x07 // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 57 | #define JAVA_iconst_5 0x08 // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 58 | #define JAVA_bipush 0x10 // 1 |
lynxeyed_atsu | 6:b9d0d96b052f | 59 | #define JAVA_sipush 0x11 // 2 |
lynxeyed_atsu | 6:b9d0d96b052f | 60 | #define JAVA_ldc 0x12 // 1 |
lynxeyed_atsu | 6:b9d0d96b052f | 61 | //#define JAVA_ldc_w 0x13 // xxx |
lynxeyed_atsu | 6:b9d0d96b052f | 62 | #define JAVA_ldc2_w 0x14 // 2 |
lynxeyed_atsu | 5:047542b65d00 | 63 | |
lynxeyed_atsu | 6:b9d0d96b052f | 64 | #define JAVA_aload 0x19 // 1 |
lynxeyed_atsu | 5:047542b65d00 | 65 | |
lynxeyed_atsu | 6:b9d0d96b052f | 66 | #define JAVA_iload_0 0x1A // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 67 | #define JAVA_iload_1 0x1B // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 68 | #define JAVA_iload_2 0x1C // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 69 | #define JAVA_iload_3 0x1D // 0 |
lynxeyed_atsu | 5:047542b65d00 | 70 | |
lynxeyed_atsu | 6:b9d0d96b052f | 71 | #define JAVA_aload_0 0x2a // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 72 | #define JAVA_aload_1 0x2b // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 73 | #define JAVA_aload_2 0x2c // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 74 | #define JAVA_aload_3 0x2d // 0 |
lynxeyed_atsu | 5:047542b65d00 | 75 | |
lynxeyed_atsu | 6:b9d0d96b052f | 76 | #define JAVA_astore 0x3A // 1 |
lynxeyed_atsu | 5:047542b65d00 | 77 | |
lynxeyed_atsu | 6:b9d0d96b052f | 78 | #define JAVA_istore_0 0x3B // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 79 | #define JAVA_istore_1 0x3C // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 80 | #define JAVA_istore_2 0x3D // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 81 | #define JAVA_istore_3 0x3E // 0 |
lynxeyed_atsu | 5:047542b65d00 | 82 | |
lynxeyed_atsu | 6:b9d0d96b052f | 83 | #define JAVA_astore_0 0x4b // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 84 | #define JAVA_astore_1 0x4c // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 85 | #define JAVA_astore_2 0x4d // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 86 | #define JAVA_astore_3 0x4e // 0 |
lynxeyed_atsu | 5:047542b65d00 | 87 | |
lynxeyed_atsu | 6:b9d0d96b052f | 88 | #define JAVA_dup 0x59 // 0 |
lynxeyed_atsu | 5:047542b65d00 | 89 | |
lynxeyed_atsu | 6:b9d0d96b052f | 90 | #define JAVA_iadd 0x60 // 0 |
lynxeyed_atsu | 5:047542b65d00 | 91 | |
lynxeyed_atsu | 6:b9d0d96b052f | 92 | #define JAVA_i2l 0x85 // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 93 | #define JAVA_i2c 0x92 // 0 |
lynxeyed_atsu | 5:047542b65d00 | 94 | |
lynxeyed_atsu | 6:b9d0d96b052f | 95 | #define JAVA_goto 0xa7 // 2 |
lynxeyed_atsu | 6:b9d0d96b052f | 96 | #define JAVA_return 0xb1 // 0 |
lynxeyed_atsu | 6:b9d0d96b052f | 97 | #define JAVA_getstatic 0xb2 // 2 |
lynxeyed_atsu | 6:b9d0d96b052f | 98 | #define JAVA_getfield 0xb4 // 2 |
lynxeyed_atsu | 6:b9d0d96b052f | 99 | #define JAVA_putfield 0xb5 // 2 |
lynxeyed_atsu | 5:047542b65d00 | 100 | #define JAVA_invokevirtual 0xb6 // 2 |
lynxeyed_atsu | 5:047542b65d00 | 101 | #define JAVA_invokespecial 0xb7 // 2 //not imprement |
lynxeyed_atsu | 6:b9d0d96b052f | 102 | #define JAVA_invokestatic 0xb8 // 2 |
lynxeyed_atsu | 5:047542b65d00 | 103 | |
lynxeyed_atsu | 6:b9d0d96b052f | 104 | #define JAVA_new 0xbb // 2 |
lynxeyed_atsu | 5:047542b65d00 | 105 | |
lynxeyed_atsu | 5:047542b65d00 | 106 | typedef struct { |
lynxeyed_atsu | 6:b9d0d96b052f | 107 | int tag; |
lynxeyed_atsu | 5:047542b65d00 | 108 | int index; |
lynxeyed_atsu | 5:047542b65d00 | 109 | int index2; |
lynxeyed_atsu | 5:047542b65d00 | 110 | int bc_num; //pointer of bytecode |
lynxeyed_atsu | 5:047542b65d00 | 111 | void* stack_pt; // stack pointer (int,long,float,double,string) |
lynxeyed_atsu | 5:047542b65d00 | 112 | } const_pool_t; |
lynxeyed_atsu | 5:047542b65d00 | 113 | |
lynxeyed_atsu | 5:047542b65d00 | 114 | |
lynxeyed_atsu | 5:047542b65d00 | 115 | typedef struct { |
lynxeyed_atsu | 6:b9d0d96b052f | 116 | int bc_offset; // offset of bytecode (this class starts here = bc_array[bc_offset]) |
lynxeyed_atsu | 6:b9d0d96b052f | 117 | int code_offset; // offset of code (Now we translate here from bc_offset = bc_array[bc_offset+code_offset] ) |
lynxeyed_atsu | 6:b9d0d96b052f | 118 | int code_length; // length of code |
lynxeyed_atsu | 6:b9d0d96b052f | 119 | int stack_num; // number of stacks |
lynxeyed_atsu | 6:b9d0d96b052f | 120 | int local_num; // number of local registers |
lynxeyed_atsu | 6:b9d0d96b052f | 121 | int field_num; // number of field length |
lynxeyed_atsu | 6:b9d0d96b052f | 122 | int myThreadNum; // Number of this thread(you must put #0 "main" method, and do not put #0 any other methods) |
lynxeyed_atsu | 5:047542b65d00 | 123 | int threadCommand; // |
lynxeyed_atsu | 5:047542b65d00 | 124 | int threadArg; |
lynxeyed_atsu | 5:047542b65d00 | 125 | |
lynxeyed_atsu | 6:b9d0d96b052f | 126 | int *local_reg; // local registers(malloc here) |
lynxeyed_atsu | 6:b9d0d96b052f | 127 | int *op_stack; // operand stack(malloc here) numerics or CP num |
lynxeyed_atsu | 5:047542b65d00 | 128 | int *op_stack_type; // type of each stack,0:nothing 1:int,byte 2:long,float,double 3:See CP |
lynxeyed_atsu | 5:047542b65d00 | 129 | |
lynxeyed_atsu | 5:047542b65d00 | 130 | int *field_mem_reg; // Field (getfield and putfield) |
lynxeyed_atsu | 5:047542b65d00 | 131 | int *field_mem_type; // Member variable type (Int or String) |
lynxeyed_atsu | 5:047542b65d00 | 132 | |
lynxeyed_atsu | 5:047542b65d00 | 133 | } class_st; |
lynxeyed_atsu | 5:047542b65d00 | 134 | |
lynxeyed_atsu | 5:047542b65d00 | 135 | extern int32_t methods_count; |
lynxeyed_atsu | 6:b9d0d96b052f | 136 | |
lynxeyed_atsu | 6:b9d0d96b052f | 137 | void bc_init(void); |
lynxeyed_atsu | 6:b9d0d96b052f | 138 | char *bc_seek(int bc_num, int length); |
lynxeyed_atsu | 5:047542b65d00 | 139 | const_pool_t getConstantPoolInfo(int constant_num); |
lynxeyed_atsu | 5:047542b65d00 | 140 | const_pool_t seekConstClassNumString(int const_num); |
lynxeyed_atsu | 5:047542b65d00 | 141 | const_pool_t seekClassIndex(int const_num); |
lynxeyed_atsu | 5:047542b65d00 | 142 | const_pool_t seekNameAndType_name(int const_num); |
lynxeyed_atsu | 5:047542b65d00 | 143 | const_pool_t seekNameAndType_desc(int const_num); |
lynxeyed_atsu | 5:047542b65d00 | 144 | // |
lynxeyed_atsu | 5:047542b65d00 | 145 | int getIntegerFromOperandStack(class_st cl); |
lynxeyed_atsu | 5:047542b65d00 | 146 | char* getStringFromOperandStack(class_st cl); |
lynxeyed_atsu | 5:047542b65d00 | 147 | // |
lynxeyed_atsu | 6:b9d0d96b052f | 148 | class_st seekCodeArrtibute(class_st cl, char* method_name, int strlen); |
lynxeyed_atsu | 5:047542b65d00 | 149 | class_st setStackFromConstantPool(class_st cl, int cp_num); |
lynxeyed_atsu | 5:047542b65d00 | 150 | class_st setIntegerToStack(class_st cl, int num); |
lynxeyed_atsu | 5:047542b65d00 | 151 | // |
lynxeyed_atsu | 5:047542b65d00 | 152 | class_st getField(class_st cl, int cp_num); |
lynxeyed_atsu | 5:047542b65d00 | 153 | class_st putField(class_st cl, int cp_num); |
lynxeyed_atsu | 5:047542b65d00 | 154 | // |
lynxeyed_atsu | 5:047542b65d00 | 155 | class_st invokevirtual_callFunction(class_st cl, int cp_num); |
lynxeyed_atsu | 5:047542b65d00 | 156 | class_st invokestatic_callFunction(class_st cl, int cp_num); |
lynxeyed_atsu | 5:047542b65d00 | 157 | class_st invokespecial_callFunction(class_st cl, int cp_num); |
lynxeyed_atsu | 5:047542b65d00 | 158 | |
lynxeyed_atsu | 5:047542b65d00 | 159 | class_st decodeVM(class_st cl); |
lynxeyed_atsu | 5:047542b65d00 | 160 | |
lynxeyed_atsu | 5:047542b65d00 | 161 | #endif /* RAVEM_H_ */ |
lynxeyed_atsu | 5:047542b65d00 | 162 |