1.1 --- a/jitcraft/Zone.h Mon Jul 02 14:04:29 2012 -0700
1.2 +++ b/jitcraft/Zone.h Mon Jul 02 23:37:12 2012 -0700
1.3 @@ -1,4 +1,5 @@
1.4 -/*
1.5 +/* vim: set ts=4 sw=4 tw=99 et:
1.6 + *
1.7 * Copyright (C) 2012 David Anderson
1.8 *
1.9 * This file is part of JITCraft.
1.10 @@ -40,7 +41,7 @@
1.11 TypeManager *types_;
1.12
1.13 // Root list.
1.14 - Local<Object> *lastThingLocal_;
1.15 + Local<Object> *lastLocalRoot_;
1.16
1.17 public:
1.18 Zone();
1.19 @@ -57,11 +58,8 @@
1.20 }
1.21 Object *allocate(MapKind kind, size_t bytes, Heap::Tenure tenure = Heap::Tenure_Default) {
1.22 assert(maps_[kind]);
1.23 - return allocate(maps_[kind], bytes, tenure);
1.24 - }
1.25 - // :TODO: handle
1.26 - Object *allocate(Map *map, size_t bytes, Heap::Tenure tenure = Heap::Tenure_Default) {
1.27 - return heap_.allocate(map, bytes, tenure);
1.28 + Local<Map> map(this, maps_[kind]);
1.29 + return allocate(map, bytes, tenure);
1.30 }
1.31 Object *allocate(Handle<Map> map, size_t bytes, Heap::Tenure tenure = Heap::Tenure_Default) {
1.32 return heap_.allocate(map, bytes, tenure);
1.33 @@ -70,6 +68,10 @@
1.34 TypeManager *types() const {
1.35 return types_;
1.36 }
1.37 +
1.38 + Local<Object> **lastLocalRoot() {
1.39 + return &lastLocalRoot_;
1.40 + }
1.41 };
1.42
1.43 // In a multi-threaded system, this would be a TLS variable.
1.44 @@ -83,8 +85,8 @@
1.45
1.46 class LocalTop
1.47 {
1.48 + Top &mine_;
1.49 Top *prev_;
1.50 - Top &mine_;
1.51
1.52 public:
1.53 LocalTop(Top &mine)
1.54 @@ -100,6 +102,22 @@
1.55 }
1.56 };
1.57
1.58 +template <typename T>
1.59 +Local<T>::Local(Zone *zone, T *thing)
1.60 + : zone_(zone),
1.61 + thing_(thing),
1.62 + prev_(*zone->lastLocalRoot())
1.63 +{
1.64 + *zone->lastLocalRoot() = toRaw();
1.65 }
1.66
1.67 -#endif // _include_jitcraft_thread_h_
1.68 \ No newline at end of file
1.69 +template <typename T>
1.70 +Local<T>::~Local()
1.71 +{
1.72 + assert(*zone_->lastLocalRoot() == toRaw());
1.73 + *zone_->lastLocalRoot() = prev_;
1.74 +}
1.75 +
1.76 +}
1.77 +
1.78 +#endif // _include_jitcraft_thread_h_