Commit 21155c15 authored by rmcilroy@chromium.org's avatar rmcilroy@chromium.org

Ensure that we don't mark weak heap references in the constant pool array.

Some heap pointer's embedded in optimized code are considered weak. Ensure
that we don't mark them during GC of the ConstantPoolArray.  Also, embed
length metadata in a bitfield, reducing the ConstantPoolArray header size from
five words to two.

R=ulan@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20573 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ed9f1af2
......@@ -5296,8 +5296,14 @@ MaybeObject* Heap::AllocateConstantPoolArray(int number_of_int64_entries,
int number_of_code_ptr_entries,
int number_of_heap_ptr_entries,
int number_of_int32_entries) {
ASSERT(number_of_int64_entries > 0 || number_of_code_ptr_entries > 0 ||
number_of_heap_ptr_entries > 0 || number_of_int32_entries > 0);
CHECK(number_of_int64_entries >= 0 &&
number_of_int64_entries <= ConstantPoolArray::kMaxEntriesPerType &&
number_of_code_ptr_entries >= 0 &&
number_of_code_ptr_entries <= ConstantPoolArray::kMaxEntriesPerType &&
number_of_heap_ptr_entries >= 0 &&
number_of_heap_ptr_entries <= ConstantPoolArray::kMaxEntriesPerType &&
number_of_int32_entries >= 0 &&
number_of_int32_entries <= ConstantPoolArray::kMaxEntriesPerType);
int size = ConstantPoolArray::SizeFor(number_of_int64_entries,
number_of_code_ptr_entries,
number_of_heap_ptr_entries,
......@@ -5316,10 +5322,10 @@ MaybeObject* Heap::AllocateConstantPoolArray(int number_of_int64_entries,
ConstantPoolArray* constant_pool =
reinterpret_cast<ConstantPoolArray*>(object);
constant_pool->SetEntryCounts(number_of_int64_entries,
number_of_code_ptr_entries,
number_of_heap_ptr_entries,
number_of_int32_entries);
constant_pool->Init(number_of_int64_entries,
number_of_code_ptr_entries,
number_of_heap_ptr_entries,
number_of_int32_entries);
if (number_of_code_ptr_entries > 0) {
int offset =
constant_pool->OffsetOfElementAt(constant_pool->first_code_ptr_index());
......@@ -5348,7 +5354,7 @@ MaybeObject* Heap::AllocateEmptyConstantPoolArray() {
if (!maybe_result->ToObject(&result)) return maybe_result;
}
HeapObject::cast(result)->set_map_no_write_barrier(constant_pool_array_map());
ConstantPoolArray::cast(result)->SetEntryCounts(0, 0, 0, 0);
ConstantPoolArray::cast(result)->Init(0, 0, 0, 0);
return result;
}
......
......@@ -200,6 +200,10 @@ void LCodeGenBase::RegisterWeakObjectsInOptimizedCode(Handle<Code> code) {
}
}
}
if (FLAG_enable_ool_constant_pool) {
code->constant_pool()->set_weak_object_state(
ConstantPoolArray::WEAK_OBJECTS_IN_OPTIMIZED_CODE);
}
#ifdef VERIFY_HEAP
// This disables verification of weak embedded objects after full GC.
// AddDependentCode can cause a GC, which would observe the state where
......
......@@ -2284,12 +2284,18 @@ void FixedDoubleArray::FillWithHoles(int from, int to) {
}
SMI_ACCESSORS(
ConstantPoolArray, first_code_ptr_index, kFirstCodePointerIndexOffset)
SMI_ACCESSORS(
ConstantPoolArray, first_heap_ptr_index, kFirstHeapPointerIndexOffset)
SMI_ACCESSORS(
ConstantPoolArray, first_int32_index, kFirstInt32IndexOffset)
void ConstantPoolArray::set_weak_object_state(
ConstantPoolArray::WeakObjectState state) {
int old_layout_field = READ_INT_FIELD(this, kArrayLayoutOffset);
int new_layout_field = WeakObjectStateField::update(old_layout_field, state);
WRITE_INT_FIELD(this, kArrayLayoutOffset, new_layout_field);
}
ConstantPoolArray::WeakObjectState ConstantPoolArray::get_weak_object_state() {
int layout_field = READ_INT_FIELD(this, kArrayLayoutOffset);
return WeakObjectStateField::decode(layout_field);
}
int ConstantPoolArray::first_int64_index() {
......@@ -2297,6 +2303,27 @@ int ConstantPoolArray::first_int64_index() {
}
int ConstantPoolArray::first_code_ptr_index() {
int layout_field = READ_INT_FIELD(this, kArrayLayoutOffset);
return first_int64_index() +
NumberOfInt64EntriesField::decode(layout_field);
}
int ConstantPoolArray::first_heap_ptr_index() {
int layout_field = READ_INT_FIELD(this, kArrayLayoutOffset);
return first_code_ptr_index() +
NumberOfCodePtrEntriesField::decode(layout_field);
}
int ConstantPoolArray::first_int32_index() {
int layout_field = READ_INT_FIELD(this, kArrayLayoutOffset);
return first_heap_ptr_index() +
NumberOfHeapPtrEntriesField::decode(layout_field);
}
int ConstantPoolArray::count_of_int64_entries() {
return first_code_ptr_index();
}
......@@ -2317,18 +2344,20 @@ int ConstantPoolArray::count_of_int32_entries() {
}
void ConstantPoolArray::SetEntryCounts(int number_of_int64_entries,
int number_of_code_ptr_entries,
int number_of_heap_ptr_entries,
int number_of_int32_entries) {
int current_index = number_of_int64_entries;
set_first_code_ptr_index(current_index);
current_index += number_of_code_ptr_entries;
set_first_heap_ptr_index(current_index);
current_index += number_of_heap_ptr_entries;
set_first_int32_index(current_index);
current_index += number_of_int32_entries;
set_length(current_index);
void ConstantPoolArray::Init(int number_of_int64_entries,
int number_of_code_ptr_entries,
int number_of_heap_ptr_entries,
int number_of_int32_entries) {
set_length(number_of_int64_entries +
number_of_code_ptr_entries +
number_of_heap_ptr_entries +
number_of_int32_entries);
int layout_field =
NumberOfInt64EntriesField::encode(number_of_int64_entries) |
NumberOfCodePtrEntriesField::encode(number_of_code_ptr_entries) |
NumberOfHeapPtrEntriesField::encode(number_of_heap_ptr_entries) |
WeakObjectStateField::encode(NO_WEAK_OBJECTS);
WRITE_INT_FIELD(this, kArrayLayoutOffset, layout_field);
}
......@@ -4741,7 +4770,6 @@ Object* Code::GetObjectFromEntryAddress(Address location_of_address) {
bool Code::IsWeakObjectInOptimizedCode(Object* object) {
ASSERT(is_optimized_code());
if (object->IsMap()) {
return Map::cast(object)->CanTransition() &&
FLAG_collect_maps &&
......
......@@ -498,8 +498,14 @@ void StaticMarkingVisitor<StaticVisitor>::VisitConstantPoolArray(
}
for (int i = 0; i < constant_pool->count_of_heap_ptr_entries(); i++) {
int index = constant_pool->first_heap_ptr_index() + i;
StaticVisitor::VisitPointer(heap,
constant_pool->RawFieldOfElementAt(index));
Object** slot = constant_pool->RawFieldOfElementAt(index);
HeapObject* object = HeapObject::cast(*slot);
heap->mark_compact_collector()->RecordSlot(slot, slot, object);
if (!(constant_pool->get_weak_object_state() ==
ConstantPoolArray::WEAK_OBJECTS_IN_OPTIMIZED_CODE &&
Code::IsWeakObjectInOptimizedCode(object))) {
StaticVisitor::MarkObject(heap, object);
}
}
}
......
......@@ -3218,6 +3218,11 @@ class FixedDoubleArray: public FixedArrayBase {
// [first_int32_index()] ... [length - 1] : 32 bit entries
class ConstantPoolArray: public FixedArrayBase {
public:
enum WeakObjectState {
NO_WEAK_OBJECTS,
WEAK_OBJECTS_IN_OPTIMIZED_CODE
};
// Getters for the field storing the first index for different type entries.
inline int first_code_ptr_index();
inline int first_heap_ptr_index();
......@@ -3237,6 +3242,10 @@ class ConstantPoolArray: public FixedArrayBase {
inline int32_t get_int32_entry(int index);
inline double get_int64_entry_as_double(int index);
// Setter and getter for weak objects state
inline void set_weak_object_state(WeakObjectState state);
inline WeakObjectState get_weak_object_state();
inline void set(int index, Address value);
inline void set(int index, Object* value);
inline void set(int index, int64_t value);
......@@ -3244,10 +3253,10 @@ class ConstantPoolArray: public FixedArrayBase {
inline void set(int index, int32_t value);
// Set up initial state.
inline void SetEntryCounts(int number_of_int64_entries,
int number_of_code_ptr_entries,
int number_of_heap_ptr_entries,
int number_of_int32_entries);
inline void Init(int number_of_int64_entries,
int number_of_code_ptr_entries,
int number_of_heap_ptr_entries,
int number_of_int32_entries);
// Copy operations
MUST_USE_RESULT inline MaybeObject* Copy();
......@@ -3290,12 +3299,16 @@ class ConstantPoolArray: public FixedArrayBase {
}
// Layout description.
static const int kFirstCodePointerIndexOffset = FixedArray::kHeaderSize;
static const int kFirstHeapPointerIndexOffset =
kFirstCodePointerIndexOffset + kPointerSize;
static const int kFirstInt32IndexOffset =
kFirstHeapPointerIndexOffset + kPointerSize;
static const int kFirstOffset = kFirstInt32IndexOffset + kPointerSize;
static const int kArrayLayoutOffset = FixedArray::kHeaderSize;
static const int kFirstOffset = kArrayLayoutOffset + kPointerSize;
static const int kFieldBitSize = 10;
static const int kMaxEntriesPerType = (1 << kFieldBitSize) - 1;
class NumberOfInt64EntriesField: public BitField<int, 0, kFieldBitSize> {};
class NumberOfCodePtrEntriesField: public BitField<int, 10, kFieldBitSize> {};
class NumberOfHeapPtrEntriesField: public BitField<int, 20, kFieldBitSize> {};
class WeakObjectStateField: public BitField<WeakObjectState, 30, 2> {};
// Dispatched behavior.
void ConstantPoolIterateBody(ObjectVisitor* v);
......@@ -3304,10 +3317,6 @@ class ConstantPoolArray: public FixedArrayBase {
DECLARE_VERIFIER(ConstantPoolArray)
private:
inline void set_first_code_ptr_index(int value);
inline void set_first_heap_ptr_index(int value);
inline void set_first_int32_index(int value);
inline static int OffsetAt(int number_of_int64_entries,
int number_of_code_ptr_entries,
int number_of_heap_ptr_entries,
......@@ -5746,7 +5755,7 @@ class Code: public HeapObject {
return is_optimized_code() && IsWeakObjectInOptimizedCode(object);
}
inline bool IsWeakObjectInOptimizedCode(Object* object);
static inline bool IsWeakObjectInOptimizedCode(Object* object);
// Max loop nesting marker used to postpose OSR. We don't take loop
// nesting that is deeper than 5 levels into account.
......
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