Commit 30e2802e authored by yangguo@chromium.org's avatar yangguo@chromium.org

Hide heap methods where possible.

Factory is already a friend class of Heap.
We introduce a TestHeap class in cctest.h to access protected methods.

R=mstarzinger@chromium.org

Review URL: https://codereview.chromium.org/247263003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@21053 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c8e95c41
......@@ -631,10 +631,9 @@ Handle<Symbol> Factory::NewSymbol() {
Handle<Symbol> Factory::NewPrivateSymbol() {
CALL_HEAP_FUNCTION(
isolate(),
isolate()->heap()->AllocatePrivateSymbol(),
Symbol);
Handle<Symbol> symbol = NewSymbol();
symbol->set_is_private(true);
return symbol;
}
......@@ -1333,9 +1332,9 @@ Handle<JSObject> Factory::NewExternal(void* value) {
}
Handle<Code> NewCodeHelper(Isolate* isolate, int object_size, bool immovable) {
CALL_HEAP_FUNCTION(isolate,
isolate->heap()->AllocateCode(object_size, immovable),
Handle<Code> Factory::NewCodeRaw(int object_size, bool immovable) {
CALL_HEAP_FUNCTION(isolate(),
isolate()->heap()->AllocateCode(object_size, immovable),
Code);
}
......@@ -1354,7 +1353,7 @@ Handle<Code> Factory::NewCode(const CodeDesc& desc,
int body_size = RoundUp(desc.instr_size, kObjectAlignment);
int obj_size = Code::SizeFor(body_size);
Handle<Code> code = NewCodeHelper(isolate(), obj_size, immovable);
Handle<Code> code = NewCodeRaw(obj_size, immovable);
ASSERT(!isolate()->code_range()->exists() ||
isolate()->code_range()->contains(code->address()));
......
......@@ -656,6 +656,9 @@ class Factory V8_FINAL {
AllocationSpace space,
Handle<AllocationSite> allocation_site);
// Creates a code object that is not yet fully initialized yet.
inline Handle<Code> NewCodeRaw(int object_size, bool immovable);
// Initializes a function with a shared part and prototype.
// Note: this code was factored out of NewFunction such that other parts of
// the VM could use it. Specifically, a function that creates instances of
......
......@@ -4336,15 +4336,6 @@ MaybeObject* Heap::AllocateSymbol() {
}
MaybeObject* Heap::AllocatePrivateSymbol() {
MaybeObject* maybe = AllocateSymbol();
Symbol* symbol;
if (!maybe->To(&symbol)) return maybe;
symbol->set_is_private(true);
return symbol;
}
MaybeObject* Heap::AllocateStruct(InstanceType type) {
Map* map;
switch (type) {
......
This diff is collapsed.
......@@ -80,6 +80,19 @@ typedef v8::internal::EnumSet<CcTestExtensionIds> CcTestExtensionFlags;
#undef DEFINE_EXTENSION_FLAG
// Use this to expose protected methods in i::Heap.
class TestHeap : public i::Heap {
public:
using i::Heap::AllocateHeapNumber;
using i::Heap::AllocateMap;
using i::Heap::AllocateJSObject;
using i::Heap::AllocateJSObjectFromMap;
using i::Heap::AllocateByteArray;
using i::Heap::AllocateArgumentsObject;
using i::Heap::CopyCode;
};
class CcTest {
public:
typedef void (TestFunction)();
......@@ -107,6 +120,10 @@ class CcTest {
return i_isolate()->heap();
}
static TestHeap* test_heap() {
return reinterpret_cast<TestHeap*>(i_isolate()->heap());
}
static v8::Local<v8::Object> global() {
return isolate()->GetCurrentContext()->Global();
}
......
......@@ -38,7 +38,7 @@ using namespace v8::internal;
static MaybeObject* AllocateAfterFailures() {
static int attempts = 0;
if (++attempts < 3) return Failure::RetryAfterGC();
Heap* heap = CcTest::heap();
TestHeap* heap = CcTest::test_heap();
// New space.
SimulateFullSpace(heap->new_space());
......
......@@ -595,13 +595,20 @@ static const char* not_so_random_string_table[] = {
static void CheckInternalizedStrings(const char** strings) {
Factory* factory = CcTest::i_isolate()->factory();
Isolate* isolate = CcTest::i_isolate();
Factory* factory = isolate->factory();
for (const char* string = *strings; *strings != 0; string = *strings++) {
Handle<String> a = factory->InternalizeUtf8String(string);
HandleScope scope(isolate);
Handle<String> a =
isolate->factory()->InternalizeUtf8String(CStrVector(string));
// InternalizeUtf8String may return a failure if a GC is needed.
CHECK(a->IsInternalizedString());
Handle<String> b = factory->InternalizeUtf8String(string);
CHECK_EQ(*b, *a);
CHECK(String::cast(*b)->IsUtf8EqualTo(CStrVector(string)));
CHECK(b->IsUtf8EqualTo(CStrVector(string)));
b = isolate->factory()->InternalizeUtf8String(CStrVector(string));
CHECK_EQ(*b, *a);
CHECK(b->IsUtf8EqualTo(CStrVector(string)));
}
}
......@@ -977,7 +984,7 @@ TEST(Regression39128) {
// Test case for crbug.com/39128.
CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate();
Heap* heap = isolate->heap();
TestHeap* heap = CcTest::test_heap();
// Increase the chance of 'bump-the-pointer' allocation in old space.
heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
......
......@@ -128,7 +128,7 @@ TEST(MarkCompactCollector) {
FLAG_incremental_marking = false;
CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate();
Heap* heap = isolate->heap();
TestHeap* heap = CcTest::test_heap();
Factory* factory = isolate->factory();
v8::HandleScope sc(CcTest::isolate());
......
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