Commit af7b6fec authored by lrn@chromium.org's avatar lrn@chromium.org

Split globals.h into two parts, where only one depends on V8.

Made allocation.{h,cc} independent of V8, allowing utils.h to allocate
vectors and collectors.

Review URL: http://codereview.chromium.org/5005001

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5826 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 2a8eb355
......@@ -3282,8 +3282,8 @@ class V8EXPORT OutputStream { // NOLINT
namespace internal {
const int kPointerSize = sizeof(void*); // NOLINT
const int kIntSize = sizeof(int); // NOLINT
static const int kApiPointerSize = sizeof(void*); // NOLINT
static const int kApiIntSize = sizeof(int); // NOLINT
// Tag information for HeapObject.
const int kHeapObjectTag = 1;
......@@ -3319,19 +3319,19 @@ template <> struct SmiConstants<8> {
}
};
const int kSmiShiftSize = SmiConstants<kPointerSize>::kSmiShiftSize;
const int kSmiValueSize = SmiConstants<kPointerSize>::kSmiValueSize;
const int kSmiShiftSize = SmiConstants<kApiPointerSize>::kSmiShiftSize;
const int kSmiValueSize = SmiConstants<kApiPointerSize>::kSmiValueSize;
template <size_t ptr_size> struct InternalConstants;
// Internal constants for 32-bit systems.
template <> struct InternalConstants<4> {
static const int kStringResourceOffset = 3 * kPointerSize;
static const int kStringResourceOffset = 3 * kApiPointerSize;
};
// Internal constants for 64-bit systems.
template <> struct InternalConstants<8> {
static const int kStringResourceOffset = 3 * kPointerSize;
static const int kStringResourceOffset = 3 * kApiPointerSize;
};
/**
......@@ -3345,12 +3345,12 @@ class Internals {
// These values match non-compiler-dependent values defined within
// the implementation of v8.
static const int kHeapObjectMapOffset = 0;
static const int kMapInstanceTypeOffset = kPointerSize + kIntSize;
static const int kMapInstanceTypeOffset = kApiPointerSize + kApiIntSize;
static const int kStringResourceOffset =
InternalConstants<kPointerSize>::kStringResourceOffset;
InternalConstants<kApiPointerSize>::kStringResourceOffset;
static const int kProxyProxyOffset = kPointerSize;
static const int kJSObjectHeaderSize = 3 * kPointerSize;
static const int kProxyProxyOffset = kApiPointerSize;
static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
static const int kFullStringRepresentationMask = 0x07;
static const int kExternalTwoByteRepresentationTag = 0x02;
......@@ -3368,7 +3368,7 @@ class Internals {
}
static inline int SmiValue(internal::Object* value) {
return SmiConstants<kPointerSize>::SmiToInt(value);
return SmiConstants<kApiPointerSize>::SmiToInt(value);
}
static inline int GetInstanceType(internal::Object* obj) {
......@@ -3559,7 +3559,7 @@ Local<Value> Object::UncheckedGetInternalField(int index) {
// If the object is a plain JSObject, which is the common case,
// we know where to find the internal fields and can return the
// value directly.
int offset = I::kJSObjectHeaderSize + (internal::kPointerSize * index);
int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
O* value = I::ReadField<O*>(obj, offset);
O** result = HandleScope::CreateHandle(value);
return Local<Value>(reinterpret_cast<Value*>(result));
......@@ -3595,7 +3595,7 @@ void* Object::GetPointerFromInternalField(int index) {
// If the object is a plain JSObject, which is the common case,
// we know where to find the internal fields and can return the
// value directly.
int offset = I::kJSObjectHeaderSize + (internal::kPointerSize * index);
int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
O* value = I::ReadField<O*>(obj, offset);
return I::GetExternalPointer(value);
}
......
......@@ -27,16 +27,21 @@
#include <stdlib.h>
#include "v8.h"
#include "../include/v8stdint.h"
#include "globals.h"
#include "checks.h"
#include "allocation.h"
#include "utils.h"
namespace v8 {
namespace internal {
void* Malloced::New(size_t size) {
ASSERT(NativeAllocationChecker::allocation_allowed());
void* result = malloc(size);
if (result == NULL) V8::FatalProcessOutOfMemory("Malloced operator new");
if (result == NULL) {
v8::internal::FatalProcessOutOfMemory("Malloced operator new");
}
return result;
}
......@@ -47,7 +52,7 @@ void Malloced::Delete(void* p) {
void Malloced::FatalProcessOutOfMemory() {
V8::FatalProcessOutOfMemory("Out of memory");
v8::internal::FatalProcessOutOfMemory("Out of memory");
}
......@@ -82,7 +87,7 @@ void AllStatic::operator delete(void* p) {
char* StrDup(const char* str) {
int length = StrLength(str);
char* result = NewArray<char>(length + 1);
memcpy(result, str, length * kCharSize);
memcpy(result, str, length);
result[length] = '\0';
return result;
}
......@@ -92,7 +97,7 @@ char* StrNDup(const char* str, int n) {
int length = StrLength(str);
if (n < length) length = n;
char* result = NewArray<char>(length + 1);
memcpy(result, str, length * kCharSize);
memcpy(result, str, length);
result[length] = '\0';
return result;
}
......@@ -124,6 +129,7 @@ void* PreallocatedStorage::New(size_t 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_;
......
......@@ -31,6 +31,10 @@
namespace v8 {
namespace internal {
// Called when allocation routines fail to allocate.
// This function should not return, but should terminate the current
// processing.
void FatalProcessOutOfMemory(const char* message);
// A class that controls whether allocation is allowed. This is for
// the C++ heap only!
......
......@@ -115,7 +115,6 @@ static void DefaultFatalErrorHandler(const char* location,
}
static FatalErrorCallback& GetFatalErrorHandler() {
if (exception_behavior == NULL) {
exception_behavior = DefaultFatalErrorHandler;
......@@ -124,6 +123,10 @@ static FatalErrorCallback& GetFatalErrorHandler() {
}
void i::FatalProcessOutOfMemory(const char* location) {
i::V8::FatalProcessOutOfMemory(location, false);
}
// When V8 cannot allocated memory FatalProcessOutOfMemory is called.
// The default fatal error handler is called and execution is stopped.
......
......@@ -30,8 +30,6 @@
#include <string.h>
#include "../include/v8stdint.h"
extern "C" void V8_Fatal(const char* file, int line, const char* format, ...);
void API_Fatal(const char* location, const char* format, ...);
......
This diff is collapsed.
......@@ -148,14 +148,6 @@ class List {
DISALLOW_COPY_AND_ASSIGN(List);
};
class FrameElement;
// Add() is inlined, ResizeAdd() called by Add() is inlined except for
// Lists of FrameElements, and ResizeAddInternal() is inlined in ResizeAdd().
template <>
void List<FrameElement,
FreeStoreAllocationPolicy>::ResizeAdd(const FrameElement& element);
} } // namespace v8::internal
#endif // V8_LIST_H_
......@@ -27,6 +27,7 @@
// Features shared by parsing and pre-parsing scanners.
#include "../include/v8stdint.h"
#include "scanner-base.h"
namespace v8 {
......
......@@ -31,7 +31,9 @@
#include <stdlib.h>
#include <string.h>
#include "globals.h"
#include "checks.h"
#include "allocation.h"
namespace v8 {
namespace internal {
......
......@@ -53,7 +53,7 @@
// Basic includes
#include "../include/v8.h"
#include "globals.h"
#include "v8globals.h"
#include "checks.h"
#include "allocation.h"
#include "v8utils.h"
......
This diff is collapsed.
......@@ -31,6 +31,9 @@
#include "frame-element.h"
#include "macro-assembler.h"
#include "list-inl.h"
#include "utils.h"
#if V8_TARGET_ARCH_IA32
#include "ia32/virtual-frame-ia32.h"
#elif V8_TARGET_ARCH_X64
......@@ -43,4 +46,14 @@
#error Unsupported target architecture.
#endif
namespace v8 {
namespace internal {
// Add() on List is inlined, ResizeAdd() called by Add() is inlined except for
// Lists of FrameElements, and ResizeAddInternal() is inlined in ResizeAdd().
template <>
void List<FrameElement,
FreeStoreAllocationPolicy>::ResizeAdd(const FrameElement& element);
} } // namespace v8::internal
#endif // V8_VIRTUAL_FRAME_H_
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