Commit 9b77e867 authored by ulan's avatar ulan Committed by Commit bot

Add debug checks to catch crashes with WeakCell::cast().

BUG=

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

Cr-Commit-Position: refs/heads/master@{#27314}
parent f1d970a4
......@@ -2098,6 +2098,7 @@ void MarkCompactCollector::RetainMaps() {
int length = retained_maps->Length();
int new_length = 0;
for (int i = 0; i < length; i += 2) {
DCHECK(retained_maps->Get(i)->IsWeakCell());
WeakCell* cell = WeakCell::cast(retained_maps->Get(i));
if (cell->cleared()) continue;
int age = Smi::cast(retained_maps->Get(i + 1))->value();
......@@ -2348,6 +2349,7 @@ void MarkCompactCollector::ClearNonLiveReferences() {
if (!table->IsKey(key)) continue;
uint32_t value_index = table->EntryToValueIndex(i);
Object* value = table->get(value_index);
DCHECK(key->IsWeakCell());
if (WeakCell::cast(key)->cleared()) {
have_code_to_deoptimize_ |=
DependentCode::cast(value)->MarkCodeForDeoptimization(
......
......@@ -2585,6 +2585,7 @@ void Isolate::CheckDetachedContextsAfterGC() {
int new_length = 0;
for (int i = 0; i < length; i += 2) {
int mark_sweeps = Smi::cast(detached_contexts->get(i))->value();
DCHECK(detached_contexts->get(i + 1)->IsWeakCell());
WeakCell* cell = WeakCell::cast(detached_contexts->get(i + 1));
if (!cell->cleared()) {
detached_contexts->set(new_length, Smi::FromInt(mark_sweeps + 1));
......@@ -2598,6 +2599,7 @@ void Isolate::CheckDetachedContextsAfterGC() {
length - new_length, length);
for (int i = 0; i < new_length; i += 2) {
int mark_sweeps = Smi::cast(detached_contexts->get(i))->value();
DCHECK(detached_contexts->get(i + 1)->IsWeakCell());
WeakCell* cell = WeakCell::cast(detached_contexts->get(i + 1));
if (mark_sweeps > 3) {
PrintF("detached context 0x%p\n survived %d GCs (leak?)\n",
......
......@@ -2349,6 +2349,7 @@ void FixedDoubleArray::FillWithHoles(int from, int to) {
Object* WeakFixedArray::Get(int index) const {
Object* raw = FixedArray::cast(this)->get(index + kFirstIndex);
if (raw->IsSmi()) return raw;
DCHECK(raw->IsWeakCell());
return WeakCell::cast(raw)->value();
}
......
......@@ -10364,6 +10364,7 @@ Handle<Object> Script::GetNameOrSourceURL(Handle<Script> script) {
Handle<JSObject> Script::GetWrapper(Handle<Script> script) {
Isolate* isolate = script->GetIsolate();
if (!script->wrapper()->IsUndefined()) {
DCHECK(script->wrapper()->IsWeakCell());
Handle<WeakCell> cell(WeakCell::cast(script->wrapper()));
if (!cell->cleared()) {
// Return a handle for the existing script wrapper from the cache.
......
......@@ -68,6 +68,7 @@ class TransitionArray: public FixedArray {
}
static inline Map* GetSimpleTransition(Object* raw_transition) {
DCHECK(IsSimpleTransition(raw_transition));
DCHECK(raw_transition->IsWeakCell());
return Map::cast(WeakCell::cast(raw_transition)->value());
}
static inline bool IsFullTransitionArray(Object* raw_transitions) {
......
......@@ -435,6 +435,7 @@ int FeedbackNexus::ExtractMaps(MapHandleList* maps) const {
// [map, handler, map, handler, ... ]
DCHECK(array->length() >= 2);
for (int i = 0; i < array->length(); i += 2) {
DCHECK(array->get(i)->IsWeakCell());
WeakCell* cell = WeakCell::cast(array->get(i));
if (!cell->cleared()) {
Map* map = Map::cast(cell->value());
......@@ -464,6 +465,7 @@ MaybeHandle<Code> FeedbackNexus::FindHandlerForMap(Handle<Map> map) const {
}
FixedArray* array = FixedArray::cast(feedback);
for (int i = 0; i < array->length(); i += 2) {
DCHECK(array->get(i)->IsWeakCell());
WeakCell* cell = WeakCell::cast(array->get(i));
if (!cell->cleared()) {
Map* array_map = Map::cast(cell->value());
......@@ -502,6 +504,7 @@ bool FeedbackNexus::FindHandlers(CodeHandleList* code_list, int length) const {
// Be sure to skip handlers whose maps have been cleared.
DCHECK(array->length() >= 2);
for (int i = 0; i < array->length(); i += 2) {
DCHECK(array->get(i)->IsWeakCell());
WeakCell* cell = WeakCell::cast(array->get(i));
if (!cell->cleared()) {
Code* code = Code::cast(array->get(i + 1));
......
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