// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include "v8.h"
-#include "isolate.h"
-#include "allocation.h"
-
-/* TODO(isolates): this is what's included in bleeding_edge
- including of v8.h was replaced with these in
- http://codereview.chromium.org/5005001/
- we need Isolate and Isolate needs a lot more so I'm including v8.h back.
#include "../include/v8stdint.h"
#include "globals.h"
#include "checks.h"
#include "allocation.h"
#include "utils.h"
-*/
namespace v8 {
namespace internal {
-#ifdef DEBUG
-
-NativeAllocationChecker::NativeAllocationChecker(
- NativeAllocationChecker::NativeAllocationAllowed allowed)
- : allowed_(allowed) {
- if (allowed == DISALLOW) {
- Isolate* isolate = Isolate::Current();
- isolate->set_allocation_disallowed(isolate->allocation_disallowed() + 1);
- }
-}
-
-
-NativeAllocationChecker::~NativeAllocationChecker() {
- Isolate* isolate = Isolate::Current();
- if (allowed_ == DISALLOW) {
- isolate->set_allocation_disallowed(isolate->allocation_disallowed() - 1);
- }
- ASSERT(isolate->allocation_disallowed() >= 0);
-}
-
-
-bool NativeAllocationChecker::allocation_allowed() {
- // TODO(isolates): either find a way to make this work that doesn't
- // require initializing an isolate before we can use malloc or drop
- // it completely.
- return true;
- // return Isolate::Current()->allocation_disallowed() == 0;
-}
-
-#endif // DEBUG
-
-
void* Malloced::New(size_t size) {
- ASSERT(NativeAllocationChecker::allocation_allowed());
void* result = malloc(size);
if (result == NULL) {
v8::internal::FatalProcessOutOfMemory("Malloced operator new");
}
-void Isolate::PreallocatedStorageInit(size_t size) {
- ASSERT(free_list_.next_ == &free_list_);
- ASSERT(free_list_.previous_ == &free_list_);
- PreallocatedStorage* free_chunk =
- reinterpret_cast<PreallocatedStorage*>(new char[size]);
- free_list_.next_ = free_list_.previous_ = free_chunk;
- free_chunk->next_ = free_chunk->previous_ = &free_list_;
- free_chunk->size_ = size - sizeof(PreallocatedStorage);
- preallocated_storage_preallocated_ = true;
-}
-
-
-void* Isolate::PreallocatedStorageNew(size_t size) {
- if (!preallocated_storage_preallocated_) {
- return FreeStoreAllocationPolicy::New(size);
- }
- ASSERT(free_list_.next_ != &free_list_);
- ASSERT(free_list_.previous_ != &free_list_);
-
- size = (size + kPointerSize - 1) & ~(kPointerSize - 1);
- // Search for exact fit.
- for (PreallocatedStorage* storage = free_list_.next_;
- storage != &free_list_;
- storage = storage->next_) {
- if (storage->size_ == size) {
- storage->Unlink();
- storage->LinkTo(&in_use_list_);
- return reinterpret_cast<void*>(storage + 1);
- }
- }
- // Search for first fit.
- for (PreallocatedStorage* storage = free_list_.next_;
- storage != &free_list_;
- storage = storage->next_) {
- if (storage->size_ >= size + sizeof(PreallocatedStorage)) {
- storage->Unlink();
- storage->LinkTo(&in_use_list_);
- PreallocatedStorage* left_over =
- reinterpret_cast<PreallocatedStorage*>(
- reinterpret_cast<char*>(storage + 1) + size);
- left_over->size_ = storage->size_ - size - sizeof(PreallocatedStorage);
- ASSERT(size + left_over->size_ + sizeof(PreallocatedStorage) ==
- storage->size_);
- storage->size_ = size;
- left_over->LinkTo(&free_list_);
- return reinterpret_cast<void*>(storage + 1);
- }
- }
- // Allocation failure.
- ASSERT(false);
- return NULL;
-}
-
-
-// We don't attempt to coalesce.
-void Isolate::PreallocatedStorageDelete(void* p) {
- if (p == NULL) {
- return;
- }
- if (!preallocated_storage_preallocated_) {
- FreeStoreAllocationPolicy::Delete(p);
- return;
- }
- PreallocatedStorage* storage = reinterpret_cast<PreallocatedStorage*>(p) - 1;
- ASSERT(storage->next_->previous_ == storage);
- ASSERT(storage->previous_->next_ == storage);
- storage->Unlink();
- storage->LinkTo(&free_list_);
-}
-
-
void PreallocatedStorage::LinkTo(PreallocatedStorage* other) {
next_ = other->next_;
other->next_->previous_ = this;
// processing.
void FatalProcessOutOfMemory(const char* message);
-// A class that controls whether allocation is allowed. This is for
-// the C++ heap only!
-class NativeAllocationChecker {
- public:
- enum NativeAllocationAllowed { ALLOW, DISALLOW };
-#ifdef DEBUG
- explicit NativeAllocationChecker(NativeAllocationAllowed allowed);
- ~NativeAllocationChecker();
- static bool allocation_allowed();
- private:
- // This flag applies to this particular instance.
- NativeAllocationAllowed allowed_;
-#else
- explicit inline NativeAllocationChecker(NativeAllocationAllowed allowed) {}
- static inline bool allocation_allowed() { return true; }
-#endif
-};
-
-
// Superclass for classes managed with new & delete.
class Malloced {
public:
template <typename T>
static T* NewArray(int size) {
- ASSERT(NativeAllocationChecker::allocation_allowed());
T* result = new T[size];
if (result == NULL) Malloced::FatalProcessOutOfMemory();
return result;
}
+void Isolate::PreallocatedStorageInit(size_t size) {
+ ASSERT(free_list_.next_ == &free_list_);
+ ASSERT(free_list_.previous_ == &free_list_);
+ PreallocatedStorage* free_chunk =
+ reinterpret_cast<PreallocatedStorage*>(new char[size]);
+ free_list_.next_ = free_list_.previous_ = free_chunk;
+ free_chunk->next_ = free_chunk->previous_ = &free_list_;
+ free_chunk->size_ = size - sizeof(PreallocatedStorage);
+ preallocated_storage_preallocated_ = true;
+}
+
+
+void* Isolate::PreallocatedStorageNew(size_t size) {
+ if (!preallocated_storage_preallocated_) {
+ return FreeStoreAllocationPolicy::New(size);
+ }
+ ASSERT(free_list_.next_ != &free_list_);
+ ASSERT(free_list_.previous_ != &free_list_);
+
+ size = (size + kPointerSize - 1) & ~(kPointerSize - 1);
+ // Search for exact fit.
+ for (PreallocatedStorage* storage = free_list_.next_;
+ storage != &free_list_;
+ storage = storage->next_) {
+ if (storage->size_ == size) {
+ storage->Unlink();
+ storage->LinkTo(&in_use_list_);
+ return reinterpret_cast<void*>(storage + 1);
+ }
+ }
+ // Search for first fit.
+ for (PreallocatedStorage* storage = free_list_.next_;
+ storage != &free_list_;
+ storage = storage->next_) {
+ if (storage->size_ >= size + sizeof(PreallocatedStorage)) {
+ storage->Unlink();
+ storage->LinkTo(&in_use_list_);
+ PreallocatedStorage* left_over =
+ reinterpret_cast<PreallocatedStorage*>(
+ reinterpret_cast<char*>(storage + 1) + size);
+ left_over->size_ = storage->size_ - size - sizeof(PreallocatedStorage);
+ ASSERT(size + left_over->size_ + sizeof(PreallocatedStorage) ==
+ storage->size_);
+ storage->size_ = size;
+ left_over->LinkTo(&free_list_);
+ return reinterpret_cast<void*>(storage + 1);
+ }
+ }
+ // Allocation failure.
+ ASSERT(false);
+ return NULL;
+}
+
+
+// We don't attempt to coalesce.
+void Isolate::PreallocatedStorageDelete(void* p) {
+ if (p == NULL) {
+ return;
+ }
+ if (!preallocated_storage_preallocated_) {
+ FreeStoreAllocationPolicy::Delete(p);
+ return;
+ }
+ PreallocatedStorage* storage = reinterpret_cast<PreallocatedStorage*>(p) - 1;
+ ASSERT(storage->next_->previous_ == storage);
+ ASSERT(storage->previous_->next_ == storage);
+ storage->Unlink();
+ storage->LinkTo(&free_list_);
+}
+
+
Isolate* Isolate::default_isolate_ = NULL;
Thread::LocalStorageKey Isolate::isolate_key_;
Thread::LocalStorageKey Isolate::thread_id_key_;
/* Assembler state. */ \
/* A previously allocated buffer of kMinimalBufferSize bytes, or NULL. */ \
V(byte*, assembler_spare_buffer, NULL) \
- /*This static counter ensures that NativeAllocationCheckers can be nested.*/ \
- V(int, allocation_disallowed, 0) \
V(FatalErrorCallback, exception_behavior, NULL) \
V(v8::Debug::MessageHandler, message_handler, NULL) \
/* To distinguish the function templates, so that we can find them in the */ \
int offset,
int length,
int* length_return) {
- ASSERT(NativeAllocationChecker::allocation_allowed());
if (robust_flag == ROBUST_STRING_TRAVERSAL && !LooksValid()) {
return SmartPointer<char>(NULL);
}
SmartPointer<uc16> String::ToWideCString(RobustnessFlag robust_flag) {
- ASSERT(NativeAllocationChecker::allocation_allowed());
if (robust_flag == ROBUST_STRING_TRAVERSAL && !LooksValid()) {
return SmartPointer<uc16>();
}
: isolate_(script->GetIsolate()),
symbol_cache_(pre_data ? pre_data->symbol_count() : 0),
script_(script),
- scanner_(isolate_),
+ scanner_(isolate_->scanner_constants()),
top_scope_(NULL),
with_nesting_level_(0),
lexical_scope_(NULL),
bool allow_lazy,
ParserRecorder* recorder) {
Isolate* isolate = Isolate::Current();
- V8JavaScriptScanner scanner(isolate);
+ V8JavaScriptScanner scanner(isolate->scanner_constants());
scanner.Initialize(source);
intptr_t stack_limit = isolate->stack_guard()->real_climit();
if (!preparser::PreParser::PreParseProgram(&scanner,
}
private:
- JsonParser() : isolate_(Isolate::Current()), scanner_(isolate_) { }
+ JsonParser()
+ : isolate_(Isolate::Current()),
+ scanner_(isolate_->scanner_constants()) { }
~JsonParser() { }
Isolate* isolate() { return isolate_; }
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include "v8.h"
-
-/*
-TODO(isolates): I incldue v8.h instead of these because we need Isolate and
-some classes (NativeAllocationChecker) are moved into isolate.h
#include "../include/v8stdint.h"
#include "globals.h"
#include "checks.h"
#include "allocation.h"
-#include "allocation-inl.h"
#include "utils.h"
#include "list-inl.h"
-#include "hashmap.h"
-*/
+#include "hashmap.h"
#include "preparse-data.h"
#include "../include/v8-preparser.h"
-#include "v8.h"
-
#include "globals.h"
#include "checks.h"
#include "allocation.h"
class StandAloneJavaScriptScanner : public JavaScriptScanner {
public:
- StandAloneJavaScriptScanner()
- : JavaScriptScanner(Isolate::Current()) { }
+ explicit StandAloneJavaScriptScanner(ScannerConstants* scanner_constants)
+ : JavaScriptScanner(scanner_constants) { }
void Initialize(UC16CharacterStream* source) {
source_ = source;
};
-// Functions declared by allocation.h
+// Functions declared by allocation.h and implemented in both api.cc (for v8)
+// or here (for a stand-alone preparser).
void FatalProcessOutOfMemory(const char* reason) {
V8_Fatal(__FILE__, __LINE__, reason);
PreParserData Preparse(UnicodeInputStream* input, size_t max_stack) {
internal::InputStreamUTF16Buffer buffer(input);
uintptr_t stack_limit = reinterpret_cast<uintptr_t>(&buffer) - max_stack;
- internal::StandAloneJavaScriptScanner scanner;
+ ScannerConstants scanner_constants;
+ internal::StandAloneJavaScriptScanner scanner(&scanner_constants);
scanner.Initialize(&buffer);
internal::CompleteParserRecorder recorder;
preparser::PreParser::PreParseResult result =
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include "v8.h"
-
-/*
-TODO(isolates): I incldue v8.h instead of these because we need Isolate and
-some classes (NativeAllocationChecker) are moved into isolate.h
#include "../include/v8stdint.h"
#include "unicode.h"
#include "globals.h"
#include "allocation.h"
#include "utils.h"
#include "list.h"
-*/
#include "scanner-base.h"
#include "preparse-data.h"
// Features shared by parsing and pre-parsing scanners.
-#include "v8.h"
-
-/*
-TODO(isolates): I incldue v8.h instead of these because we need Isolate and
-some classes (NativeAllocationChecker) are moved into isolate.h
#include "../include/v8stdint.h"
-*/
#include "scanner-base.h"
#include "char-predicates-inl.h"
// ----------------------------------------------------------------------------
// Scanner
-Scanner::Scanner(Isolate* isolate)
- : scanner_constants_(isolate->scanner_constants()),
+Scanner::Scanner(ScannerConstants* scanner_constants)
+ : scanner_constants_(scanner_constants),
octal_pos_(kNoOctalLocation) {
}
// ----------------------------------------------------------------------------
// JavaScriptScanner
-JavaScriptScanner::JavaScriptScanner(Isolate* isolate) : Scanner(isolate) {}
+JavaScriptScanner::JavaScriptScanner(ScannerConstants* scanner_contants)
+ : Scanner(scanner_contants) { }
Token::Value JavaScriptScanner::Next() {
// ---------------------------------------------------------------------
// Constants used by scanners.
public:
+ ScannerConstants() {}
typedef unibrow::Utf8InputBuffer<1024> Utf8Decoder;
StaticResource<Utf8Decoder>* utf8_decoder() {
bool IsIdentifier(unibrow::CharacterStream* buffer);
private:
- ScannerConstants() {}
unibrow::Predicate<IdentifierStart, 128> kIsIdentifierStart;
unibrow::Predicate<IdentifierPart, 128> kIsIdentifierPart;
unibrow::Predicate<unibrow::WhiteSpace, 128> kIsWhiteSpace;
StaticResource<Utf8Decoder> utf8_decoder_;
- friend class Isolate;
DISALLOW_COPY_AND_ASSIGN(ScannerConstants);
};
bool complete_;
};
- explicit Scanner(Isolate* isolate);
+ explicit Scanner(ScannerConstants* scanner_contants);
// Returns the current token again.
Token::Value current_token() { return current_.token; }
bool complete_;
};
- explicit JavaScriptScanner(Isolate* isolate);
+ explicit JavaScriptScanner(ScannerConstants* scanner_contants);
// Returns the next token.
Token::Value Next();
// ----------------------------------------------------------------------------
// JsonScanner
-JsonScanner::JsonScanner(Isolate* isolate) : Scanner(isolate) { }
+JsonScanner::JsonScanner(ScannerConstants* scanner_constants)
+ : Scanner(scanner_constants) { }
void JsonScanner::Initialize(UC16CharacterStream* source) {
class V8JavaScriptScanner : public JavaScriptScanner {
public:
- explicit V8JavaScriptScanner(Isolate* isolate)
- : JavaScriptScanner(isolate) {}
+ explicit V8JavaScriptScanner(ScannerConstants* scanner_constants)
+ : JavaScriptScanner(scanner_constants) {}
void Initialize(UC16CharacterStream* source);
};
class JsonScanner : public Scanner {
public:
- explicit JsonScanner(Isolate* isolate);
+ explicit JsonScanner(ScannerConstants* scanner_constants);
void Initialize(UC16CharacterStream* source);
allocator = preallocated_message_space_;
}
- NativeAllocationChecker allocation_checker(
- !FLAG_preallocate_message_memory ?
- NativeAllocationChecker::ALLOW :
- NativeAllocationChecker::DISALLOW);
-
StringStream::ClearMentionedObjectCache();
StringStream accumulator(allocator);
incomplete_message_ = &accumulator;
reinterpret_cast<const i::byte*>(program),
static_cast<unsigned>(strlen(program)));
i::CompleteParserRecorder log;
- i::V8JavaScriptScanner scanner(ISOLATE);
+ i::V8JavaScriptScanner scanner(ISOLATE->scanner_constants());
scanner.Initialize(&stream);
v8::preparser::PreParser::PreParseResult result =
reinterpret_cast<const i::byte*>(*program),
static_cast<unsigned>(kProgramSize));
i::CompleteParserRecorder log;
- i::V8JavaScriptScanner scanner(ISOLATE);
+ i::V8JavaScriptScanner scanner(ISOLATE->scanner_constants());
scanner.Initialize(&stream);
i::Token::Value* expected_tokens,
int skip_pos = 0, // Zero means not skipping.
int skip_to = 0) {
- i::V8JavaScriptScanner scanner(ISOLATE);
+ i::V8JavaScriptScanner scanner(ISOLATE->scanner_constants());
scanner.Initialize(stream);
int i = 0;
i::Utf8ToUC16CharacterStream stream(
reinterpret_cast<const i::byte*>(re_source),
static_cast<unsigned>(strlen(re_source)));
- i::V8JavaScriptScanner scanner(ISOLATE);
+ i::V8JavaScriptScanner scanner(ISOLATE->scanner_constants());
scanner.Initialize(&stream);
i::Token::Value start = scanner.peek();