Handle-ize BytecodeEmitter.
Handle-ize BytecodeEmitter.
1.1 --- a/jitcraft/BytecodeCompiler.cpp Tue Jul 03 00:32:19 2012 -0700
1.2 +++ b/jitcraft/BytecodeCompiler.cpp Tue Jul 03 00:36:48 2012 -0700
1.3 @@ -702,7 +702,7 @@
1.4 return NULL;
1.5
1.6 for (size_t i = 0; i < __ objects()->size(); i++)
1.7 - objects->set(zone_, i, __ objects()->at(i));
1.8 + objects->set(zone_, i, *(__ objects()->at(i)));
1.9
1.10 Local<Code> code(zone_, Code::New(zone_, bytes, locals_, objects, __ maxStackDepth(), module_));
1.11 if (!code)
2.1 --- a/jitcraft/BytecodeEmitter.h Tue Jul 03 00:32:19 2012 -0700
2.2 +++ b/jitcraft/BytecodeEmitter.h Tue Jul 03 00:36:48 2012 -0700
2.3 @@ -1,4 +1,5 @@
2.4 -/*
2.5 +/* vim: set ts=4 sw=4 tw=99 et:
2.6 + *
2.7 * Copyright (C) 2012 David Anderson
2.8 *
2.9 * This file is part of JITCraft.
2.10 @@ -23,12 +24,15 @@
2.11 #include <vector>
2.12 #include "Opcodes.h"
2.13 #include "NameBinding.h"
2.14 +#include "Handles.h"
2.15
2.16 namespace jc {
2.17
2.18 class Type;
2.19 class Map;
2.20
2.21 +typedef std::vector<ScopedRoot<Object> *> ObjectList;
2.22 +
2.23 class BytecodeEmitter
2.24 {
2.25 bytecode *buffer_;
2.26 @@ -38,7 +42,7 @@
2.27 bool oom_;
2.28 unsigned maxStackDepth_;
2.29 unsigned stackDepth_;
2.30 - std::vector<Object *> objects_;
2.31 + ObjectList objects_;
2.32
2.33 private:
2.34 static const size_t MAX_LENGTH = INT_MAX / 2;
2.35 @@ -80,7 +84,10 @@
2.36 }
2.37 void writeObject(Object *obj) {
2.38 writeUint32(objects_.size());
2.39 - objects_.push_back(obj);
2.40 + ScopedRoot<Object> *root = new ScopedRoot<Object>(obj);
2.41 + if (!root)
2.42 + oom_ = true;
2.43 + objects_.push_back(root);
2.44 }
2.45
2.46 int position() const {
2.47 @@ -106,7 +113,7 @@
2.48 unsigned maxStackDepth() const {
2.49 return maxStackDepth_;
2.50 }
2.51 - const std::vector<Object *> *objects() const {
2.52 + const ObjectList *objects() const {
2.53 return &objects_;
2.54 }
2.55
2.56 @@ -310,7 +317,7 @@
2.57 void cvt_i2f() {
2.58 singleByteOp(OP_CVT_I2F);
2.59 }
2.60 - void newarray_lifo(Map *map) {
2.61 + void newarray_lifo(Handle<Map> map) {
2.62 ensure(OP_NEWARRAY_LIFO_LENGTH);
2.63 writeOp(OP_NEWARRAY_LIFO);
2.64 writeObject(map);
2.65 @@ -375,7 +382,7 @@
2.66 singleByteOp(OP_SETREF_F);
2.67 }
2.68 }
2.69 - void object(Object *obj) {
2.70 + void object(Handle<Object> obj) {
2.71 ensure(OP_OBJECT_LENGTH);
2.72 writeOp(OP_OBJECT);
2.73 writeObject(obj);