Added checking in the regular expression parser that we're below the

stack limit and that the zone allocation limit hasn't been met.


git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@879 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent b07b40b3
This diff is collapsed.
......@@ -603,6 +603,10 @@ bool Top::MayIndexedAccess(JSObject* receiver,
}
const char* Top::kStackOverflowMessage =
"Uncaught RangeError: Maximum call stack size exceeded";
Failure* Top::StackOverflow() {
HandleScope scope;
Handle<String> key = Factory::stack_overflow_symbol();
......@@ -616,9 +620,7 @@ Failure* Top::StackOverflow() {
// doesn't use ReportUncaughtException to determine the location
// from where the exception occurred. It should probably be
// reworked.
static const char* kMessage =
"Uncaught RangeError: Maximum call stack size exceeded";
DoThrow(*exception, NULL, kMessage);
DoThrow(*exception, NULL, kStackOverflowMessage);
return Failure::Exception();
}
......
......@@ -271,6 +271,8 @@ class Top {
static char* ArchiveThread(char* to);
static char* RestoreThread(char* from);
static const char* kStackOverflowMessage;
private:
// The context that initiated this JS execution.
static ThreadLocalTop thread_local_;
......
......@@ -48,6 +48,11 @@ inline void* Zone::New(int size) {
}
bool Zone::excess_allocation() {
return segment_bytes_allocated_ > zone_excess_limit_;
}
} } // namespace v8::internal
#endif // V8_ZONE_INL_H_
......@@ -34,6 +34,8 @@ namespace v8 { 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;
......@@ -63,6 +65,7 @@ class Segment {
// of the segment chain. Returns the new segment.
static Segment* New(int size) {
Segment* result = reinterpret_cast<Segment*>(Malloced::New(size));
Zone::segment_bytes_allocated_ += size;
if (result != NULL) {
result->next_ = head_;
result->size_ = size;
......@@ -72,10 +75,13 @@ class Segment {
}
// Deletes the given segment. Does not touch the segment chain.
static void Delete(Segment* segment) {
static void Delete(Segment* segment, int size) {
Zone::segment_bytes_allocated_ -= size;
Malloced::Delete(segment);
}
static int bytes_allocated() { return bytes_allocated_; }
private:
// Computes the address of the nth byte in this segment.
Address address(int n) const {
......@@ -83,12 +89,14 @@ class Segment {
}
static Segment* head_;
static int bytes_allocated_;
Segment* next_;
int size_;
};
Segment* Segment::head_ = NULL;
int Segment::bytes_allocated_ = 0;
void Zone::DeleteAll() {
......@@ -112,11 +120,12 @@ void Zone::DeleteAll() {
// Unlink the segment we wish to keep from the list.
current->clear_next();
} else {
int size = current->size();
#ifdef DEBUG
// Zap the entire current segment (including the header).
memset(current, kZapDeadByte, current->size());
memset(current, kZapDeadByte, size);
#endif
Segment::Delete(current);
Segment::Delete(current, size);
}
current = next;
}
......
......@@ -61,7 +61,13 @@ class Zone {
// Delete all objects and free all memory allocated in the Zone.
static void DeleteAll();
// Returns true if more memory has been allocated in zones than
// the limit allows.
static inline bool excess_allocation();
private:
friend class Segment;
// All pointers returned from New() have this alignment.
static const int kAlignment = kPointerSize;
......@@ -71,6 +77,13 @@ class Zone {
// Never keep segments larger than this size in bytes around.
static const int kMaximumKeptSegmentSize = 64 * KB;
// Report zone excess when allocation exceeds this limit.
static 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.
......
......@@ -51,6 +51,7 @@ using namespace v8::internal;
static SmartPointer<const char> Parse(const char* input) {
V8::Initialize(NULL);
v8::HandleScope scope;
ZoneScope zone_scope(DELETE_ON_EXIT);
FlatStringReader reader(CStrVector(input));
......@@ -63,6 +64,7 @@ static SmartPointer<const char> Parse(const char* input) {
}
static bool ParseEscapes(const char* input) {
V8::Initialize(NULL);
v8::HandleScope scope;
unibrow::Utf8InputBuffer<> buffer(input, strlen(input));
ZoneScope zone_scope(DELETE_ON_EXIT);
......@@ -253,6 +255,7 @@ TEST(ParserRegression) {
static void ExpectError(const char* input,
const char* expected) {
V8::Initialize(NULL);
v8::HandleScope scope;
ZoneScope zone_scope(DELETE_ON_EXIT);
FlatStringReader reader(CStrVector(input));
......@@ -372,6 +375,7 @@ TEST(CharacterClassEscapes) {
static RegExpNode* Compile(const char* input, bool multiline) {
V8::Initialize(NULL);
FlatStringReader reader(CStrVector(input));
RegExpParseResult result;
if (!v8::internal::ParseRegExp(&reader, multiline, &result))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment