Skip to content
This repository
Browse code

initial commit

  • Loading branch information...
commit 9ed7dbb3d5b3f4aa33441733de35ba2fbc9b53e2 0 parents
authored May 21, 2007
109  src/types.def
... ...
@@ -0,0 +1,109 @@
  1
+(type class
  2
+  (uintptr_t id)
  3
+  (object name)
  4
+  (object super)
  5
+  (object objectMask)
  6
+  (object fieldTable)
  7
+  (object methodTable)
  8
+  (object staticTable))
  9
+
  10
+(type objectMask
  11
+  (uint32_t maskLength)
  12
+  (uint32_t arrayMaskLength)
  13
+  (array uint32_t body))
  14
+
  15
+(pod field
  16
+  (uint16_t flags)
  17
+  (object name)
  18
+  (object class))
  19
+
  20
+(type fieldTable
  21
+  (object index)
  22
+  (array field body))
  23
+
  24
+(pod method
  25
+  (uint16_t flags)
  26
+  (object name)
  27
+  (object spec)
  28
+  (object code))
  29
+
  30
+(type methodTable
  31
+  (object index)
  32
+  (array method body))
  33
+
  34
+(pod exceptionHandler
  35
+  (uint16_t start)
  36
+  (uint16_t end)
  37
+  (uint16_t handler)
  38
+  (uint16_t catchType))
  39
+
  40
+(type exceptionHandlerTable
  41
+  (array exceptionHandler body))
  42
+
  43
+(type code
  44
+  (object pool)
  45
+  (object exceptionHandlerTable)
  46
+  (uint16_t maxStack)
  47
+  (uint16_t maxLocals)
  48
+  (array uint8_t body))
  49
+
  50
+(type frame
  51
+  (object code)
  52
+  (uint32_t ip)
  53
+  (array object locals))
  54
+
  55
+(type reference
  56
+  (object class)
  57
+  (object name)
  58
+  (object spec))
  59
+
  60
+(type string
  61
+  (uint32_t hash)
  62
+  (uint32_t id)
  63
+  (array char value))
  64
+
  65
+(type byte
  66
+  (uint8_t value))
  67
+
  68
+(type short
  69
+  (uint16_t value))
  70
+
  71
+(type int
  72
+  (uint32_t value))
  73
+
  74
+(type long
  75
+  (uint64_t value))
  76
+
  77
+(type float
  78
+  (uint32_t value))
  79
+
  80
+(type double
  81
+  (uint64_t value))
  82
+
  83
+(type rawArray
  84
+  (array object body))
  85
+
  86
+(type objectArray
  87
+  (object elementClass)
  88
+  (array object body))
  89
+
  90
+(type byteArray
  91
+  (array uint8_t body))
  92
+
  93
+(type shortArray
  94
+  (array uint16_t body))
  95
+
  96
+(type charArray
  97
+  (array uint16_t body))
  98
+
  99
+(type intArray
  100
+  (array uint32_t body))
  101
+
  102
+(type longArray
  103
+  (array uint64_t body))
  104
+
  105
+(type floatArray
  106
+  (array uint32_t body))
  107
+
  108
+(type doubleArray
  109
+  (array uint64_t body))
188  src/vm.cpp
... ...
@@ -0,0 +1,188 @@
  1
+
  2
+namespace {
  3
+
  4
+object
  5
+run(Thread* t)
  6
+{
  7
+  unsigned ip = 0;
  8
+
  9
+#define PUSH(x) t->stack[(t->sp)++] = x
  10
+#define POP(x) x = t->stack[--(t->sp)]
  11
+#define NEXT ++ ip; goto loop
  12
+
  13
+ loop:
  14
+  switch (codeBody(t->code)[ip]) {
  15
+  case aaload: {
  16
+    object index; POP(index);
  17
+    object array; POP(array);
  18
+
  19
+    if (array) {
  20
+      int32_t i = intValue(index);
  21
+      if (i >= 0 and i < objectArrayLength(array)) {
  22
+        PUSH(objectArrayBody(array)[i]);
  23
+      } else {
  24
+        object message = makeString(t, "%d not in [0,%d]", i,
  25
+                                    objectArrayLength(array));
  26
+        t->exception = makeAIOOBException(t, message);
  27
+        goto throw_;
  28
+      }
  29
+    } else {
  30
+      t->exception = makeNPException(t, 0);
  31
+      goto throw_;
  32
+    }
  33
+  } NEXT;
  34
+
  35
+  case aastore: {
  36
+    object value; POP(value);
  37
+    object index; POP(index);
  38
+    object array; POP(array);
  39
+    int32_t i = intValue(index);
  40
+
  41
+    if (array) {
  42
+      if (i >= 0 and i < objectArrayLength(array)) {
  43
+        set(t, objectArrayBody(array)[i], value);
  44
+      } else {
  45
+        object message = makeString(t, "%d not in [0,%d]", i,
  46
+                                    objectArrayLength(array));
  47
+        t->exception = makeAIOOBException(t, message);
  48
+        goto throw_;
  49
+      }
  50
+    } else {
  51
+      t->exception = makeNPException(t, 0);
  52
+      goto throw_;
  53
+    }
  54
+  } NEXT;
  55
+
  56
+  case aconst_null: {
  57
+    PUSH(0);
  58
+  } NEXT;
  59
+
  60
+  case aload: {
  61
+    PUSH(frameBody(t->frame)[codeBody(t->code)[++ip]]);
  62
+  } NEXT;
  63
+
  64
+  case aload_0: {
  65
+    PUSH(frameBody(t->frame)[0]);
  66
+  } NEXT;
  67
+
  68
+  case aload_1: {
  69
+    PUSH(frameBody(t->frame)[1]);
  70
+  } NEXT;
  71
+
  72
+  case aload_2: {
  73
+    PUSH(frameBody(t->frame)[2]);
  74
+  } NEXT;
  75
+
  76
+  case aload_3: {
  77
+    PUSH(frameBody(t->frame)[3]);
  78
+  } NEXT;
  79
+
  80
+  case anewarray: {
  81
+    object count; POP(count);
  82
+    int32_t c = intValue(count);
  83
+
  84
+    if (c >= 0) {
  85
+      uint8_t index1 = codeBody(t->code)[++ip];
  86
+      uint8_t index2 = codeBody(t->code)[++ip];
  87
+      uint16_t index = (index1 << 8) | index2;
  88
+      
  89
+      object class_ = resolvePoolEntry(t, codePool(t->code), index);
  90
+      if (t->exception) goto throw_;
  91
+      
  92
+      object array = makeObjectArray(t, class_, c);
  93
+      memset(objectArrayBody(array), 0, c * 4);
  94
+      
  95
+      PUSH(array);
  96
+    } else {
  97
+      object message = makeString(t, "%d", c);
  98
+      t->exception = makeNASException(t, message);
  99
+      goto throw_;
  100
+    }
  101
+  } NEXT;
  102
+
  103
+  case areturn: {
  104
+    object value; POP(value);
  105
+    if (t->sp) {
  106
+      POP(t->frame);
  107
+      t->code = frameCode(t->frame);
  108
+      ip = frameIp(t->frame);
  109
+      PUSH(value);
  110
+      goto loop;
  111
+    } else {
  112
+      return value;
  113
+    }
  114
+  } NEXT;
  115
+
  116
+  case arraylength: {
  117
+    object array; POP(array);
  118
+    if (array) {
  119
+      PUSH(makeInt(t, arrayLength(array)));
  120
+    } else {
  121
+      t->exception = makeNPException(t, 0);
  122
+      goto throw_;
  123
+    }
  124
+  } UNREACHABLE;
  125
+
  126
+  case astore: {
  127
+    object value; POP(value);
  128
+    set(t, frameBody(t->frame)[codeBody(t->code)[++ip]], value);
  129
+  } NEXT;
  130
+
  131
+  case astore_0: {
  132
+    object value; POP(value);
  133
+    set(t, frameBody(t->frame)[0], value);
  134
+  } NEXT;
  135
+
  136
+  case astore_1: {
  137
+    object value; POP(value);
  138
+    set(t, frameBody(t->frame)[1], value);
  139
+  } NEXT;
  140
+
  141
+  case astore_2: {
  142
+    object value; POP(value);
  143
+    set(t, frameBody(t->frame)[2], value);
  144
+  } NEXT;
  145
+
  146
+  case astore_3: {
  147
+    object value; POP(value);
  148
+    set(t, frameBody(t->frame)[3], value);
  149
+  } NEXT;
  150
+
  151
+  case athrow: {
  152
+    POP(t->exception);
  153
+    goto throw_;
  154
+  } UNREACHABLE;
  155
+  }
  156
+
  157
+ throw_:
  158
+  for (; t->sp >= 0; --(t->sp)) {
  159
+    if (typeOf(t->stack[t->sp]) == FrameType) {
  160
+      t->frame = t->stack[t->sp];
  161
+      t->code = frameCode(t->frame);
  162
+      object eht = codeExceptionHandlerTable(t->code);
  163
+      if (eht) {
  164
+        for (unsigned i = 0; i < exceptionHandleTableLength(eht); ++i) {
  165
+          ExceptionHandler* eh = exceptionHandlerTableBody(eht)[i];
  166
+          uint16_t catchType = exceptionHandlerCatchType(eh);
  167
+          if (catchType == 0 or
  168
+              instanceOf(rawArrayBody(codePool(t->code))[catchType],
  169
+                         t->exception))
  170
+          {
  171
+            ip = exceptionHandlerHandler(eh);
  172
+            PUSH(t->exception);
  173
+            t->exception = 0;
  174
+            goto loop;
  175
+          }
  176
+        }
  177
+      }
  178
+    }
  179
+  }
  180
+
  181
+  t->code = defaultExceptionHandler(t);
  182
+  ip = 0;
  183
+  PUSH(t->exception);
  184
+  t->exception = 0;
  185
+  goto loop;
  186
+}
  187
+
  188
+} // namespace

0 notes on commit 9ed7dbb

Please sign in to comment.
Something went wrong with that request. Please try again.