Revision: 4789
Author: lukezarko
Date: Wed Jun 2 09:14:32 2010
Log: - Remove [static] from methods in Zone and associated helpers.
- Experiment with a way to handle isolate-global statics.
Review URL: http://codereview.chromium.org/2493002
http://code.google.com/p/v8/source/detail?r=4789
Modified:
/branches/experimental/isolates/src/data-flow.h
/branches/experimental/isolates/src/isolate.cc
/branches/experimental/isolates/src/isolate.h
/branches/experimental/isolates/src/parser.cc
/branches/experimental/isolates/src/scopes.cc
/branches/experimental/isolates/src/zone-inl.h
/branches/experimental/isolates/src/zone.cc
/branches/experimental/isolates/src/zone.h
/branches/experimental/isolates/test/cctest/test-ast.cc
/branches/experimental/isolates/test/cctest/test-dataflow.cc
/branches/experimental/isolates/test/cctest/test-liveedit.cc
/branches/experimental/isolates/test/cctest/test-regexp.cc
/branches/experimental/isolates/test/cctest/test-strings.cc
=======================================
--- /branches/experimental/isolates/src/data-flow.h Mon Mar 29 07:23:55 2010
+++ /branches/experimental/isolates/src/data-flow.h Wed Jun 2 09:14:32 2010
@@ -45,7 +45,7 @@
explicit BitVector(int length)
: length_(length),
data_length_(SizeFor(length)),
- data_(Zone::NewArray<uint32_t>(data_length_)) {
+ data_(ZONE->NewArray<uint32_t>(data_length_)) {
ASSERT(length > 0);
Clear();
}
@@ -53,7 +53,7 @@
BitVector(const BitVector& other)
: length_(other.length()),
data_length_(SizeFor(length_)),
- data_(Zone::NewArray<uint32_t>(data_length_)) {
+ data_(ZONE->NewArray<uint32_t>(data_length_)) {
CopyFrom(other);
}
=======================================
--- /branches/experimental/isolates/src/isolate.cc Wed Jun 2 08:08:09 2010
+++ /branches/experimental/isolates/src/isolate.cc Wed Jun 2 09:14:32 2010
@@ -68,6 +68,10 @@
: bootstrapper_(NULL),
stub_cache_(NULL) {
handle_scope_data_.Initialize();
+#define ISOLATE_INIT_EXECUTE(type, name,
initial_value) \
+ name##_ = (initial_value);
+ ISOLATE_INIT_LIST(ISOLATE_INIT_EXECUTE)
+#undef ISOLATE_INIT_EXECUTE
}
=======================================
--- /branches/experimental/isolates/src/isolate.h Wed Jun 2 08:08:09 2010
+++ /branches/experimental/isolates/src/isolate.h Wed Jun 2 09:14:32 2010
@@ -30,6 +30,7 @@
#include "apiutils.h"
#include "heap.h"
+#include "zone.h"
namespace v8 {
namespace internal {
@@ -38,8 +39,13 @@
class Deserializer;
class StubCache;
+#define
ISOLATE_INIT_LIST(V) \
+ V(bool, zone_allow_allocation, true) /* AssertNoZoneAllocation */
+
class Isolate {
public:
+ ~Isolate();
+
// Returns the single global isolate.
static Isolate* Current() {
ASSERT(global_isolate != NULL);
@@ -52,20 +58,25 @@
// Initialize process-wide state.
static void InitOnce();
-
- ~Isolate();
-
- // Accessors.
+
+#define GLOBAL_ACCESSOR(type, name,
initialvalue) \
+ type name() const { return name##_;
} \
+ void set_##name(type value) { name##_ = value; }
+ ISOLATE_INIT_LIST(GLOBAL_ACCESSOR)
+#undef GLOBAL_ACCESSOR
+
+
Bootstrapper* bootstrapper() { return bootstrapper_; }
Heap* heap() { return &heap_; }
StubCache* stub_cache() { return stub_cache_; }
v8::ImplementationUtilities::HandleScopeData* handle_scope_data() {
return &handle_scope_data_;
}
+ Zone* zone() { return &zone_; }
private:
Isolate();
-
+
static Isolate* global_isolate;
bool Init(Deserializer* des);
@@ -74,12 +85,20 @@
Heap heap_;
StubCache* stub_cache_;
v8::ImplementationUtilities::HandleScopeData handle_scope_data_;
+ Zone zone_;
+
+#define GLOBAL_BACKING_STORE(type, name,
initialvalue) \
+ type name##_;
+ ISOLATE_INIT_LIST(GLOBAL_BACKING_STORE)
+#undef GLOBAL_BACKING_STORE
DISALLOW_COPY_AND_ASSIGN(Isolate);
};
-// Temporary macros for accessing fields off the global isolate.
+// Temporary macros for accessing fields off the global isolate. Define
these
+// when reformatting code would become burdensome.
#define HEAP (v8::internal::Isolate::Current()->heap())
+#define ZONE (v8::internal::Isolate::Current()->zone())
// Temporary macro to be used to flag definitions that are indeed static
@@ -87,6 +106,10 @@
#define RLYSTC static
+// Temporary macro to be used to flag classes that should be static.
+#define STATIC_CLASS class
+
+
} } // namespace v8::internal
#endif // V8_ISOLATE_H_
=======================================
--- /branches/experimental/isolates/src/parser.cc Tue Jun 1 03:51:42 2010
+++ /branches/experimental/isolates/src/parser.cc Wed Jun 2 09:14:32 2010
@@ -4293,7 +4293,7 @@
StackLimitCheck check;
if (check.HasOverflowed()) {
ReportError(CStrVector(Top::kStackOverflowMessage));
- } else if (Zone::excess_allocation()) {
+ } else if (ZONE->excess_allocation()) {
ReportError(CStrVector("Regular expression too large"));
} else {
current_ = in()->Get(next_pos_);
=======================================
--- /branches/experimental/isolates/src/scopes.cc Mon Mar 8 05:01:24 2010
+++ /branches/experimental/isolates/src/scopes.cc Wed Jun 2 09:14:32 2010
@@ -42,7 +42,7 @@
/* nothing to do */
virtual ~ZoneAllocator() {}
- virtual void* New(size_t size) { return
Zone::New(static_cast<int>(size)); }
+ virtual void* New(size_t size) { return
ZONE->New(static_cast<int>(size)); }
/* ignored - Zone is freed in one fell swoop */
virtual void Delete(void* p) {}
=======================================
--- /branches/experimental/isolates/src/zone-inl.h Tue Mar 2 02:03:38 2010
+++ /branches/experimental/isolates/src/zone-inl.h Wed Jun 2 09:14:32 2010
@@ -28,15 +28,27 @@
#ifndef V8_ZONE_INL_H_
#define V8_ZONE_INL_H_
+#include "isolate.h"
#include "zone.h"
#include "v8-counters.h"
namespace v8 {
namespace internal {
+
+
+AssertNoZoneAllocation::AssertNoZoneAllocation()
+ : prev_(Isolate::Current()->zone_allow_allocation()) {
+ Isolate::Current()->set_zone_allow_allocation(false);
+}
+
+
+AssertNoZoneAllocation::~AssertNoZoneAllocation() {
+ Isolate::Current()->set_zone_allow_allocation(prev_);
+}
inline void* Zone::New(int size) {
- ASSERT(AssertNoZoneAllocation::allow_allocation());
+ ASSERT(Isolate::Current()->zone_allow_allocation());
ASSERT(ZoneScope::nesting() > 0);
// Round up the requested size to fit the alignment.
size = RoundUp(size, kAlignment);
@@ -53,7 +65,7 @@
template <typename T>
T* Zone::NewArray(int length) {
- return static_cast<T*>(Zone::New(length * sizeof(T)));
+ return static_cast<T*>(New(length * sizeof(T)));
}
@@ -75,6 +87,19 @@
// freed by the Zone.
SplayTree<Config, ZoneListAllocationPolicy>::ResetRoot();
}
+
+
+// TODO(isolates): for performance reasons, this should be replaced with a
new
+// operator that takes the zone in which the object should
be
+// allocated.
+void* ZoneObject::operator new(size_t size) {
+ return ZONE->New(static_cast<int>(size));
+}
+
+
+inline void* ZoneListAllocationPolicy::New(int size) {
+ return ZONE->New(size);
+}
} } // namespace v8::internal
=======================================
--- /branches/experimental/isolates/src/zone.cc Tue Mar 2 02:03:38 2010
+++ /branches/experimental/isolates/src/zone.cc Wed Jun 2 09:14:32 2010
@@ -34,14 +34,21 @@
namespace internal {
-Address Zone::position_ = 0;
-Address Zone::limit_ = 0;
-int Zone::zone_excess_limit_ = 256 * MB;
-int Zone::segment_bytes_allocated_ = 0;
-
-bool AssertNoZoneAllocation::allow_allocation_ = true;
-
-int ZoneScope::nesting_ = 0;
+int ZoneScope::nesting_ = 0;
+
+Zone::Zone()
+ : zone_excess_limit_(256 * MB),
+ segment_bytes_allocated_(0),
+ position_(0),
+ limit_(0) {
+}
+
+
+ZoneScope::~ZoneScope() {
+ if (ShouldDeleteOnExit()) ZONE->DeleteAll();
+ --nesting_;
+}
+
// Segments represent chunks of memory: They have starting address
// (encoded in the this pointer) and a size in bytes. Segments are
@@ -67,7 +74,7 @@
// of the segment chain. Returns the new segment.
static Segment* New(int size) {
Segment* result = reinterpret_cast<Segment*>(Malloced::New(size));
- Zone::adjust_segment_bytes_allocated(size);
+ ZONE->adjust_segment_bytes_allocated(size);
if (result != NULL) {
result->next_ = head_;
result->size_ = size;
@@ -78,7 +85,7 @@
// Deletes the given segment. Does not touch the segment chain.
static void Delete(Segment* segment, int size) {
- Zone::adjust_segment_bytes_allocated(-size);
+ ZONE->adjust_segment_bytes_allocated(-size);
Malloced::Delete(segment);
}
=======================================
--- /branches/experimental/isolates/src/zone.h Tue Mar 2 02:03:38 2010
+++ /branches/experimental/isolates/src/zone.h Wed Jun 2 09:14:32 2010
@@ -57,22 +57,23 @@
public:
// Allocate 'size' bytes of memory in the Zone; expands the Zone by
// allocating new segments of memory on demand using malloc().
- static inline void* New(int size);
+ inline void* New(int size);
template <typename T>
- static inline T* NewArray(int length);
+ inline T* NewArray(int length);
// Delete all objects and free all memory allocated in the Zone.
- static void DeleteAll();
+ void DeleteAll();
// Returns true if more memory has been allocated in zones than
// the limit allows.
- static inline bool excess_allocation();
-
- static inline void adjust_segment_bytes_allocated(int delta);
+ inline bool excess_allocation();
+
+ inline void adjust_segment_bytes_allocated(int delta);
private:
-
+ friend class Isolate;
+
// All pointers returned from New() have this alignment.
static const int kAlignment = kPointerSize;
@@ -86,30 +87,28 @@
static const int kMaximumKeptSegmentSize = 64 * KB;
// Report zone excess when allocation exceeds this limit.
- static int zone_excess_limit_;
+ int zone_excess_limit_;
// The number of bytes allocated in segments. Note that this number
// includes memory allocated from the OS but not yet allocated from
// the zone.
- static int segment_bytes_allocated_;
-
- // The Zone is intentionally a singleton; you should not try to
- // allocate instances of the class.
- Zone() { UNREACHABLE(); }
-
+ int segment_bytes_allocated_;
+
+ // Each isolate gets its own zone.
+ Zone();
// Expand the Zone to hold at least 'size' more bytes and allocate
// the bytes. Returns the address of the newly allocated chunk of
// memory in the Zone. Should only be called if there isn't enough
// room in the Zone already.
- static Address NewExpand(int size);
+ Address NewExpand(int size);
// The free region in the current (front) segment is represented as
// the half-open interval [position, limit). The 'position' variable
// is guaranteed to be aligned as dictated by kAlignment.
- static Address position_;
- static Address limit_;
+ Address position_;
+ Address limit_;
};
@@ -118,7 +117,7 @@
class ZoneObject {
public:
// Allocate a new ZoneObject of 'size' bytes in the Zone.
- void* operator new(size_t size) { return
Zone::New(static_cast<int>(size)); }
+ inline void* operator new(size_t size);
// Ideally, the delete operator should be private instead of
// public, but unfortunately the compiler sometimes synthesizes
@@ -134,14 +133,10 @@
class AssertNoZoneAllocation {
public:
- AssertNoZoneAllocation() : prev_(allow_allocation_) {
- allow_allocation_ = false;
- }
- ~AssertNoZoneAllocation() { allow_allocation_ = prev_; }
- static bool allow_allocation() { return allow_allocation_; }
+ inline AssertNoZoneAllocation();
+ inline ~AssertNoZoneAllocation();
private:
bool prev_;
- static bool allow_allocation_;
};
@@ -151,7 +146,7 @@
class ZoneListAllocationPolicy {
public:
// Allocate 'size' bytes of memory in the zone.
- static void* New(int size) { return Zone::New(size); }
+ static inline void* New(int size);
// De-allocation attempts are silently ignored.
static void Delete(void* p) { }
@@ -181,10 +176,7 @@
nesting_++;
}
- virtual ~ZoneScope() {
- if (ShouldDeleteOnExit()) Zone::DeleteAll();
- --nesting_;
- }
+ virtual ~ZoneScope();
bool ShouldDeleteOnExit() {
return nesting_ == 1 && mode_ == DELETE_ON_EXIT;
=======================================
--- /branches/experimental/isolates/test/cctest/test-ast.cc Thu Jul 30
05:25:24 2009
+++ /branches/experimental/isolates/test/cctest/test-ast.cc Wed Jun 2
09:14:32 2010
@@ -35,6 +35,7 @@
using namespace v8::internal;
TEST(List) {
+ v8::internal::V8::Initialize(NULL);
List<AstNode*>* list = new List<AstNode*>(0);
CHECK_EQ(0, list->length());
=======================================
--- /branches/experimental/isolates/test/cctest/test-dataflow.cc Wed Mar 10
00:31:25 2010
+++ /branches/experimental/isolates/test/cctest/test-dataflow.cc Wed Jun 2
09:14:32 2010
@@ -35,6 +35,7 @@
using namespace v8::internal;
TEST(BitVector) {
+ v8::internal::V8::Initialize(NULL);
ZoneScope zone(DELETE_ON_EXIT);
{
BitVector v(15);
=======================================
--- /branches/experimental/isolates/test/cctest/test-liveedit.cc Tue Apr 27
14:20:02 2010
+++ /branches/experimental/isolates/test/cctest/test-liveedit.cc Wed Jun 2
09:14:32 2010
@@ -156,6 +156,7 @@
// --- T h e A c t u a l T e s t s
TEST(LiveEditDiffer) {
+ v8::internal::V8::Initialize(NULL);
CompareStrings("zz1zzz12zz123zzz", "zzzzzzzzzz", 6);
CompareStrings("zz1zzz12zz123zzz", "zz0zzz0zz0zzz", 9);
CompareStrings("123456789", "987654321", 16);
=======================================
--- /branches/experimental/isolates/test/cctest/test-regexp.cc Mon Apr 19
12:30:11 2010
+++ /branches/experimental/isolates/test/cctest/test-regexp.cc Wed Jun 2
09:14:32 2010
@@ -459,6 +459,7 @@
TEST(CharacterClassEscapes) {
+ v8::internal::V8::Initialize(NULL);
TestCharacterClassEscapes('.', IsRegExpNewline);
TestCharacterClassEscapes('d', IsDigit);
TestCharacterClassEscapes('D', NotDigit);
@@ -525,6 +526,7 @@
TEST(SplayTreeSimple) {
+ v8::internal::V8::Initialize(NULL);
static const unsigned kLimit = 1000;
ZoneScope zone_scope(DELETE_ON_EXIT);
ZoneSplayTree<TestConfig> tree;
@@ -577,6 +579,7 @@
TEST(DispatchTableConstruction) {
+ v8::internal::V8::Initialize(NULL);
// Initialize test data.
static const int kLimit = 1000;
static const int kRangeCount = 8;
@@ -1336,6 +1339,7 @@
TEST(AddInverseToTable) {
+ v8::internal::V8::Initialize(NULL);
static const int kLimit = 1000;
static const int kRangeCount = 16;
for (int t = 0; t < 10; t++) {
@@ -1511,6 +1515,7 @@
TEST(CharacterRangeCaseIndependence) {
+ v8::internal::V8::Initialize(NULL);
TestSimpleRangeCaseIndependence(CharacterRange::Singleton('a'),
CharacterRange::Singleton('A'));
TestSimpleRangeCaseIndependence(CharacterRange::Singleton('z'),
@@ -1552,6 +1557,7 @@
TEST(CharClassDifference) {
+ v8::internal::V8::Initialize(NULL);
ZoneScope zone_scope(DELETE_ON_EXIT);
ZoneList<CharacterRange>* base = new ZoneList<CharacterRange>(1);
base->Add(CharacterRange::Everything());
@@ -1578,6 +1584,7 @@
TEST(CanonicalizeCharacterSets) {
+ v8::internal::V8::Initialize(NULL);
ZoneScope scope(DELETE_ON_EXIT);
ZoneList<CharacterRange>* list = new ZoneList<CharacterRange>(4);
CharacterSet set(list);
@@ -1648,6 +1655,7 @@
}
TEST(CharacterRangeMerge) {
+ v8::internal::V8::Initialize(NULL);
ZoneScope zone_scope(DELETE_ON_EXIT);
ZoneList<CharacterRange> l1(4);
ZoneList<CharacterRange> l2(4);
=======================================
--- /branches/experimental/isolates/test/cctest/test-strings.cc Wed Jun 2
07:19:54 2010
+++ /branches/experimental/isolates/test/cctest/test-strings.cc Wed Jun 2
09:14:32 2010
@@ -113,7 +113,7 @@
break;
}
case 2: {
- uc16* buf = Zone::NewArray<uc16>(len);
+ uc16* buf = ZONE->NewArray<uc16>(len);
for (int j = 0; j < len; j++) {
buf[j] = gen() % 65536;
}
@@ -365,7 +365,7 @@
// Generate short ascii and non-ascii external strings.
for (int i = 0; i <= kMaxLength; i++) {
- char* ascii = Zone::NewArray<char>(i + 1);
+ char* ascii = ZONE->NewArray<char>(i + 1);
for (int j = 0; j < i; j++) {
ascii[j] = 'a';
}
@@ -377,7 +377,7 @@
v8::String::NewExternal(ascii_resource);
ascii_external_strings->Set(v8::Integer::New(i),
ascii_external_string);
- uc16* non_ascii = Zone::NewArray<uc16>(i + 1);
+ uc16* non_ascii = ZONE->NewArray<uc16>(i + 1);
for (int j = 0; j < i; j++) {
non_ascii[j] = 0x1234;
}
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev