continue;
}
if (r->IsLarge()) {
- mirror::Object* obj = reinterpret_cast<mirror::Object*>(r->Begin());
- if (obj->GetClass() != nullptr) {
+ if (r->LiveBytes() > 0) {
+ // Avoid visiting dead large objects since they may contain dangling pointers to the
+ // from-space.
+ DCHECK_GT(r->LiveBytes(), 0u) << "Visiting dead large object";
+ mirror::Object* obj = reinterpret_cast<mirror::Object*>(r->Begin());
+ DCHECK(obj->GetClass() != nullptr);
callback(obj, arg);
}
} else if (r->IsLargeTail()) {
--- /dev/null
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class Main {
+ static volatile Object a[] = null;
+
+ public static void main(String[] args) {
+ for (int i = 0; i < 10; ++i) {
+ a = new Object[i * 300000];
+ Runtime.getRuntime().gc();
+ }
+ }
+}