Merge "Increase frame size for ASAN enabled builds."
diff --git a/Android.mk b/Android.mk
index cc18660..2647268 100644
--- a/Android.mk
+++ b/Android.mk
@@ -434,12 +434,25 @@
########################################################################
# Phony target for only building what go/lem requires on target.
.PHONY: build-art-target-golem
+# Also include libartbenchmark, we always include it when running golem.
+ART_TARGET_SHARED_LIBRARY_BENCHMARK := $(TARGET_OUT_SHARED_LIBRARIES)/libartbenchmark.so
build-art-target-golem: dex2oat dalvikvm patchoat linker \
$(TARGET_OUT)/etc/public.libraries.txt \
$(ART_TARGET_DEX_DEPENDENCIES) \
$(ART_TARGET_SHARED_LIBRARY_DEPENDENCIES) \
+ $(ART_TARGET_SHARED_LIBRARY_BENCHMARK) \
$(TARGET_CORE_IMG_OUT_BASE).art \
$(TARGET_CORE_IMG_OUT_BASE)-interpreter.art
+ sed -i '/libartd.so/d' $(TARGET_OUT)/etc/public.libraries.txt
+ # remove libartd.so from public.libraries.txt because golem builds won't have it.
+
+########################################################################
+# Phony target for building what go/lem requires on host.
+.PHONY: build-art-host-golem
+# Also include libartbenchmark, we always include it when running golem.
+ART_HOST_SHARED_LIBRARY_BENCHMARK := $(ART_HOST_OUT_SHARED_LIBRARIES)/libartbenchmark.so
+build-art-host-golem: build-art-host \
+ $(ART_HOST_SHARED_LIBRARY_BENCHMARK)
########################################################################
# Rules for building all dependencies for tests.
diff --git a/benchmark/Android.bp b/benchmark/Android.bp
index 617f5b0..dd19888 100644
--- a/benchmark/Android.bp
+++ b/benchmark/Android.bp
@@ -19,13 +19,16 @@
host_supported: true,
defaults: ["art_defaults", "art_debug_defaults"],
srcs: [
+ "jni_loader.cc",
"jobject-benchmark/jobject_benchmark.cc",
"jni-perf/perf_jni.cc",
+ "micro-native/micro_native.cc",
"scoped-primitive-array/scoped_primitive_array.cc",
],
shared_libs: [
"libart",
"libbacktrace",
+ "libbase",
"libnativehelper",
],
clang: true,
diff --git a/benchmark/jni_loader.cc b/benchmark/jni_loader.cc
new file mode 100644
index 0000000..2c9f86e
--- /dev/null
+++ b/benchmark/jni_loader.cc
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#include <jni.h>
+
+extern void register_micro_native_methods(JNIEnv* env);
+
+jint JNI_OnLoad(JavaVM* vm, void* /*reserved*/) {
+ JNIEnv* env;
+ if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
+ return -1;
+ }
+
+ // List of functions to call to register methods explicitly.
+ // Otherwise we use the regular JNI naming conventions to register implicitly.
+ register_micro_native_methods(env);
+
+ return JNI_VERSION_1_6;
+}
diff --git a/benchmark/micro-native/micro_native.cc b/benchmark/micro-native/micro_native.cc
new file mode 100644
index 0000000..43c29e2
--- /dev/null
+++ b/benchmark/micro-native/micro_native.cc
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#define LOG_TAG "NativeMethods"
+
+#define CLASS_NAME "benchmarks/MicroNative/java/NativeMethods"
+
+#include "JNIHelp.h"
+#include "JniConstants.h"
+
+static void NativeMethods_emptyJniStaticSynchronizedMethod0(JNIEnv*, jclass) { }
+static void NativeMethods_emptyJniSynchronizedMethod0(JNIEnv*, jclass) { }
+
+static JNINativeMethod gMethods_NormalOnly[] = {
+ NATIVE_METHOD(NativeMethods, emptyJniStaticSynchronizedMethod0, "()V"),
+ NATIVE_METHOD(NativeMethods, emptyJniSynchronizedMethod0, "()V"),
+};
+
+static void NativeMethods_emptyJniMethod0(JNIEnv*, jobject) { }
+static void NativeMethods_emptyJniMethod6(JNIEnv*, jobject, int, int, int, int, int, int) { }
+static void NativeMethods_emptyJniMethod6L(JNIEnv*, jobject, jobject, jarray, jarray, jobject,
+ jarray, jarray) { }
+static void NativeMethods_emptyJniStaticMethod6L(JNIEnv*, jclass, jobject, jarray, jarray, jobject,
+ jarray, jarray) { }
+
+static void NativeMethods_emptyJniStaticMethod0(JNIEnv*, jclass) { }
+static void NativeMethods_emptyJniStaticMethod6(JNIEnv*, jclass, int, int, int, int, int, int) { }
+
+static JNINativeMethod gMethods[] = {
+ NATIVE_METHOD(NativeMethods, emptyJniMethod0, "()V"),
+ NATIVE_METHOD(NativeMethods, emptyJniMethod6, "(IIIIII)V"),
+ NATIVE_METHOD(NativeMethods, emptyJniMethod6L, "(Ljava/lang/String;[Ljava/lang/String;[[ILjava/lang/Object;[Ljava/lang/Object;[[[[Ljava/lang/Object;)V"),
+ NATIVE_METHOD(NativeMethods, emptyJniStaticMethod6L, "(Ljava/lang/String;[Ljava/lang/String;[[ILjava/lang/Object;[Ljava/lang/Object;[[[[Ljava/lang/Object;)V"),
+ NATIVE_METHOD(NativeMethods, emptyJniStaticMethod0, "()V"),
+ NATIVE_METHOD(NativeMethods, emptyJniStaticMethod6, "(IIIIII)V"),
+};
+
+static void NativeMethods_emptyJniMethod0_Fast(JNIEnv*, jobject) { }
+static void NativeMethods_emptyJniMethod6_Fast(JNIEnv*, jobject, int, int, int, int, int, int) { }
+static void NativeMethods_emptyJniMethod6L_Fast(JNIEnv*, jobject, jobject, jarray, jarray, jobject,
+ jarray, jarray) { }
+static void NativeMethods_emptyJniStaticMethod6L_Fast(JNIEnv*, jclass, jobject, jarray, jarray,
+ jobject, jarray, jarray) { }
+
+static void NativeMethods_emptyJniStaticMethod0_Fast(JNIEnv*, jclass) { }
+static void NativeMethods_emptyJniStaticMethod6_Fast(JNIEnv*, jclass, int, int, int, int, int, int) { }
+
+static JNINativeMethod gMethods_Fast[] = {
+ NATIVE_METHOD(NativeMethods, emptyJniMethod0_Fast, "()V"),
+ NATIVE_METHOD(NativeMethods, emptyJniMethod6_Fast, "(IIIIII)V"),
+ NATIVE_METHOD(NativeMethods, emptyJniMethod6L_Fast, "(Ljava/lang/String;[Ljava/lang/String;[[ILjava/lang/Object;[Ljava/lang/Object;[[[[Ljava/lang/Object;)V"),
+ NATIVE_METHOD(NativeMethods, emptyJniStaticMethod6L_Fast, "(Ljava/lang/String;[Ljava/lang/String;[[ILjava/lang/Object;[Ljava/lang/Object;[[[[Ljava/lang/Object;)V"),
+ NATIVE_METHOD(NativeMethods, emptyJniStaticMethod0_Fast, "()V"),
+ NATIVE_METHOD(NativeMethods, emptyJniStaticMethod6_Fast, "(IIIIII)V"),
+};
+
+static void NativeMethods_emptyJniStaticMethod0_Critical() { }
+static void NativeMethods_emptyJniStaticMethod6_Critical(int, int, int, int, int, int) { }
+
+static JNINativeMethod gMethods_Critical[] = {
+ NATIVE_METHOD(NativeMethods, emptyJniStaticMethod0_Critical, "()V"),
+ NATIVE_METHOD(NativeMethods, emptyJniStaticMethod6_Critical, "(IIIIII)V"),
+};
+
+void register_micro_native_methods(JNIEnv* env) {
+ jniRegisterNativeMethods(env, CLASS_NAME, gMethods_NormalOnly, NELEM(gMethods_NormalOnly));
+ jniRegisterNativeMethods(env, CLASS_NAME, gMethods, NELEM(gMethods));
+ jniRegisterNativeMethods(env, CLASS_NAME, gMethods_Fast, NELEM(gMethods_Fast));
+ jniRegisterNativeMethods(env, CLASS_NAME, gMethods_Critical, NELEM(gMethods_Critical));
+}
diff --git a/compiler/Android.bp b/compiler/Android.bp
index 09c53b6..f264d30 100644
--- a/compiler/Android.bp
+++ b/compiler/Android.bp
@@ -185,6 +185,7 @@
},
generated_sources: ["art_compiler_operator_srcs"],
shared_libs: [
+ "libbase",
"liblz4",
"liblzma",
],
@@ -288,6 +289,7 @@
shared_libs: [
"libartd-compiler",
"libart-runtime-gtest",
+ "libbase",
],
}
diff --git a/compiler/dex/quick/dex_file_method_inliner.cc b/compiler/dex/quick/dex_file_method_inliner.cc
index 8d53dbf..6750554 100644
--- a/compiler/dex/quick/dex_file_method_inliner.cc
+++ b/compiler/dex/quick/dex_file_method_inliner.cc
@@ -640,28 +640,6 @@
INTRINSIC(JavaLangLong, RotateLeft, JI_J, kIntrinsicRotateLeft, k64),
#undef INTRINSIC
-
-#define SPECIAL(c, n, p, o, d) \
- { { kClassCache ## c, kNameCache ## n, kProtoCache ## p }, { o, kInlineSpecial, { d } } }
-
- SPECIAL(JavaLangString, Init, _V, kInlineStringInit, 0),
- SPECIAL(JavaLangString, Init, ByteArray_V, kInlineStringInit, 1),
- SPECIAL(JavaLangString, Init, ByteArrayI_V, kInlineStringInit, 2),
- SPECIAL(JavaLangString, Init, ByteArrayII_V, kInlineStringInit, 3),
- SPECIAL(JavaLangString, Init, ByteArrayIII_V, kInlineStringInit, 4),
- SPECIAL(JavaLangString, Init, ByteArrayIIString_V, kInlineStringInit, 5),
- SPECIAL(JavaLangString, Init, ByteArrayString_V, kInlineStringInit, 6),
- SPECIAL(JavaLangString, Init, ByteArrayIICharset_V, kInlineStringInit, 7),
- SPECIAL(JavaLangString, Init, ByteArrayCharset_V, kInlineStringInit, 8),
- SPECIAL(JavaLangString, Init, CharArray_V, kInlineStringInit, 9),
- SPECIAL(JavaLangString, Init, CharArrayII_V, kInlineStringInit, 10),
- SPECIAL(JavaLangString, Init, IICharArray_V, kInlineStringInit, 11),
- SPECIAL(JavaLangString, Init, IntArrayII_V, kInlineStringInit, 12),
- SPECIAL(JavaLangString, Init, String_V, kInlineStringInit, 13),
- SPECIAL(JavaLangString, Init, StringBuffer_V, kInlineStringInit, 14),
- SPECIAL(JavaLangString, Init, StringBuilder_V, kInlineStringInit, 15),
-
-#undef SPECIAL
};
DexFileMethodInliner::DexFileMethodInliner()
@@ -843,22 +821,4 @@
}
}
-uint32_t DexFileMethodInliner::GetOffsetForStringInit(uint32_t method_index,
- PointerSize pointer_size) {
- ReaderMutexLock mu(Thread::Current(), lock_);
- auto it = inline_methods_.find(method_index);
- if (it != inline_methods_.end() && (it->second.opcode == kInlineStringInit)) {
- uint32_t string_init_base_offset = Thread::QuickEntryPointOffsetWithSize(
- OFFSETOF_MEMBER(QuickEntryPoints, pNewEmptyString), pointer_size);
- return string_init_base_offset + it->second.d.data * static_cast<size_t>(pointer_size);
- }
- return 0;
-}
-
-bool DexFileMethodInliner::IsStringInitMethodIndex(uint32_t method_index) {
- ReaderMutexLock mu(Thread::Current(), lock_);
- auto it = inline_methods_.find(method_index);
- return (it != inline_methods_.end()) && (it->second.opcode == kInlineStringInit);
-}
-
} // namespace art
diff --git a/compiler/dex/quick/dex_file_method_inliner.h b/compiler/dex/quick/dex_file_method_inliner.h
index 43fc687..f4ae5a5 100644
--- a/compiler/dex/quick/dex_file_method_inliner.h
+++ b/compiler/dex/quick/dex_file_method_inliner.h
@@ -82,17 +82,6 @@
bool IsSpecial(uint32_t method_index) REQUIRES(!lock_);
/**
- * Gets the thread pointer entrypoint offset for a string init method index and pointer size.
- */
- uint32_t GetOffsetForStringInit(uint32_t method_index, PointerSize pointer_size)
- REQUIRES(!lock_);
-
- /**
- * Check whether a particular method index is a string init.
- */
- bool IsStringInitMethodIndex(uint32_t method_index) REQUIRES(!lock_);
-
- /**
* To avoid multiple lookups of a class by its descriptor, we cache its
* type index in the IndexCache. These are the indexes into the IndexCache
* class_indexes array.
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index adbf9fd..f1d3116 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -595,9 +595,14 @@
: optimizer::DexToDexCompilationLevel::kRequired);
}
} else if ((access_flags & kAccNative) != 0) {
- // Are we extracting only and have support for generic JNI down calls?
- if (!driver->GetCompilerOptions().IsJniCompilationEnabled() &&
- InstructionSetHasGenericJniStub(driver->GetInstructionSet())) {
+ const InstructionSet instruction_set = driver->GetInstructionSet();
+ const bool use_generic_jni =
+ // Are we extracting only and have support for generic JNI down calls?
+ (!driver->GetCompilerOptions().IsJniCompilationEnabled() &&
+ InstructionSetHasGenericJniStub(instruction_set)) ||
+ // Always punt to generic JNI for MIPS because of no support for @CriticalNative. b/31743474
+ (instruction_set == kMips || instruction_set == kMips64);
+ if (use_generic_jni) {
// Leaving this empty will trigger the generic JNI version
} else {
// Look-up the ArtMethod associated with this code_item (if any)
@@ -2789,18 +2794,6 @@
return oss.str();
}
-bool CompilerDriver::IsStringTypeIndex(uint16_t type_index, const DexFile* dex_file) {
- const char* type = dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_index));
- return strcmp(type, "Ljava/lang/String;") == 0;
-}
-
-bool CompilerDriver::IsStringInit(uint32_t method_index, const DexFile* dex_file, int32_t* offset) {
- DexFileMethodInliner* inliner = GetMethodInlinerMap()->GetMethodInliner(dex_file);
- const PointerSize pointer_size = InstructionSetPointerSize(GetInstructionSet());
- *offset = inliner->GetOffsetForStringInit(method_index, pointer_size);
- return inliner->IsStringInitMethodIndex(method_index);
-}
-
bool CompilerDriver::MayInlineInternal(const DexFile* inlined_from,
const DexFile* inlined_into) const {
// We're not allowed to inline across dex files if we're the no-inline-from dex file.
diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h
index 1f4c3ac..41f0d36 100644
--- a/compiler/driver/compiler_driver.h
+++ b/compiler/driver/compiler_driver.h
@@ -432,9 +432,6 @@
// Get memory usage during compilation.
std::string GetMemoryUsageString(bool extended) const;
- bool IsStringTypeIndex(uint16_t type_index, const DexFile* dex_file);
- bool IsStringInit(uint32_t method_index, const DexFile* dex_file, int32_t* offset);
-
void SetHadHardVerifierFailure() {
had_hard_verifier_failure_ = true;
}
diff --git a/compiler/image_writer.cc b/compiler/image_writer.cc
index ad881b7..6b5758b 100644
--- a/compiler/image_writer.cc
+++ b/compiler/image_writer.cc
@@ -45,6 +45,7 @@
#include "gc/space/space-inl.h"
#include "globals.h"
#include "image.h"
+#include "imt_conflict_table.h"
#include "intern_table.h"
#include "linear_alloc.h"
#include "lock_word.h"
diff --git a/compiler/oat_writer.cc b/compiler/oat_writer.cc
index 9045817..c840a9e 100644
--- a/compiler/oat_writer.cc
+++ b/compiler/oat_writer.cc
@@ -966,7 +966,7 @@
nullptr,
invoke_type);
if (method == nullptr) {
- LOG(INTERNAL_FATAL) << "Unexpected failure to resolve a method: "
+ LOG(FATAL_WITHOUT_ABORT) << "Unexpected failure to resolve a method: "
<< PrettyMethod(it.GetMemberIndex(), *dex_file_, true);
soa.Self()->AssertPendingException();
mirror::Throwable* exc = soa.Self()->GetException();
diff --git a/compiler/optimizing/code_generator_arm.cc b/compiler/optimizing/code_generator_arm.cc
index 6be458c..55e1221 100644
--- a/compiler/optimizing/code_generator_arm.cc
+++ b/compiler/optimizing/code_generator_arm.cc
@@ -6748,10 +6748,13 @@
Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
switch (invoke->GetMethodLoadKind()) {
- case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
+ case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: {
+ uint32_t offset =
+ GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value();
// temp = thread->string_init_entrypoint
- __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset());
+ __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, offset);
break;
+ }
case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
break;
diff --git a/compiler/optimizing/code_generator_arm64.cc b/compiler/optimizing/code_generator_arm64.cc
index 7160607..a2a2e42 100644
--- a/compiler/optimizing/code_generator_arm64.cc
+++ b/compiler/optimizing/code_generator_arm64.cc
@@ -3570,10 +3570,13 @@
// Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention.
Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
switch (invoke->GetMethodLoadKind()) {
- case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
+ case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: {
+ uint32_t offset =
+ GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value();
// temp = thread->string_init_entrypoint
- __ Ldr(XRegisterFrom(temp), MemOperand(tr, invoke->GetStringInitOffset()));
+ __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset));
break;
+ }
case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
break;
diff --git a/compiler/optimizing/code_generator_mips.cc b/compiler/optimizing/code_generator_mips.cc
index f560207..5c0ca85 100644
--- a/compiler/optimizing/code_generator_mips.cc
+++ b/compiler/optimizing/code_generator_mips.cc
@@ -4396,13 +4396,16 @@
}
switch (method_load_kind) {
- case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
+ case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: {
// temp = thread->string_init_entrypoint
+ uint32_t offset =
+ GetThreadOffset<kMipsPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value();
__ LoadFromOffset(kLoadWord,
temp.AsRegister<Register>(),
TR,
- invoke->GetStringInitOffset());
+ offset);
break;
+ }
case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
break;
diff --git a/compiler/optimizing/code_generator_mips64.cc b/compiler/optimizing/code_generator_mips64.cc
index a5e2351..02576bd 100644
--- a/compiler/optimizing/code_generator_mips64.cc
+++ b/compiler/optimizing/code_generator_mips64.cc
@@ -3006,13 +3006,16 @@
Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
switch (invoke->GetMethodLoadKind()) {
- case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
+ case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: {
// temp = thread->string_init_entrypoint
+ uint32_t offset =
+ GetThreadOffset<kMips64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value();
__ LoadFromOffset(kLoadDoubleword,
temp.AsRegister<GpuRegister>(),
TR,
- invoke->GetStringInitOffset());
+ offset);
break;
+ }
case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
break;
diff --git a/compiler/optimizing/code_generator_x86.cc b/compiler/optimizing/code_generator_x86.cc
index 47dfb2e..c300080 100644
--- a/compiler/optimizing/code_generator_x86.cc
+++ b/compiler/optimizing/code_generator_x86.cc
@@ -4276,10 +4276,13 @@
Location temp) {
Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
switch (invoke->GetMethodLoadKind()) {
- case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
+ case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: {
// temp = thread->string_init_entrypoint
- __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset()));
+ uint32_t offset =
+ GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value();
+ __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset));
break;
+ }
case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
break;
diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc
index 59c0ca4..f9a3e42 100644
--- a/compiler/optimizing/code_generator_x86_64.cc
+++ b/compiler/optimizing/code_generator_x86_64.cc
@@ -754,11 +754,13 @@
// All registers are assumed to be correctly set up.
Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
switch (invoke->GetMethodLoadKind()) {
- case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
+ case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: {
// temp = thread->string_init_entrypoint
- __ gs()->movq(temp.AsRegister<CpuRegister>(),
- Address::Absolute(invoke->GetStringInitOffset(), /* no_rip */ true));
+ uint32_t offset =
+ GetThreadOffset<kX86_64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value();
+ __ gs()->movq(temp.AsRegister<CpuRegister>(), Address::Absolute(offset, /* no_rip */ true));
break;
+ }
case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
break;
diff --git a/compiler/optimizing/instruction_builder.cc b/compiler/optimizing/instruction_builder.cc
index f7dc237..3b08d9f 100644
--- a/compiler/optimizing/instruction_builder.cc
+++ b/compiler/optimizing/instruction_builder.cc
@@ -21,6 +21,7 @@
#include "class_linker.h"
#include "dex_instruction-inl.h"
#include "driver/compiler_options.h"
+#include "imtable-inl.h"
#include "scoped_thread_state_change.h"
namespace art {
@@ -767,6 +768,11 @@
return resolved_method;
}
+static bool IsStringConstructor(ArtMethod* method) {
+ ScopedObjectAccess soa(Thread::Current());
+ return method->GetDeclaringClass()->IsStringClass() && method->IsConstructor();
+}
+
bool HInstructionBuilder::BuildInvoke(const Instruction& instruction,
uint32_t dex_pc,
uint32_t method_idx,
@@ -785,39 +791,6 @@
number_of_arguments++;
}
- // Special handling for string init.
- int32_t string_init_offset = 0;
- bool is_string_init = compiler_driver_->IsStringInit(method_idx,
- dex_file_,
- &string_init_offset);
- // Replace calls to String.<init> with StringFactory.
- if (is_string_init) {
- HInvokeStaticOrDirect::DispatchInfo dispatch_info = {
- HInvokeStaticOrDirect::MethodLoadKind::kStringInit,
- HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod,
- dchecked_integral_cast<uint64_t>(string_init_offset),
- 0U
- };
- MethodReference target_method(dex_file_, method_idx);
- HInvoke* invoke = new (arena_) HInvokeStaticOrDirect(
- arena_,
- number_of_arguments - 1,
- Primitive::kPrimNot /*return_type */,
- dex_pc,
- method_idx,
- nullptr,
- dispatch_info,
- invoke_type,
- target_method,
- HInvokeStaticOrDirect::ClinitCheckRequirement::kImplicit);
- return HandleStringInit(invoke,
- number_of_vreg_arguments,
- args,
- register_index,
- is_range,
- descriptor);
- }
-
ArtMethod* resolved_method = ResolveMethod(method_idx, invoke_type);
if (UNLIKELY(resolved_method == nullptr)) {
@@ -838,6 +811,35 @@
true /* is_unresolved */);
}
+ // Replace calls to String.<init> with StringFactory.
+ if (IsStringConstructor(resolved_method)) {
+ uint32_t string_init_entry_point = WellKnownClasses::StringInitToEntryPoint(resolved_method);
+ HInvokeStaticOrDirect::DispatchInfo dispatch_info = {
+ HInvokeStaticOrDirect::MethodLoadKind::kStringInit,
+ HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod,
+ dchecked_integral_cast<uint64_t>(string_init_entry_point),
+ 0U
+ };
+ MethodReference target_method(dex_file_, method_idx);
+ HInvoke* invoke = new (arena_) HInvokeStaticOrDirect(
+ arena_,
+ number_of_arguments - 1,
+ Primitive::kPrimNot /*return_type */,
+ dex_pc,
+ method_idx,
+ nullptr,
+ dispatch_info,
+ invoke_type,
+ target_method,
+ HInvokeStaticOrDirect::ClinitCheckRequirement::kImplicit);
+ return HandleStringInit(invoke,
+ number_of_vreg_arguments,
+ args,
+ register_index,
+ is_range,
+ descriptor);
+ }
+
// Potential class initialization check, in the case of a static method call.
HClinitCheck* clinit_check = nullptr;
HInvoke* invoke = nullptr;
@@ -894,7 +896,7 @@
dex_pc,
method_idx,
resolved_method,
- resolved_method->GetImtIndex());
+ ImTable::GetImtIndex(resolved_method));
}
return HandleInvoke(invoke,
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h
index 57ae555..4dc4c20 100644
--- a/compiler/optimizing/nodes.h
+++ b/compiler/optimizing/nodes.h
@@ -4044,9 +4044,9 @@
}
bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; }
- int32_t GetStringInitOffset() const {
+ QuickEntrypointEnum GetStringInitEntryPoint() const {
DCHECK(IsStringInit());
- return dispatch_info_.method_load_data;
+ return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data);
}
uint64_t GetMethodAddress() const {
diff --git a/dex2oat/Android.bp b/dex2oat/Android.bp
index 11c18b0..931bbd3 100644
--- a/dex2oat/Android.bp
+++ b/dex2oat/Android.bp
@@ -49,6 +49,7 @@
shared_libs: [
"libart",
"libart-compiler",
+ "libbase",
"libsigchain",
],
}
@@ -62,6 +63,7 @@
shared_libs: [
"libartd",
"libartd-compiler",
+ "libbase",
"libsigchain",
],
}
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index c422163..3b2715d 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -450,7 +450,11 @@
// it's rather easy to hang in unwinding.
// LogLine also avoids ART logging lock issues, as it's really only a wrapper around
// logcat logging or stderr output.
- LogMessage::LogLine(__FILE__, __LINE__, LogSeverity::FATAL, message.c_str());
+ android::base::LogMessage::LogLine(__FILE__,
+ __LINE__,
+ android::base::LogId::DEFAULT,
+ LogSeverity::FATAL,
+ message.c_str());
exit(1);
}
diff --git a/dexdump/Android.bp b/dexdump/Android.bp
index 64f2299..3e589f7 100644
--- a/dexdump/Android.bp
+++ b/dexdump/Android.bp
@@ -22,7 +22,10 @@
"dexdump.cc",
],
cflags: ["-Wall"],
- shared_libs: ["libart"],
+ shared_libs: [
+ "libart",
+ "libbase",
+ ],
}
art_cc_test {
diff --git a/dexlayout/Android.bp b/dexlayout/Android.bp
index c411572..296cdb6 100644
--- a/dexlayout/Android.bp
+++ b/dexlayout/Android.bp
@@ -22,7 +22,10 @@
"dex_ir_builder.cc",
],
cflags: ["-Wall"],
- shared_libs: ["libart"],
+ shared_libs: [
+ "libart",
+ "libbase",
+ ],
}
art_cc_test {
diff --git a/imgdiag/Android.bp b/imgdiag/Android.bp
index 7837d66..eaeb78e 100644
--- a/imgdiag/Android.bp
+++ b/imgdiag/Android.bp
@@ -26,7 +26,10 @@
// that the image it's analyzing be the same ISA as the runtime ISA.
compile_multilib: "both",
- shared_libs: ["libbacktrace"],
+ shared_libs: [
+ "libbacktrace",
+ "libbase",
+ ],
target: {
android: {
shared_libs: ["libcutils"],
diff --git a/oatdump/Android.bp b/oatdump/Android.bp
index dd6331c..bbe6cc1 100644
--- a/oatdump/Android.bp
+++ b/oatdump/Android.bp
@@ -34,6 +34,7 @@
"libart",
"libart-compiler",
"libart-disassembler",
+ "libbase",
],
}
@@ -47,6 +48,7 @@
"libartd",
"libartd-compiler",
"libartd-disassembler",
+ "libbase",
],
}
diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc
index d8ac581..06d9814 100644
--- a/oatdump/oatdump.cc
+++ b/oatdump/oatdump.cc
@@ -23,6 +23,7 @@
#include <set>
#include <string>
#include <unordered_map>
+#include <unordered_set>
#include <vector>
#include "arch/instruction_set_features.h"
@@ -42,6 +43,7 @@
#include "gc/space/large_object_space.h"
#include "gc/space/space-inl.h"
#include "image-inl.h"
+#include "imtable-inl.h"
#include "indenter.h"
#include "linker/buffered_output_stream.h"
#include "linker/file_output_stream.h"
@@ -2547,6 +2549,392 @@
return EXIT_SUCCESS;
}
+class IMTDumper {
+ public:
+ static bool DumpImt(Runtime* runtime, const std::string& imt_file) {
+ std::vector<std::string> lines = ReadCommentedInputFromFile(imt_file);
+ std::unordered_set<std::string> prepared;
+
+ for (const std::string& line : lines) {
+ // A line should be either a class descriptor, in which case we will dump the complete IMT,
+ // or a class descriptor and an interface method, in which case we will lookup the method,
+ // determine its IMT slot, and check the class' IMT.
+ size_t first_space = line.find(' ');
+ if (first_space == std::string::npos) {
+ DumpIMTForClass(runtime, line, &prepared);
+ } else {
+ DumpIMTForMethod(runtime,
+ line.substr(0, first_space),
+ line.substr(first_space + 1, std::string::npos),
+ &prepared);
+ }
+ std::cerr << std::endl;
+ }
+
+ return true;
+ }
+
+ static bool DumpImtStats(Runtime* runtime, const std::vector<const DexFile*>& dex_files) {
+ size_t wo_imt = 0;
+ size_t w_imt = 0;
+ std::map<size_t, size_t> histogram;
+
+ ClassLinker* class_linker = runtime->GetClassLinker();
+ const PointerSize pointer_size = class_linker->GetImagePointerSize();
+ std::unordered_set<std::string> prepared;
+
+ Thread* self = Thread::Current();
+ ScopedObjectAccess soa(self);
+ StackHandleScope<1> scope(self);
+ MutableHandle<mirror::Class> h_klass(scope.NewHandle<mirror::Class>(nullptr));
+
+ for (const DexFile* dex_file : dex_files) {
+ for (uint32_t class_def_index = 0;
+ class_def_index != dex_file->NumClassDefs();
+ ++class_def_index) {
+ const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index);
+ const char* descriptor = dex_file->GetClassDescriptor(class_def);
+ h_klass.Assign(class_linker->FindClass(self,
+ descriptor,
+ ScopedNullHandle<mirror::ClassLoader>()));
+ if (h_klass.Get() == nullptr) {
+ std::cerr << "Warning: could not load " << descriptor << std::endl;
+ continue;
+ }
+
+ if (HasNoIMT(runtime, h_klass, pointer_size, &prepared)) {
+ wo_imt++;
+ continue;
+ }
+
+ ImTable* im_table = PrepareAndGetImTable(runtime, h_klass, pointer_size, &prepared);
+ if (im_table == nullptr) {
+ // Should not happen, but accept.
+ wo_imt++;
+ continue;
+ }
+
+ w_imt++;
+ for (size_t imt_index = 0; imt_index != ImTable::kSize; ++imt_index) {
+ ArtMethod* ptr = im_table->Get(imt_index, pointer_size);
+ if (ptr->IsRuntimeMethod()) {
+ if (ptr->IsImtUnimplementedMethod()) {
+ histogram[0]++;
+ } else {
+ ImtConflictTable* current_table = ptr->GetImtConflictTable(pointer_size);
+ histogram[current_table->NumEntries(pointer_size)]++;
+ }
+ } else {
+ histogram[1]++;
+ }
+ }
+ }
+ }
+
+ std::cerr << "IMT stats:"
+ << std::endl << std::endl;
+
+ std::cerr << " " << w_imt << " classes with IMT."
+ << std::endl << std::endl;
+ std::cerr << " " << wo_imt << " classes without IMT (or copy from Object)."
+ << std::endl << std::endl;
+
+ double sum_one = 0;
+ size_t count_one = 0;
+
+ std::cerr << " " << "IMT histogram" << std::endl;
+ for (auto& bucket : histogram) {
+ std::cerr << " " << bucket.first << " " << bucket.second << std::endl;
+ if (bucket.first > 0) {
+ sum_one += bucket.second * bucket.first;
+ count_one += bucket.second;
+ }
+ }
+
+ double count_zero = count_one + histogram[0];
+ std::cerr << " Stats:" << std::endl;
+ std::cerr << " Average depth (including empty): " << (sum_one / count_zero) << std::endl;
+ std::cerr << " Average depth (excluding empty): " << (sum_one / count_one) << std::endl;
+
+ return true;
+ }
+
+ private:
+ // Check whether the given class has no IMT (or the one shared with java.lang.Object).
+ static bool HasNoIMT(Runtime* runtime,
+ Handle<mirror::Class> klass,
+ const PointerSize pointer_size,
+ std::unordered_set<std::string>* prepared)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ if (klass->IsObjectClass() || !klass->ShouldHaveImt()) {
+ return true;
+ }
+
+ if (klass->GetImt(pointer_size) == nullptr) {
+ PrepareClass(runtime, klass, prepared);
+ }
+
+ mirror::Class* object_class = mirror::Class::GetJavaLangClass()->GetSuperClass();
+ DCHECK(object_class->IsObjectClass());
+
+ bool result = klass->GetImt(pointer_size) == object_class->GetImt(pointer_size);
+
+ if (klass->GetIfTable() == nullptr) {
+ DCHECK(result);
+ }
+
+ return result;
+ }
+
+ static void PrintTable(ImtConflictTable* table, PointerSize pointer_size)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ if (table == nullptr) {
+ std::cerr << " <No IMT?>" << std::endl;
+ return;
+ }
+ size_t table_index = 0;
+ for (;;) {
+ ArtMethod* ptr = table->GetInterfaceMethod(table_index, pointer_size);
+ if (ptr == nullptr) {
+ return;
+ }
+ table_index++;
+ std::cerr << " " << PrettyMethod(ptr, true) << std::endl;
+ }
+ }
+
+ static ImTable* PrepareAndGetImTable(Runtime* runtime,
+ Thread* self,
+ const std::string& class_name,
+ const PointerSize pointer_size,
+ mirror::Class** klass_out,
+ std::unordered_set<std::string>* prepared)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ if (class_name.empty()) {
+ return nullptr;
+ }
+
+ std::string descriptor;
+ if (class_name[0] == 'L') {
+ descriptor = class_name;
+ } else {
+ descriptor = DotToDescriptor(class_name.c_str());
+ }
+
+ ScopedNullHandle<mirror::ClassLoader> null_handle;
+
+ mirror::Class* klass =
+ runtime->GetClassLinker()->FindClass(self, descriptor.c_str(), null_handle);
+
+ if (klass == nullptr) {
+ self->ClearException();
+ std::cerr << "Did not find " << class_name << std::endl;
+ *klass_out = nullptr;
+ return nullptr;
+ }
+
+ StackHandleScope<1> scope(Thread::Current());
+ Handle<mirror::Class> h_klass = scope.NewHandle<mirror::Class>(klass);
+
+ ImTable* ret = PrepareAndGetImTable(runtime, h_klass, pointer_size, prepared);
+ *klass_out = h_klass.Get();
+ return ret;
+ }
+
+ static ImTable* PrepareAndGetImTable(Runtime* runtime,
+ Handle<mirror::Class> h_klass,
+ const PointerSize pointer_size,
+ std::unordered_set<std::string>* prepared)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ PrepareClass(runtime, h_klass, prepared);
+ return h_klass->GetImt(pointer_size);
+ }
+
+ static void DumpIMTForClass(Runtime* runtime,
+ const std::string& class_name,
+ std::unordered_set<std::string>* prepared) {
+ Thread* self = Thread::Current();
+ ScopedObjectAccess soa(self);
+
+ const PointerSize pointer_size = runtime->GetClassLinker()->GetImagePointerSize();
+ mirror::Class* klass;
+ ImTable* imt = PrepareAndGetImTable(runtime, self, class_name, pointer_size, &klass, prepared);
+ if (imt == nullptr) {
+ return;
+ }
+
+ std::cerr << class_name << std::endl << " IMT:" << std::endl;
+ for (size_t index = 0; index < ImTable::kSize; ++index) {
+ std::cerr << " " << index << ":" << std::endl;
+ ArtMethod* ptr = imt->Get(index, pointer_size);
+ if (ptr->IsRuntimeMethod()) {
+ if (ptr->IsImtUnimplementedMethod()) {
+ std::cerr << " <empty>" << std::endl;
+ } else {
+ ImtConflictTable* current_table = ptr->GetImtConflictTable(pointer_size);
+ PrintTable(current_table, pointer_size);
+ }
+ } else {
+ std::cerr << " " << PrettyMethod(ptr, true) << std::endl;
+ }
+ }
+
+ std::cerr << " Interfaces:" << std::endl;
+ // Run through iftable, find methods that slot here, see if they fit.
+ mirror::IfTable* if_table = klass->GetIfTable();
+ if (if_table != nullptr) {
+ for (size_t i = 0, num_interfaces = klass->GetIfTableCount(); i < num_interfaces; ++i) {
+ mirror::Class* iface = if_table->GetInterface(i);
+ std::string iface_name;
+ std::cerr << " " << iface->GetDescriptor(&iface_name) << std::endl;
+
+ for (ArtMethod& iface_method : iface->GetVirtualMethods(pointer_size)) {
+ uint32_t base_hash = ImTable::GetBaseImtHash(&iface_method);
+ uint32_t imt_slot = ImTable::GetImtIndex(&iface_method);
+ std::cerr << " " << PrettyMethod(&iface_method, true) << " slot=" << std::dec
+ << imt_slot << " base_hash=0x" << std::hex << base_hash << std::endl;
+ }
+ }
+ }
+ }
+
+ static void DumpIMTForMethod(Runtime* runtime,
+ const std::string& class_name,
+ const std::string& method,
+ std::unordered_set<std::string>* prepared) {
+ Thread* self = Thread::Current();
+ ScopedObjectAccess soa(self);
+
+ const PointerSize pointer_size = runtime->GetClassLinker()->GetImagePointerSize();
+ mirror::Class* klass;
+ ImTable* imt = PrepareAndGetImTable(runtime,
+ self,
+ class_name,
+ pointer_size,
+ &klass,
+ prepared);
+ if (imt == nullptr) {
+ return;
+ }
+
+ std::cerr << class_name << " <" << method << ">" << std::endl;
+ for (size_t index = 0; index < ImTable::kSize; ++index) {
+ ArtMethod* ptr = imt->Get(index, pointer_size);
+ if (ptr->IsRuntimeMethod()) {
+ if (ptr->IsImtUnimplementedMethod()) {
+ continue;
+ }
+
+ ImtConflictTable* current_table = ptr->GetImtConflictTable(pointer_size);
+ if (current_table == nullptr) {
+ continue;
+ }
+
+ size_t table_index = 0;
+ for (;;) {
+ ArtMethod* ptr2 = current_table->GetInterfaceMethod(table_index, pointer_size);
+ if (ptr2 == nullptr) {
+ break;
+ }
+ table_index++;
+
+ std::string p_name = PrettyMethod(ptr2, true);
+ if (StartsWith(p_name, method.c_str())) {
+ std::cerr << " Slot "
+ << index
+ << " ("
+ << current_table->NumEntries(pointer_size)
+ << ")"
+ << std::endl;
+ PrintTable(current_table, pointer_size);
+ return;
+ }
+ }
+ } else {
+ std::string p_name = PrettyMethod(ptr, true);
+ if (StartsWith(p_name, method.c_str())) {
+ std::cerr << " Slot " << index << " (1)" << std::endl;
+ std::cerr << " " << p_name << std::endl;
+ } else {
+ // Run through iftable, find methods that slot here, see if they fit.
+ mirror::IfTable* if_table = klass->GetIfTable();
+ if (if_table != nullptr) {
+ for (size_t i = 0, num_interfaces = klass->GetIfTableCount(); i < num_interfaces; ++i) {
+ mirror::Class* iface = if_table->GetInterface(i);
+ size_t num_methods = iface->NumDeclaredVirtualMethods();
+ if (num_methods > 0) {
+ for (ArtMethod& iface_method : iface->GetMethods(pointer_size)) {
+ if (ImTable::GetImtIndex(&iface_method) == index) {
+ std::string i_name = PrettyMethod(&iface_method, true);
+ if (StartsWith(i_name, method.c_str())) {
+ std::cerr << " Slot " << index << " (1)" << std::endl;
+ std::cerr << " " << p_name << " (" << i_name << ")" << std::endl;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // Read lines from the given stream, dropping comments and empty lines
+ static std::vector<std::string> ReadCommentedInputStream(std::istream& in_stream) {
+ std::vector<std::string> output;
+ while (in_stream.good()) {
+ std::string dot;
+ std::getline(in_stream, dot);
+ if (StartsWith(dot, "#") || dot.empty()) {
+ continue;
+ }
+ output.push_back(dot);
+ }
+ return output;
+ }
+
+ // Read lines from the given file, dropping comments and empty lines.
+ static std::vector<std::string> ReadCommentedInputFromFile(const std::string& input_filename) {
+ std::unique_ptr<std::ifstream> input_file(new std::ifstream(input_filename, std::ifstream::in));
+ if (input_file.get() == nullptr) {
+ LOG(ERROR) << "Failed to open input file " << input_filename;
+ return std::vector<std::string>();
+ }
+ std::vector<std::string> result = ReadCommentedInputStream(*input_file);
+ input_file->close();
+ return result;
+ }
+
+ // Prepare a class, i.e., ensure it has a filled IMT. Will do so recursively for superclasses,
+ // and note in the given set that the work was done.
+ static void PrepareClass(Runtime* runtime,
+ Handle<mirror::Class> h_klass,
+ std::unordered_set<std::string>* done)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ if (!h_klass->ShouldHaveImt()) {
+ return;
+ }
+
+ std::string name;
+ name = h_klass->GetDescriptor(&name);
+
+ if (done->find(name) != done->end()) {
+ return;
+ }
+ done->insert(name);
+
+ if (h_klass->HasSuperClass()) {
+ StackHandleScope<1> h(Thread::Current());
+ PrepareClass(runtime, h.NewHandle<mirror::Class>(h_klass->GetSuperClass()), done);
+ }
+
+ if (!h_klass->IsTemp()) {
+ runtime->GetClassLinker()->FillIMTAndConflictTables(h_klass.Get());
+ }
+ }
+};
+
struct OatdumpArgs : public CmdlineArgs {
protected:
using Base = CmdlineArgs;
@@ -2596,6 +2984,10 @@
app_image_ = option.substr(strlen("--app-image=")).data();
} else if (option.starts_with("--app-oat=")) {
app_oat_ = option.substr(strlen("--app-oat=")).data();
+ } else if (option.starts_with("--dump-imt=")) {
+ imt_dump_ = option.substr(strlen("--dump-imt=")).data();
+ } else if (option == "--dump-imt-stats") {
+ imt_stat_dump_ = true;
} else {
return kParseUnknownArgument;
}
@@ -2692,6 +3084,16 @@
" --addr2instr=<address>: output matching method disassembled code from relative\n"
" address (e.g. PC from crash dump)\n"
" Example: --addr2instr=0x00001a3b\n"
+ "\n"
+ " --dump-imt=<file.txt>: output IMT collisions (if any) for the given receiver\n"
+ " types and interface methods in the given file. The file\n"
+ " is read line-wise, and each line should either be a class\n"
+ " name or descriptor, or a class name/descriptor and a prefix\n"
+ " of a complete method name.\n"
+ " Example: --dump-imt=imt.txt\n"
+ "\n"
+ " --dump-imt-stats: output IMT statistics for the given boot image\n"
+ " Example: --dump-imt-stats"
"\n";
return usage;
@@ -2703,6 +3105,7 @@
const char* method_filter_ = "";
const char* image_location_ = nullptr;
std::string elf_filename_prefix_;
+ std::string imt_dump_;
bool dump_vmap_ = true;
bool dump_code_info_stack_maps_ = false;
bool disassemble_code_ = true;
@@ -2711,6 +3114,7 @@
bool list_classes_ = false;
bool list_methods_ = false;
bool dump_header_only_ = false;
+ bool imt_stat_dump_ = false;
uint32_t addr2instr_ = 0;
const char* export_dex_location_ = nullptr;
const char* app_image_ = nullptr;
@@ -2739,7 +3143,9 @@
args_->app_oat_,
args_->addr2instr_));
- return (args_->boot_image_location_ != nullptr || args_->image_location_ != nullptr) &&
+ return (args_->boot_image_location_ != nullptr ||
+ args_->image_location_ != nullptr ||
+ !args_->imt_dump_.empty()) &&
!args_->symbolize_;
}
@@ -2767,6 +3173,14 @@
virtual bool ExecuteWithRuntime(Runtime* runtime) {
CHECK(args_ != nullptr);
+ if (!args_->imt_dump_.empty()) {
+ return IMTDumper::DumpImt(runtime, args_->imt_dump_);
+ }
+
+ if (args_->imt_stat_dump_) {
+ return IMTDumper::DumpImtStats(runtime, runtime->GetClassLinker()->GetBootClassPath());
+ }
+
if (args_->oat_filename_ != nullptr) {
return DumpOat(runtime,
args_->oat_filename_,
diff --git a/patchoat/Android.bp b/patchoat/Android.bp
index 8d8d6d1..a78f97d 100644
--- a/patchoat/Android.bp
+++ b/patchoat/Android.bp
@@ -24,6 +24,9 @@
compile_multilib: "prefer32",
},
},
+ shared_libs: [
+ "libbase",
+ ],
}
art_cc_binary {
diff --git a/profman/Android.bp b/profman/Android.bp
index 322dda2..2dcbaee 100644
--- a/profman/Android.bp
+++ b/profman/Android.bp
@@ -32,6 +32,10 @@
include_dirs: [
"art/cmdline",
],
+
+ shared_libs: [
+ "libbase",
+ ],
}
art_cc_binary {
diff --git a/runtime/Android.bp b/runtime/Android.bp
index ad953ea..fd9b5b9 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -470,6 +470,7 @@
srcs: ["common_runtime_test.cc"],
shared_libs: [
"libartd",
+ "libbase",
],
}
diff --git a/runtime/arch/stub_test.cc b/runtime/arch/stub_test.cc
index 507dbf0..3424e3c 100644
--- a/runtime/arch/stub_test.cc
+++ b/runtime/arch/stub_test.cc
@@ -22,6 +22,7 @@
#include "class_linker-inl.h"
#include "common_runtime_test.h"
#include "entrypoints/quick/quick_entrypoints_enum.h"
+#include "imt_conflict_table.h"
#include "linear_alloc.h"
#include "mirror/class-inl.h"
#include "mirror/string-inl.h"
diff --git a/runtime/art_method-inl.h b/runtime/art_method-inl.h
index 9b4b38a..73cce5e 100644
--- a/runtime/art_method-inl.h
+++ b/runtime/art_method-inl.h
@@ -123,10 +123,6 @@
return dex_method_index_;
}
-inline uint32_t ArtMethod::GetImtIndex() {
- return GetDexMethodIndex() % ImTable::kSize;
-}
-
inline ArtMethod** ArtMethod::GetDexCacheResolvedMethods(PointerSize pointer_size) {
return GetNativePointer<ArtMethod**>(DexCacheResolvedMethodsOffset(pointer_size),
pointer_size);
diff --git a/runtime/art_method.h b/runtime/art_method.h
index b1baccd..3d2db69 100644
--- a/runtime/art_method.h
+++ b/runtime/art_method.h
@@ -34,6 +34,7 @@
namespace art {
template<class T> class Handle;
+class ImtConflictTable;
union JValue;
class OatQuickMethodHeader;
class ProfilingInfo;
@@ -48,175 +49,6 @@
class PointerArray;
} // namespace mirror
-// Table to resolve IMT conflicts at runtime. The table is attached to
-// the jni entrypoint of IMT conflict ArtMethods.
-// The table contains a list of pairs of { interface_method, implementation_method }
-// with the last entry being null to make an assembly implementation of a lookup
-// faster.
-class ImtConflictTable {
- enum MethodIndex {
- kMethodInterface,
- kMethodImplementation,
- kMethodCount, // Number of elements in enum.
- };
-
- public:
- // Build a new table copying `other` and adding the new entry formed of
- // the pair { `interface_method`, `implementation_method` }
- ImtConflictTable(ImtConflictTable* other,
- ArtMethod* interface_method,
- ArtMethod* implementation_method,
- PointerSize pointer_size) {
- const size_t count = other->NumEntries(pointer_size);
- for (size_t i = 0; i < count; ++i) {
- SetInterfaceMethod(i, pointer_size, other->GetInterfaceMethod(i, pointer_size));
- SetImplementationMethod(i, pointer_size, other->GetImplementationMethod(i, pointer_size));
- }
- SetInterfaceMethod(count, pointer_size, interface_method);
- SetImplementationMethod(count, pointer_size, implementation_method);
- // Add the null marker.
- SetInterfaceMethod(count + 1, pointer_size, nullptr);
- SetImplementationMethod(count + 1, pointer_size, nullptr);
- }
-
- // num_entries excludes the header.
- ImtConflictTable(size_t num_entries, PointerSize pointer_size) {
- SetInterfaceMethod(num_entries, pointer_size, nullptr);
- SetImplementationMethod(num_entries, pointer_size, nullptr);
- }
-
- // Set an entry at an index.
- void SetInterfaceMethod(size_t index, PointerSize pointer_size, ArtMethod* method) {
- SetMethod(index * kMethodCount + kMethodInterface, pointer_size, method);
- }
-
- void SetImplementationMethod(size_t index, PointerSize pointer_size, ArtMethod* method) {
- SetMethod(index * kMethodCount + kMethodImplementation, pointer_size, method);
- }
-
- ArtMethod* GetInterfaceMethod(size_t index, PointerSize pointer_size) const {
- return GetMethod(index * kMethodCount + kMethodInterface, pointer_size);
- }
-
- ArtMethod* GetImplementationMethod(size_t index, PointerSize pointer_size) const {
- return GetMethod(index * kMethodCount + kMethodImplementation, pointer_size);
- }
-
- // Return true if two conflict tables are the same.
- bool Equals(ImtConflictTable* other, PointerSize pointer_size) const {
- size_t num = NumEntries(pointer_size);
- if (num != other->NumEntries(pointer_size)) {
- return false;
- }
- for (size_t i = 0; i < num; ++i) {
- if (GetInterfaceMethod(i, pointer_size) != other->GetInterfaceMethod(i, pointer_size) ||
- GetImplementationMethod(i, pointer_size) !=
- other->GetImplementationMethod(i, pointer_size)) {
- return false;
- }
- }
- return true;
- }
-
- // Visit all of the entries.
- // NO_THREAD_SAFETY_ANALYSIS for calling with held locks. Visitor is passed a pair of ArtMethod*
- // and also returns one. The order is <interface, implementation>.
- template<typename Visitor>
- void Visit(const Visitor& visitor, PointerSize pointer_size) NO_THREAD_SAFETY_ANALYSIS {
- uint32_t table_index = 0;
- for (;;) {
- ArtMethod* interface_method = GetInterfaceMethod(table_index, pointer_size);
- if (interface_method == nullptr) {
- break;
- }
- ArtMethod* implementation_method = GetImplementationMethod(table_index, pointer_size);
- auto input = std::make_pair(interface_method, implementation_method);
- std::pair<ArtMethod*, ArtMethod*> updated = visitor(input);
- if (input.first != updated.first) {
- SetInterfaceMethod(table_index, pointer_size, updated.first);
- }
- if (input.second != updated.second) {
- SetImplementationMethod(table_index, pointer_size, updated.second);
- }
- ++table_index;
- }
- }
-
- // Lookup the implementation ArtMethod associated to `interface_method`. Return null
- // if not found.
- ArtMethod* Lookup(ArtMethod* interface_method, PointerSize pointer_size) const {
- uint32_t table_index = 0;
- for (;;) {
- ArtMethod* current_interface_method = GetInterfaceMethod(table_index, pointer_size);
- if (current_interface_method == nullptr) {
- break;
- }
- if (current_interface_method == interface_method) {
- return GetImplementationMethod(table_index, pointer_size);
- }
- ++table_index;
- }
- return nullptr;
- }
-
- // Compute the number of entries in this table.
- size_t NumEntries(PointerSize pointer_size) const {
- uint32_t table_index = 0;
- while (GetInterfaceMethod(table_index, pointer_size) != nullptr) {
- ++table_index;
- }
- return table_index;
- }
-
- // Compute the size in bytes taken by this table.
- size_t ComputeSize(PointerSize pointer_size) const {
- // Add the end marker.
- return ComputeSize(NumEntries(pointer_size), pointer_size);
- }
-
- // Compute the size in bytes needed for copying the given `table` and add
- // one more entry.
- static size_t ComputeSizeWithOneMoreEntry(ImtConflictTable* table, PointerSize pointer_size) {
- return table->ComputeSize(pointer_size) + EntrySize(pointer_size);
- }
-
- // Compute size with a fixed number of entries.
- static size_t ComputeSize(size_t num_entries, PointerSize pointer_size) {
- return (num_entries + 1) * EntrySize(pointer_size); // Add one for null terminator.
- }
-
- static size_t EntrySize(PointerSize pointer_size) {
- return static_cast<size_t>(pointer_size) * static_cast<size_t>(kMethodCount);
- }
-
- private:
- ArtMethod* GetMethod(size_t index, PointerSize pointer_size) const {
- if (pointer_size == PointerSize::k64) {
- return reinterpret_cast<ArtMethod*>(static_cast<uintptr_t>(data64_[index]));
- } else {
- return reinterpret_cast<ArtMethod*>(static_cast<uintptr_t>(data32_[index]));
- }
- }
-
- void SetMethod(size_t index, PointerSize pointer_size, ArtMethod* method) {
- if (pointer_size == PointerSize::k64) {
- data64_[index] = dchecked_integral_cast<uint64_t>(reinterpret_cast<uintptr_t>(method));
- } else {
- data32_[index] = dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(method));
- }
- }
-
- // Array of entries that the assembly stubs will iterate over. Note that this is
- // not fixed size, and we allocate data prior to calling the constructor
- // of ImtConflictTable.
- union {
- uint32_t data32_[0];
- uint64_t data64_[0];
- };
-
- DISALLOW_COPY_AND_ASSIGN(ImtConflictTable);
-};
-
class ArtMethod FINAL {
public:
ArtMethod() : access_flags_(0), dex_code_item_offset_(0), dex_method_index_(0),
@@ -428,8 +260,6 @@
ALWAYS_INLINE uint32_t GetDexMethodIndex() REQUIRES_SHARED(Locks::mutator_lock_);
- ALWAYS_INLINE uint32_t GetImtIndex() REQUIRES_SHARED(Locks::mutator_lock_);
-
void SetDexMethodIndex(uint32_t new_idx) {
// Not called within a transaction.
dex_method_index_ = new_idx;
diff --git a/runtime/base/bit_utils.h b/runtime/base/bit_utils.h
index d2f0fdb..f0811b0 100644
--- a/runtime/base/bit_utils.h
+++ b/runtime/base/bit_utils.h
@@ -21,13 +21,8 @@
#include <limits>
#include <type_traits>
-// This header is used in the disassembler with libbase's logging. Only include ART logging
-// when no other logging macros are available. b/15436106, b/31338270
-#ifndef CHECK
-#include "base/logging.h"
-#endif
-
#include "base/iteration_range.h"
+#include "base/logging.h"
#include "base/stl_util.h"
namespace art {
diff --git a/runtime/base/logging.cc b/runtime/base/logging.cc
index e00e62d..17873b5 100644
--- a/runtime/base/logging.cc
+++ b/runtime/base/logging.cc
@@ -28,6 +28,7 @@
// Headers for LogMessage::LogLine.
#ifdef ART_TARGET_ANDROID
#include "cutils/log.h"
+#include <android/set_abort_message.h>
#else
#include <sys/types.h>
#include <unistd.h>
@@ -39,24 +40,10 @@
unsigned int gAborting = 0;
-static LogSeverity gMinimumLogSeverity = INFO;
static std::unique_ptr<std::string> gCmdLine;
static std::unique_ptr<std::string> gProgramInvocationName;
static std::unique_ptr<std::string> gProgramInvocationShortName;
-// Print INTERNAL_FATAL messages directly instead of at destruction time. This only works on the
-// host right now: for the device, a stream buf collating output into lines and calling LogLine or
-// lower-level logging is necessary.
-#ifdef ART_TARGET_ANDROID
-static constexpr bool kPrintInternalFatalDirectly = false;
-#else
-static constexpr bool kPrintInternalFatalDirectly = !kIsTargetBuild;
-#endif
-
-static bool PrintDirectly(LogSeverity severity) {
- return kPrintInternalFatalDirectly && severity == INTERNAL_FATAL;
-}
-
const char* GetCmdLine() {
return (gCmdLine.get() != nullptr) ? gCmdLine->c_str() : nullptr;
}
@@ -70,6 +57,16 @@
: "art";
}
+NO_RETURN
+static void RuntimeAborter(const char* abort_message) {
+#ifdef __ANDROID__
+ android_set_abort_message(abort_message);
+#else
+ UNUSED(abort_message);
+#endif
+ Runtime::Abort();
+}
+
void InitLogging(char* argv[]) {
if (gCmdLine.get() != nullptr) {
return;
@@ -94,150 +91,14 @@
// TODO: fall back to /proc/self/cmdline when argv is null on Linux.
gCmdLine.reset(new std::string("<unset>"));
}
- const char* tags = getenv("ANDROID_LOG_TAGS");
- if (tags == nullptr) {
- return;
- }
- std::vector<std::string> specs;
- Split(tags, ' ', &specs);
- for (size_t i = 0; i < specs.size(); ++i) {
- // "tag-pattern:[vdiwefs]"
- std::string spec(specs[i]);
- if (spec.size() == 3 && StartsWith(spec, "*:")) {
- switch (spec[2]) {
- case 'v':
- gMinimumLogSeverity = VERBOSE;
- continue;
- case 'd':
- gMinimumLogSeverity = DEBUG;
- continue;
- case 'i':
- gMinimumLogSeverity = INFO;
- continue;
- case 'w':
- gMinimumLogSeverity = WARNING;
- continue;
- case 'e':
- gMinimumLogSeverity = ERROR;
- continue;
- case 'f':
- gMinimumLogSeverity = FATAL;
- continue;
- // liblog will even suppress FATAL if you say 's' for silent, but that's crazy!
- case 's':
- gMinimumLogSeverity = FATAL;
- continue;
- }
- }
- LOG(FATAL) << "unsupported '" << spec << "' in ANDROID_LOG_TAGS (" << tags << ")";
- }
-}
-
-// This indirection greatly reduces the stack impact of having
-// lots of checks/logging in a function.
-class LogMessageData {
- public:
- LogMessageData(const char* file, unsigned int line, LogSeverity severity, int error)
- : file_(GetFilenameBase(file)),
- line_number_(line),
- severity_(severity),
- error_(error) {}
-
- const char * GetFile() const {
- return file_;
- }
-
- unsigned int GetLineNumber() const {
- return line_number_;
- }
-
- LogSeverity GetSeverity() const {
- return severity_;
- }
-
- int GetError() const {
- return error_;
- }
-
- std::ostream& GetBuffer() {
- return buffer_;
- }
-
- std::string ToString() const {
- return buffer_.str();
- }
-
- private:
- std::ostringstream buffer_;
- const char* const file_;
- const unsigned int line_number_;
- const LogSeverity severity_;
- const int error_;
-
- static const char* GetFilenameBase(const char* file) {
- const char* last_slash = strrchr(file, '/');
- return (last_slash == nullptr) ? file : last_slash + 1;
- }
-
- DISALLOW_COPY_AND_ASSIGN(LogMessageData);
-};
-
-
-LogMessage::LogMessage(const char* file, unsigned int line, LogSeverity severity, int error)
- : data_(new LogMessageData(file, line, severity, error)) {
- if (PrintDirectly(severity)) {
- static constexpr char kLogCharacters[] = { 'V', 'D', 'I', 'W', 'E', 'F', 'F' };
- static_assert(arraysize(kLogCharacters) == static_cast<size_t>(INTERNAL_FATAL) + 1,
- "Wrong character array size");
- stream() << ProgramInvocationShortName() << " " << kLogCharacters[static_cast<size_t>(severity)]
- << " " << getpid() << " " << ::art::GetTid() << " " << file << ":" << line << "]";
- }
-}
-LogMessage::~LogMessage() {
- if (PrintDirectly(data_->GetSeverity())) {
- // Add newline at the end to match the not printing directly behavior.
- std::cerr << '\n';
- } else {
- if (data_->GetSeverity() < gMinimumLogSeverity) {
- return; // No need to format something we're not going to output.
- }
-
- // Finish constructing the message.
- if (data_->GetError() != -1) {
- data_->GetBuffer() << ": " << strerror(data_->GetError());
- }
- std::string msg(data_->ToString());
-
- // Do the actual logging with the lock held.
- {
- MutexLock mu(Thread::Current(), *Locks::logging_lock_);
- if (msg.find('\n') == std::string::npos) {
- LogLine(data_->GetFile(), data_->GetLineNumber(), data_->GetSeverity(), msg.c_str());
- } else {
- msg += '\n';
- size_t i = 0;
- while (i < msg.size()) {
- size_t nl = msg.find('\n', i);
- msg[nl] = '\0';
- LogLine(data_->GetFile(), data_->GetLineNumber(), data_->GetSeverity(), &msg[i]);
- i = nl + 1;
- }
- }
- }
- }
-
- // Abort if necessary.
- if (data_->GetSeverity() == FATAL) {
- Runtime::Abort();
- }
-}
-
-std::ostream& LogMessage::stream() {
- if (PrintDirectly(data_->GetSeverity())) {
- return std::cerr;
- }
- return data_->GetBuffer();
+#ifdef __ANDROID__
+#define INIT_LOGGING_DEFAULT_LOGGER android::base::LogdLogger()
+#else
+#define INIT_LOGGING_DEFAULT_LOGGER android::base::StderrLogger
+#endif
+ android::base::InitLogging(argv, INIT_LOGGING_DEFAULT_LOGGER, RuntimeAborter);
+#undef INIT_LOGGING_DEFAULT_LOGGER
}
#ifdef ART_TARGET_ANDROID
@@ -245,31 +106,14 @@
ANDROID_LOG_VERBOSE, ANDROID_LOG_DEBUG, ANDROID_LOG_INFO, ANDROID_LOG_WARN,
ANDROID_LOG_ERROR, ANDROID_LOG_FATAL, ANDROID_LOG_FATAL
};
-static_assert(arraysize(kLogSeverityToAndroidLogPriority) == INTERNAL_FATAL + 1,
+static_assert(arraysize(kLogSeverityToAndroidLogPriority) == ::android::base::FATAL + 1,
"Mismatch in size of kLogSeverityToAndroidLogPriority and values in LogSeverity");
#endif
-void LogMessage::LogLine(const char* file, unsigned int line, LogSeverity log_severity,
- const char* message) {
-#ifdef ART_TARGET_ANDROID
- const char* tag = ProgramInvocationShortName();
- int priority = kLogSeverityToAndroidLogPriority[static_cast<size_t>(log_severity)];
- if (priority == ANDROID_LOG_FATAL) {
- LOG_PRI(priority, tag, "%s:%u] %s", file, line, message);
- } else {
- LOG_PRI(priority, tag, "%s", message);
- }
-#else
- static const char* log_characters = "VDIWEFF";
- CHECK_EQ(strlen(log_characters), INTERNAL_FATAL + 1U);
- char severity = log_characters[log_severity];
- fprintf(stderr, "%s %c %5d %5d %s:%u] %s\n",
- ProgramInvocationShortName(), severity, getpid(), ::art::GetTid(), file, line, message);
-#endif
-}
-
-void LogMessage::LogLineLowStack(const char* file, unsigned int line, LogSeverity log_severity,
- const char* message) {
+void LogHelper::LogLineLowStack(const char* file,
+ unsigned int line,
+ LogSeverity log_severity,
+ const char* message) {
#ifdef ART_TARGET_ANDROID
// Use android_writeLog() to avoid stack-based buffers used by android_printLog().
const char* tag = ProgramInvocationShortName();
@@ -292,8 +136,9 @@
}
#else
static constexpr char kLogCharacters[] = { 'V', 'D', 'I', 'W', 'E', 'F', 'F' };
- static_assert(arraysize(kLogCharacters) == static_cast<size_t>(INTERNAL_FATAL) + 1,
- "Wrong character array size");
+ static_assert(
+ arraysize(kLogCharacters) == static_cast<size_t>(::android::base::FATAL) + 1,
+ "Wrong character array size");
const char* program_name = ProgramInvocationShortName();
TEMP_FAILURE_RETRY(write(STDERR_FILENO, program_name, strlen(program_name)));
@@ -310,13 +155,4 @@
#endif // ART_TARGET_ANDROID
}
-ScopedLogSeverity::ScopedLogSeverity(LogSeverity level) {
- old_ = gMinimumLogSeverity;
- gMinimumLogSeverity = level;
-}
-
-ScopedLogSeverity::~ScopedLogSeverity() {
- gMinimumLogSeverity = old_;
-}
-
} // namespace art
diff --git a/runtime/base/logging.h b/runtime/base/logging.h
index 185aa0e..5f84204 100644
--- a/runtime/base/logging.h
+++ b/runtime/base/logging.h
@@ -18,20 +18,16 @@
#define ART_RUNTIME_BASE_LOGGING_H_
#include <ostream>
+#include <sstream>
+#include "android-base/logging.h"
#include "base/macros.h"
namespace art {
-enum LogSeverity {
- VERBOSE,
- DEBUG,
- INFO,
- WARNING,
- ERROR,
- FATAL,
- INTERNAL_FATAL, // For Runtime::Abort.
-};
+// Make libbase's LogSeverity more easily available.
+using ::android::base::LogSeverity;
+using ::android::base::ScopedLogSeverity;
// The members of this struct are the valid arguments to VLOG and VLOG_IS_ON in code,
// and the "-verbose:" command line argument.
@@ -89,172 +85,28 @@
// hasn't been performed then just returns "art"
extern const char* ProgramInvocationShortName();
-// Logs a message to logcat on Android otherwise to stderr. If the severity is FATAL it also causes
-// an abort. For example: LOG(FATAL) << "We didn't expect to reach here";
-#define LOG(severity) ::art::LogMessage(__FILE__, __LINE__, severity, -1).stream()
+class LogHelper {
+ public:
+ // A logging helper for logging a single line. Can be used with little stack.
+ static void LogLineLowStack(const char* file,
+ unsigned int line,
+ android::base::LogSeverity severity,
+ const char* msg);
-// A variant of LOG that also logs the current errno value. To be used when library calls fail.
-#define PLOG(severity) ::art::LogMessage(__FILE__, __LINE__, severity, errno).stream()
-
-// Marker that code is yet to be implemented.
-#define UNIMPLEMENTED(level) LOG(level) << __PRETTY_FUNCTION__ << " unimplemented "
+ private:
+ DISALLOW_ALLOCATION();
+ DISALLOW_COPY_AND_ASSIGN(LogHelper);
+};
// Is verbose logging enabled for the given module? Where the module is defined in LogVerbosity.
#define VLOG_IS_ON(module) UNLIKELY(::art::gLogVerbosity.module)
// Variant of LOG that logs when verbose logging is enabled for a module. For example,
// VLOG(jni) << "A JNI operation was performed";
-#define VLOG(module) \
- if (VLOG_IS_ON(module)) \
- ::art::LogMessage(__FILE__, __LINE__, INFO, -1).stream()
+#define VLOG(module) if (VLOG_IS_ON(module)) LOG(INFO)
// Return the stream associated with logging for the given module.
-#define VLOG_STREAM(module) ::art::LogMessage(__FILE__, __LINE__, INFO, -1).stream()
-
-// Check whether condition x holds and LOG(FATAL) if not. The value of the expression x is only
-// evaluated once. Extra logging can be appended using << after. For example,
-// CHECK(false == true) results in a log message of "Check failed: false == true".
-#define CHECK(x) \
- if (UNLIKELY(!(x))) \
- ::art::LogMessage(__FILE__, __LINE__, ::art::FATAL, -1).stream() \
- << "Check failed: " #x << " "
-
-// Helper for CHECK_xx(x,y) macros.
-#define CHECK_OP(LHS, RHS, OP) \
- for (auto _values = ::art::MakeEagerEvaluator(LHS, RHS); \
- UNLIKELY(!(_values.lhs OP _values.rhs)); /* empty */) \
- ::art::LogMessage(__FILE__, __LINE__, ::art::FATAL, -1).stream() \
- << "Check failed: " << #LHS << " " << #OP << " " << #RHS \
- << " (" #LHS "=" << _values.lhs << ", " #RHS "=" << _values.rhs << ") "
-
-
-// Check whether a condition holds between x and y, LOG(FATAL) if not. The value of the expressions
-// x and y is evaluated once. Extra logging can be appended using << after. For example,
-// CHECK_NE(0 == 1, false) results in "Check failed: false != false (0==1=false, false=false) ".
-#define CHECK_EQ(x, y) CHECK_OP(x, y, ==)
-#define CHECK_NE(x, y) CHECK_OP(x, y, !=)
-#define CHECK_LE(x, y) CHECK_OP(x, y, <=)
-#define CHECK_LT(x, y) CHECK_OP(x, y, <)
-#define CHECK_GE(x, y) CHECK_OP(x, y, >=)
-#define CHECK_GT(x, y) CHECK_OP(x, y, >)
-
-// Helper for CHECK_STRxx(s1,s2) macros.
-#define CHECK_STROP(s1, s2, sense) \
- if (UNLIKELY((strcmp(s1, s2) == 0) != (sense))) \
- LOG(::art::FATAL) << "Check failed: " \
- << "\"" << (s1) << "\"" \
- << ((sense) ? " == " : " != ") \
- << "\"" << (s2) << "\""
-
-// Check for string (const char*) equality between s1 and s2, LOG(FATAL) if not.
-#define CHECK_STREQ(s1, s2) CHECK_STROP(s1, s2, true)
-#define CHECK_STRNE(s1, s2) CHECK_STROP(s1, s2, false)
-
-// Perform the pthread function call(args), LOG(FATAL) on error.
-#define CHECK_PTHREAD_CALL(call, args, what) \
- do { \
- int rc = call args; \
- if (rc != 0) { \
- errno = rc; \
- PLOG(::art::FATAL) << # call << " failed for " << (what); \
- } \
- } while (false)
-
-
-// DCHECKs are debug variants of CHECKs only enabled in debug builds. Generally CHECK should be
-// used unless profiling identifies a CHECK as being in performance critical code.
-#if defined(NDEBUG)
-static constexpr bool kEnableDChecks = false;
-#else
-static constexpr bool kEnableDChecks = true;
-#endif
-
-#define DCHECK(x) if (::art::kEnableDChecks) CHECK(x)
-#define DCHECK_EQ(x, y) if (::art::kEnableDChecks) CHECK_EQ(x, y)
-#define DCHECK_NE(x, y) if (::art::kEnableDChecks) CHECK_NE(x, y)
-#define DCHECK_LE(x, y) if (::art::kEnableDChecks) CHECK_LE(x, y)
-#define DCHECK_LT(x, y) if (::art::kEnableDChecks) CHECK_LT(x, y)
-#define DCHECK_GE(x, y) if (::art::kEnableDChecks) CHECK_GE(x, y)
-#define DCHECK_GT(x, y) if (::art::kEnableDChecks) CHECK_GT(x, y)
-#define DCHECK_STREQ(s1, s2) if (::art::kEnableDChecks) CHECK_STREQ(s1, s2)
-#define DCHECK_STRNE(s1, s2) if (::art::kEnableDChecks) CHECK_STRNE(s1, s2)
-
-// Temporary class created to evaluate the LHS and RHS, used with MakeEagerEvaluator to infer the
-// types of LHS and RHS.
-template <typename LHS, typename RHS>
-struct EagerEvaluator {
- constexpr EagerEvaluator(LHS l, RHS r) : lhs(l), rhs(r) { }
- LHS lhs;
- RHS rhs;
-};
-
-// Helper function for CHECK_xx.
-template <typename LHS, typename RHS>
-constexpr EagerEvaluator<LHS, RHS> MakeEagerEvaluator(LHS lhs, RHS rhs) {
- return EagerEvaluator<LHS, RHS>(lhs, rhs);
-}
-
-// Explicitly instantiate EagerEvalue for pointers so that char*s aren't treated as strings. To
-// compare strings use CHECK_STREQ and CHECK_STRNE. We rely on signed/unsigned warnings to
-// protect you against combinations not explicitly listed below.
-#define EAGER_PTR_EVALUATOR(T1, T2) \
- template <> struct EagerEvaluator<T1, T2> { \
- EagerEvaluator(T1 l, T2 r) \
- : lhs(reinterpret_cast<const void*>(l)), \
- rhs(reinterpret_cast<const void*>(r)) { } \
- const void* lhs; \
- const void* rhs; \
- }
-EAGER_PTR_EVALUATOR(const char*, const char*);
-EAGER_PTR_EVALUATOR(const char*, char*);
-EAGER_PTR_EVALUATOR(char*, const char*);
-EAGER_PTR_EVALUATOR(char*, char*);
-EAGER_PTR_EVALUATOR(const unsigned char*, const unsigned char*);
-EAGER_PTR_EVALUATOR(const unsigned char*, unsigned char*);
-EAGER_PTR_EVALUATOR(unsigned char*, const unsigned char*);
-EAGER_PTR_EVALUATOR(unsigned char*, unsigned char*);
-EAGER_PTR_EVALUATOR(const signed char*, const signed char*);
-EAGER_PTR_EVALUATOR(const signed char*, signed char*);
-EAGER_PTR_EVALUATOR(signed char*, const signed char*);
-EAGER_PTR_EVALUATOR(signed char*, signed char*);
-
-// Data for the log message, not stored in LogMessage to avoid increasing the stack size.
-class LogMessageData;
-
-// A LogMessage is a temporarily scoped object used by LOG and the unlikely part of a CHECK. The
-// destructor will abort if the severity is FATAL.
-class LogMessage {
- public:
- LogMessage(const char* file, unsigned int line, LogSeverity severity, int error);
-
- ~LogMessage(); // TODO: enable REQUIRES(!Locks::logging_lock_).
-
- // Returns the stream associated with the message, the LogMessage performs output when it goes
- // out of scope.
- std::ostream& stream();
-
- // The routine that performs the actual logging.
- static void LogLine(const char* file, unsigned int line, LogSeverity severity, const char* msg);
-
- // A variant of the above for use with little stack.
- static void LogLineLowStack(const char* file, unsigned int line, LogSeverity severity,
- const char* msg);
-
- private:
- const std::unique_ptr<LogMessageData> data_;
-
- DISALLOW_COPY_AND_ASSIGN(LogMessage);
-};
-
-// Allows to temporarily change the minimum severity level for logging.
-class ScopedLogSeverity {
- public:
- explicit ScopedLogSeverity(LogSeverity level);
- ~ScopedLogSeverity();
-
- private:
- LogSeverity old_;
-};
+#define VLOG_STREAM(module) LOG_STREAM(INFO)
} // namespace art
diff --git a/runtime/base/mutex.cc b/runtime/base/mutex.cc
index 43c38c4..9d56954 100644
--- a/runtime/base/mutex.cc
+++ b/runtime/base/mutex.cc
@@ -328,14 +328,20 @@
bool shutting_down = IsShuttingDown();
#if ART_USE_FUTEXES
if (state_.LoadRelaxed() != 0) {
- LOG(shutting_down ? WARNING : FATAL) << "destroying mutex with owner: " << exclusive_owner_;
+ LOG(shutting_down
+ ? ::android::base::WARNING
+ : ::android::base::FATAL) << "destroying mutex with owner: " << exclusive_owner_;
} else {
if (exclusive_owner_ != 0) {
- LOG(shutting_down ? WARNING : FATAL) << "unexpectedly found an owner on unlocked mutex "
+ LOG(shutting_down
+ ? ::android::base::WARNING
+ : ::android::base::FATAL) << "unexpectedly found an owner on unlocked mutex "
<< name_;
}
if (num_contenders_.LoadSequentiallyConsistent() != 0) {
- LOG(shutting_down ? WARNING : FATAL) << "unexpectedly found a contender on mutex " << name_;
+ LOG(shutting_down
+ ? ::android::base::WARNING
+ : ::android::base::FATAL) << "unexpectedly found a contender on mutex " << name_;
}
}
#else
@@ -346,7 +352,9 @@
errno = rc;
// TODO: should we just not log at all if shutting down? this could be the logging mutex!
MutexLock mu(Thread::Current(), *Locks::runtime_shutdown_lock_);
- PLOG(shutting_down ? WARNING : FATAL) << "pthread_mutex_destroy failed for " << name_;
+ PLOG(shutting_down
+ ? ::android::base::WARNING
+ : ::android::base::FATAL) << "pthread_mutex_destroy failed for " << name_;
}
#endif
}
@@ -480,9 +488,11 @@
if (this != Locks::logging_lock_) {
LOG(FATAL) << "Unexpected state_ in unlock " << cur_state << " for " << name_;
} else {
- LogMessage::LogLine(__FILE__, __LINE__, INTERNAL_FATAL,
- StringPrintf("Unexpected state_ %d in unlock for %s",
- cur_state, name_).c_str());
+ LogHelper::LogLineLowStack(__FILE__,
+ __LINE__,
+ ::android::base::FATAL_WITHOUT_ABORT,
+ StringPrintf("Unexpected state_ %d in unlock for %s",
+ cur_state, name_).c_str());
_exit(1);
}
}
@@ -762,7 +772,10 @@
if (num_waiters_!= 0) {
Runtime* runtime = Runtime::Current();
bool shutting_down = runtime == nullptr || runtime->IsShuttingDown(Thread::Current());
- LOG(shutting_down ? WARNING : FATAL) << "ConditionVariable::~ConditionVariable for " << name_
+ LOG(shutting_down
+ ? ::android::base::WARNING
+ : ::android::base::FATAL)
+ << "ConditionVariable::~ConditionVariable for " << name_
<< " called with " << num_waiters_ << " waiters.";
}
#else
@@ -774,7 +787,9 @@
MutexLock mu(Thread::Current(), *Locks::runtime_shutdown_lock_);
Runtime* runtime = Runtime::Current();
bool shutting_down = (runtime == nullptr) || runtime->IsShuttingDownLocked();
- PLOG(shutting_down ? WARNING : FATAL) << "pthread_cond_destroy failed for " << name_;
+ PLOG(shutting_down
+ ? ::android::base::WARNING
+ : ::android::base::FATAL) << "pthread_cond_destroy failed for " << name_;
}
#endif
}
diff --git a/runtime/base/stl_util.h b/runtime/base/stl_util.h
index a4cf249..a53dcea 100644
--- a/runtime/base/stl_util.h
+++ b/runtime/base/stl_util.h
@@ -20,11 +20,7 @@
#include <algorithm>
#include <sstream>
-// This header is used in the disassembler with libbase's logging. Only include ART logging
-// when no other logging macros are available. b/15436106, b/31338270
-#ifndef CHECK
#include "base/logging.h"
-#endif
namespace art {
diff --git a/runtime/base/unix_file/fd_file.cc b/runtime/base/unix_file/fd_file.cc
index 48e3ceb..4498198 100644
--- a/runtime/base/unix_file/fd_file.cc
+++ b/runtime/base/unix_file/fd_file.cc
@@ -64,16 +64,16 @@
void FdFile::Destroy() {
if (kCheckSafeUsage && (guard_state_ < GuardState::kNoCheck)) {
if (guard_state_ < GuardState::kFlushed) {
- LOG(::art::ERROR) << "File " << file_path_ << " wasn't explicitly flushed before destruction.";
+ LOG(ERROR) << "File " << file_path_ << " wasn't explicitly flushed before destruction.";
}
if (guard_state_ < GuardState::kClosed) {
- LOG(::art::ERROR) << "File " << file_path_ << " wasn't explicitly closed before destruction.";
+ LOG(ERROR) << "File " << file_path_ << " wasn't explicitly closed before destruction.";
}
CHECK_GE(guard_state_, GuardState::kClosed);
}
if (auto_close_ && fd_ != -1) {
if (Close() != 0) {
- PLOG(::art::WARNING) << "Failed to close file " << file_path_;
+ PLOG(WARNING) << "Failed to close file " << file_path_;
}
}
}
@@ -104,7 +104,7 @@
if (kCheckSafeUsage) {
if (guard_state_ < GuardState::kNoCheck) {
if (warn_threshold < GuardState::kNoCheck && guard_state_ >= warn_threshold) {
- LOG(::art::ERROR) << warning;
+ LOG(ERROR) << warning;
}
guard_state_ = target;
}
@@ -117,7 +117,7 @@
if (guard_state_ < target) {
guard_state_ = target;
} else if (target < guard_state_) {
- LOG(::art::ERROR) << warning;
+ LOG(ERROR) << warning;
}
}
}
@@ -350,13 +350,13 @@
DCHECK(!read_only_mode_);
int flush_result = TEMP_FAILURE_RETRY(Flush());
if (flush_result != 0) {
- LOG(::art::ERROR) << "CloseOrErase failed while flushing a file.";
+ LOG(ERROR) << "CloseOrErase failed while flushing a file.";
Erase();
return flush_result;
}
int close_result = TEMP_FAILURE_RETRY(Close());
if (close_result != 0) {
- LOG(::art::ERROR) << "CloseOrErase failed while closing a file.";
+ LOG(ERROR) << "CloseOrErase failed while closing a file.";
Erase();
return close_result;
}
@@ -367,11 +367,11 @@
DCHECK(!read_only_mode_);
int flush_result = TEMP_FAILURE_RETRY(Flush());
if (flush_result != 0) {
- LOG(::art::ERROR) << "FlushClose failed while flushing a file.";
+ LOG(ERROR) << "FlushClose failed while flushing a file.";
}
int close_result = TEMP_FAILURE_RETRY(Close());
if (close_result != 0) {
- LOG(::art::ERROR) << "FlushClose failed while closing a file.";
+ LOG(ERROR) << "FlushClose failed while closing a file.";
}
return (flush_result != 0) ? flush_result : close_result;
}
@@ -383,7 +383,7 @@
bool FdFile::ClearContent() {
DCHECK(!read_only_mode_);
if (SetLength(0) < 0) {
- PLOG(art::ERROR) << "Failed to reset the length";
+ PLOG(ERROR) << "Failed to reset the length";
return false;
}
return ResetOffset();
@@ -393,7 +393,7 @@
DCHECK(!read_only_mode_);
off_t rc = TEMP_FAILURE_RETRY(lseek(fd_, 0, SEEK_SET));
if (rc == static_cast<off_t>(-1)) {
- PLOG(art::ERROR) << "Failed to reset the offset";
+ PLOG(ERROR) << "Failed to reset the offset";
return false;
}
return true;
diff --git a/runtime/check_jni.cc b/runtime/check_jni.cc
index 6683f13..a980535 100644
--- a/runtime/check_jni.cc
+++ b/runtime/check_jni.cc
@@ -275,7 +275,7 @@
return false;
}
if (!Runtime::Current()->GetHeap()->IsValidObjectAddress(o)) {
- Runtime::Current()->GetHeap()->DumpSpaces(LOG(ERROR));
+ Runtime::Current()->GetHeap()->DumpSpaces(LOG_STREAM(ERROR));
AbortF("field operation on invalid %s: %p",
ToStr<IndirectRefKind>(GetIndirectRefKind(java_object)).c_str(),
java_object);
@@ -783,7 +783,7 @@
}
if (!Runtime::Current()->GetHeap()->IsValidObjectAddress(obj)) {
- Runtime::Current()->GetHeap()->DumpSpaces(LOG(ERROR));
+ Runtime::Current()->GetHeap()->DumpSpaces(LOG_STREAM(ERROR));
AbortF("%s is an invalid %s: %p (%p)",
what, ToStr<IndirectRefKind>(GetIndirectRefKind(java_object)).c_str(),
java_object, obj);
@@ -1109,7 +1109,7 @@
mirror::Array* a = soa.Decode<mirror::Array*>(java_array);
if (UNLIKELY(!Runtime::Current()->GetHeap()->IsValidObjectAddress(a))) {
- Runtime::Current()->GetHeap()->DumpSpaces(LOG(ERROR));
+ Runtime::Current()->GetHeap()->DumpSpaces(LOG_STREAM(ERROR));
AbortF("jarray is an invalid %s: %p (%p)",
ToStr<IndirectRefKind>(GetIndirectRefKind(java_array)).c_str(),
java_array, a);
@@ -1146,7 +1146,7 @@
ArtField* f = soa.DecodeField(fid);
// TODO: Better check here.
if (!Runtime::Current()->GetHeap()->IsValidObjectAddress(f->GetDeclaringClass())) {
- Runtime::Current()->GetHeap()->DumpSpaces(LOG(ERROR));
+ Runtime::Current()->GetHeap()->DumpSpaces(LOG_STREAM(ERROR));
AbortF("invalid jfieldID: %p", fid);
return nullptr;
}
@@ -1162,7 +1162,7 @@
ArtMethod* m = soa.DecodeMethod(mid);
// TODO: Better check here.
if (!Runtime::Current()->GetHeap()->IsValidObjectAddress(m->GetDeclaringClass())) {
- Runtime::Current()->GetHeap()->DumpSpaces(LOG(ERROR));
+ Runtime::Current()->GetHeap()->DumpSpaces(LOG_STREAM(ERROR));
AbortF("invalid jmethodID: %p", mid);
return nullptr;
}
diff --git a/runtime/class_linker-inl.h b/runtime/class_linker-inl.h
index caabcde..d5b3090 100644
--- a/runtime/class_linker-inl.h
+++ b/runtime/class_linker-inl.h
@@ -70,6 +70,7 @@
mirror::StringDexCachePair::LookupString(declaring_class->GetDexCacheStrings(),
string_idx,
mirror::DexCache::kDexCacheStringCacheSize).Read();
+ Thread::PoisonObjectPointersIfDebug();
if (UNLIKELY(string == nullptr)) {
StackHandleScope<1> hs(Thread::Current());
Handle<mirror::DexCache> dex_cache(hs.NewHandle(declaring_class->GetDexCache()));
@@ -84,6 +85,7 @@
inline mirror::Class* ClassLinker::ResolveType(uint16_t type_idx, ArtMethod* referrer) {
mirror::Class* resolved_type = referrer->GetDexCacheResolvedType(type_idx, image_pointer_size_);
+ Thread::PoisonObjectPointersIfDebug();
if (UNLIKELY(resolved_type == nullptr)) {
mirror::Class* declaring_class = referrer->GetDeclaringClass();
StackHandleScope<2> hs(Thread::Current());
@@ -101,6 +103,7 @@
mirror::Class* declaring_class = referrer->GetDeclaringClass();
mirror::DexCache* dex_cache_ptr = declaring_class->GetDexCache();
mirror::Class* resolved_type = dex_cache_ptr->GetResolvedType(type_idx);
+ Thread::PoisonObjectPointersIfDebug();
if (UNLIKELY(resolved_type == nullptr)) {
StackHandleScope<2> hs(Thread::Current());
Handle<mirror::DexCache> dex_cache(hs.NewHandle(dex_cache_ptr));
@@ -148,6 +151,7 @@
ArtMethod* referrer,
InvokeType type) {
ArtMethod* resolved_method = GetResolvedMethod(method_idx, referrer);
+ Thread::PoisonObjectPointersIfDebug();
if (UNLIKELY(resolved_method == nullptr)) {
mirror::Class* declaring_class = referrer->GetDeclaringClass();
StackHandleScope<2> hs(self);
@@ -179,6 +183,7 @@
bool is_static) {
mirror::Class* declaring_class = referrer->GetDeclaringClass();
ArtField* resolved_field = GetResolvedField(field_idx, declaring_class);
+ Thread::PoisonObjectPointersIfDebug();
if (UNLIKELY(resolved_field == nullptr)) {
StackHandleScope<2> hs(Thread::Current());
Handle<mirror::DexCache> dex_cache(hs.NewHandle(declaring_class->GetDexCache()));
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 845e39a..48550f3 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -56,6 +56,8 @@
#include "gc/space/image_space.h"
#include "handle_scope-inl.h"
#include "image-inl.h"
+#include "imt_conflict_table.h"
+#include "imtable-inl.h"
#include "intern_table.h"
#include "interpreter/interpreter.h"
#include "jit/jit.h"
@@ -2167,6 +2169,7 @@
const char* descriptor,
mirror::Class* klass) {
DCHECK(klass != nullptr);
+ self->PoisonObjectPointers();
// For temporary classes we must wait for them to be retired.
if (init_done_ && klass->IsTemp()) {
@@ -2378,6 +2381,7 @@
DCHECK_NE(*descriptor, '\0') << "descriptor is empty string";
DCHECK(self != nullptr);
self->AssertNoPendingException();
+ self->PoisonObjectPointers(); // For DefineClass, CreateArrayClass, etc...
if (descriptor[1] == '\0') {
// only the descriptors of primitive types should be 1 character long, also avoid class lookup
// for primitive classes that aren't backed by dex files.
@@ -6267,7 +6271,7 @@
// or interface methods in the IMT here they will not create extra conflicts since we compare
// names and signatures in SetIMTRef.
ArtMethod* interface_method = interface->GetVirtualMethod(j, image_pointer_size_);
- const uint32_t imt_index = interface_method->GetImtIndex();
+ const uint32_t imt_index = ImTable::GetImtIndex(interface_method);
// There is only any conflicts if all of the interface methods for an IMT slot don't have
// the same implementation method, keep track of this to avoid creating a conflict table in
@@ -6321,7 +6325,7 @@
}
DCHECK(implementation_method != nullptr);
ArtMethod* interface_method = interface->GetVirtualMethod(j, image_pointer_size_);
- const uint32_t imt_index = interface_method->GetImtIndex();
+ const uint32_t imt_index = ImTable::GetImtIndex(interface_method);
if (!imt[imt_index]->IsRuntimeMethod() ||
imt[imt_index] == unimplemented_method ||
imt[imt_index] == imt_conflict_method) {
@@ -6780,7 +6784,7 @@
auto* interface_method = iftable->GetInterface(i)->GetVirtualMethod(j, image_pointer_size_);
MethodNameAndSignatureComparator interface_name_comparator(
interface_method->GetInterfaceMethodIfProxy(image_pointer_size_));
- uint32_t imt_index = interface_method->GetImtIndex();
+ uint32_t imt_index = ImTable::GetImtIndex(interface_method);
ArtMethod** imt_ptr = &out_imt[imt_index];
// For each method listed in the interface's method list, find the
// matching method in our class's method list. We want to favor the
@@ -7523,6 +7527,7 @@
Handle<mirror::DexCache> dex_cache) {
DCHECK(dex_cache.Get() != nullptr);
mirror::String* resolved = dex_cache->GetResolvedString(string_idx);
+ Thread::PoisonObjectPointersIfDebug();
if (resolved != nullptr) {
return resolved;
}
@@ -7565,6 +7570,7 @@
Handle<mirror::ClassLoader> class_loader) {
DCHECK(dex_cache.Get() != nullptr);
mirror::Class* resolved = dex_cache->GetResolvedType(type_idx);
+ Thread::PoisonObjectPointersIfDebug();
if (resolved == nullptr) {
Thread* self = Thread::Current();
const char* descriptor = dex_file.StringByTypeIdx(type_idx);
@@ -7603,6 +7609,7 @@
DCHECK(dex_cache.Get() != nullptr);
// Check for hit in the dex cache.
ArtMethod* resolved = dex_cache->GetResolvedMethod(method_idx, image_pointer_size_);
+ Thread::PoisonObjectPointersIfDebug();
if (resolved != nullptr && !resolved->IsRuntimeMethod()) {
DCHECK(resolved->GetDeclaringClassUnchecked() != nullptr) << resolved->GetDexMethodIndex();
if (kResolveMode == ClassLinker::kForceICCECheck) {
@@ -7806,6 +7813,7 @@
Handle<mirror::DexCache> dex_cache,
Handle<mirror::ClassLoader> class_loader) {
ArtMethod* resolved = dex_cache->GetResolvedMethod(method_idx, image_pointer_size_);
+ Thread::PoisonObjectPointersIfDebug();
if (resolved != nullptr && !resolved->IsRuntimeMethod()) {
DCHECK(resolved->GetDeclaringClassUnchecked() != nullptr) << resolved->GetDexMethodIndex();
return resolved;
@@ -7838,6 +7846,7 @@
bool is_static) {
DCHECK(dex_cache.Get() != nullptr);
ArtField* resolved = dex_cache->GetResolvedField(field_idx, image_pointer_size_);
+ Thread::PoisonObjectPointersIfDebug();
if (resolved != nullptr) {
return resolved;
}
@@ -7880,6 +7889,7 @@
Handle<mirror::ClassLoader> class_loader) {
DCHECK(dex_cache.Get() != nullptr);
ArtField* resolved = dex_cache->GetResolvedField(field_idx, image_pointer_size_);
+ Thread::PoisonObjectPointersIfDebug();
if (resolved != nullptr) {
return resolved;
}
@@ -7920,7 +7930,7 @@
explicit DumpClassVisitor(int flags) : flags_(flags) {}
bool operator()(mirror::Class* klass) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) {
- klass->DumpClass(LOG(ERROR), flags_);
+ klass->DumpClass(LOG_STREAM(ERROR), flags_);
return true;
}
diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc
index 8a48604..11722b2 100644
--- a/runtime/common_runtime_test.cc
+++ b/runtime/common_runtime_test.cc
@@ -58,7 +58,7 @@
setenv("ANDROID_LOG_TAGS", "*:e", 1);
art::InitLogging(argv);
- LOG(::art::INFO) << "Running main() from common_runtime_test.cc...";
+ LOG(INFO) << "Running main() from common_runtime_test.cc...";
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
diff --git a/runtime/dex_file_annotations.cc b/runtime/dex_file_annotations.cc
index c6c87fd..789a5bd 100644
--- a/runtime/dex_file_annotations.cc
+++ b/runtime/dex_file_annotations.cc
@@ -572,7 +572,7 @@
*annotation_ptr = annotation;
if (result_style == DexFile::kAllObjects && primitive_type != Primitive::kPrimVoid) {
- element_object = BoxPrimitive(primitive_type, annotation_value->value_);
+ element_object = BoxPrimitive(primitive_type, annotation_value->value_).Decode();
set_object = true;
}
@@ -1027,6 +1027,66 @@
annotation_class);
}
+bool GetParametersMetadataForMethod(ArtMethod* method,
+ MutableHandle<mirror::ObjectArray<mirror::String>>* names,
+ MutableHandle<mirror::IntArray>* access_flags) {
+ const DexFile::AnnotationSetItem::AnnotationSetItem* annotation_set =
+ FindAnnotationSetForMethod(method);
+ if (annotation_set == nullptr) {
+ return false;
+ }
+
+ const DexFile* dex_file = method->GetDexFile();
+ const DexFile::AnnotationItem* annotation_item =
+ SearchAnnotationSet(*dex_file,
+ annotation_set,
+ "Ldalvik/annotation/MethodParameters;",
+ DexFile::kDexVisibilitySystem);
+ if (annotation_item == nullptr) {
+ return false;
+ }
+
+ StackHandleScope<5> hs(Thread::Current());
+
+ // Extract the parameters' names String[].
+ mirror::Class* string_class = mirror::String::GetJavaLangString();
+ Handle<mirror::Class> string_array_class(hs.NewHandle(
+ Runtime::Current()->GetClassLinker()->FindArrayClass(Thread::Current(), &string_class)));
+ if (UNLIKELY(string_array_class.Get() == nullptr)) {
+ return false;
+ }
+
+ Handle<mirror::Class> klass = hs.NewHandle(method->GetDeclaringClass());
+ Handle<mirror::Object> names_obj =
+ hs.NewHandle(GetAnnotationValue(klass,
+ annotation_item,
+ "names",
+ string_array_class,
+ DexFile::kDexAnnotationArray));
+ if (names_obj.Get() == nullptr) {
+ return false;
+ }
+
+ // Extract the parameters' access flags int[].
+ Handle<mirror::Class> int_array_class(hs.NewHandle(mirror::IntArray::GetArrayClass()));
+ if (UNLIKELY(int_array_class.Get() == nullptr)) {
+ return false;
+ }
+ Handle<mirror::Object> access_flags_obj =
+ hs.NewHandle(GetAnnotationValue(klass,
+ annotation_item,
+ "accessFlags",
+ int_array_class,
+ DexFile::kDexAnnotationArray));
+ if (access_flags_obj.Get() == nullptr) {
+ return false;
+ }
+
+ names->Assign(names_obj.Get()->AsObjectArray<mirror::String>());
+ access_flags->Assign(access_flags_obj.Get()->AsIntArray());
+ return true;
+}
+
mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForMethod(ArtMethod* method) {
const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForMethod(method);
if (annotation_set == nullptr) {
diff --git a/runtime/dex_file_annotations.h b/runtime/dex_file_annotations.h
index 7b4e856..c66c5bd 100644
--- a/runtime/dex_file_annotations.h
+++ b/runtime/dex_file_annotations.h
@@ -30,6 +30,7 @@
class ArtField;
class ArtMethod;
class ClassLinker;
+template<class T> class MutableHandle;
namespace annotations {
@@ -58,6 +59,10 @@
uint32_t parameter_idx,
Handle<mirror::Class> annotation_class)
REQUIRES_SHARED(Locks::mutator_lock_);
+bool GetParametersMetadataForMethod(ArtMethod* method,
+ MutableHandle<mirror::ObjectArray<mirror::String>>* names,
+ MutableHandle<mirror::IntArray>* access_flags)
+ REQUIRES_SHARED(Locks::mutator_lock_);
mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForMethod(ArtMethod* method)
REQUIRES_SHARED(Locks::mutator_lock_);
bool IsMethodAnnotationPresent(ArtMethod* method, Handle<mirror::Class> annotation_class,
diff --git a/runtime/entrypoints/entrypoint_utils-inl.h b/runtime/entrypoints/entrypoint_utils-inl.h
index 14110c2..99b8805 100644
--- a/runtime/entrypoints/entrypoint_utils-inl.h
+++ b/runtime/entrypoints/entrypoint_utils-inl.h
@@ -26,6 +26,8 @@
#include "dex_file.h"
#include "entrypoints/quick/callee_save_frame.h"
#include "handle_scope-inl.h"
+#include "imt_conflict_table.h"
+#include "imtable-inl.h"
#include "indirect_reference_table.h"
#include "invoke_type.h"
#include "jni_internal.h"
@@ -612,7 +614,7 @@
UNREACHABLE();
}
case kInterface: {
- uint32_t imt_index = resolved_method->GetImtIndex();
+ uint32_t imt_index = ImTable::GetImtIndex(resolved_method);
PointerSize pointer_size = class_linker->GetImagePointerSize();
ArtMethod* imt_method = (*this_object)->GetClass()->GetImt(pointer_size)->
Get(imt_index, pointer_size);
diff --git a/runtime/entrypoints/entrypoint_utils.cc b/runtime/entrypoints/entrypoint_utils.cc
index fd9ffbd..bfa2b69 100644
--- a/runtime/entrypoints/entrypoint_utils.cc
+++ b/runtime/entrypoints/entrypoint_utils.cc
@@ -160,7 +160,7 @@
} else {
JValue jv;
jv.SetJ(args.at(i).j);
- mirror::Object* val = BoxPrimitive(Primitive::GetType(shorty[i + 1]), jv);
+ mirror::Object* val = BoxPrimitive(Primitive::GetType(shorty[i + 1]), jv).Decode();
if (val == nullptr) {
CHECK(soa.Self()->IsExceptionPending());
return zero;
diff --git a/runtime/entrypoints/quick/quick_deoptimization_entrypoints.cc b/runtime/entrypoints/quick/quick_deoptimization_entrypoints.cc
index 5b9d03b..343343f 100644
--- a/runtime/entrypoints/quick/quick_deoptimization_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_deoptimization_entrypoints.cc
@@ -36,7 +36,7 @@
// specialized visitor that will show whether a method is Quick or Shadow.
} else {
LOG(INFO) << "Deopting:";
- self->Dump(LOG(INFO));
+ self->Dump(LOG_STREAM(INFO));
}
}
diff --git a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
index fcbd834..cfd948e 100644
--- a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
@@ -23,6 +23,8 @@
#include "entrypoints/entrypoint_utils-inl.h"
#include "entrypoints/runtime_asm_entrypoints.h"
#include "gc/accounting/card_table-inl.h"
+#include "imt_conflict_table.h"
+#include "imtable-inl.h"
#include "interpreter/interpreter.h"
#include "linear_alloc.h"
#include "method_reference.h"
@@ -2239,7 +2241,8 @@
if (LIKELY(interface_method->GetDexMethodIndex() != DexFile::kDexNoIndex)) {
// If the dex cache already resolved the interface method, look whether we have
// a match in the ImtConflictTable.
- ArtMethod* conflict_method = imt->Get(interface_method->GetImtIndex(), kRuntimePointerSize);
+ ArtMethod* conflict_method = imt->Get(ImTable::GetImtIndex(interface_method),
+ kRuntimePointerSize);
if (LIKELY(conflict_method->IsRuntimeMethod())) {
ImtConflictTable* current_table = conflict_method->GetImtConflictTable(kRuntimePointerSize);
DCHECK(current_table != nullptr);
@@ -2291,7 +2294,7 @@
// We arrive here if we have found an implementation, and it is not in the ImtConflictTable.
// We create a new table with the new pair { interface_method, method }.
- uint32_t imt_index = interface_method->GetImtIndex();
+ uint32_t imt_index = ImTable::GetImtIndex(interface_method);
ArtMethod* conflict_method = imt->Get(imt_index, kRuntimePointerSize);
if (conflict_method->IsRuntimeMethod()) {
ArtMethod* new_conflict_method = Runtime::Current()->GetClassLinker()->AddMethodToConflictTable(
diff --git a/runtime/fault_handler.cc b/runtime/fault_handler.cc
index f86921c..f9345b6 100644
--- a/runtime/fault_handler.cc
+++ b/runtime/fault_handler.cc
@@ -438,7 +438,7 @@
// above.
abort();
#endif
- self->DumpJavaStack(LOG(ERROR));
+ self->DumpJavaStack(LOG_STREAM(ERROR));
}
return false; // Return false since we want to propagate the fault to the main signal handler.
diff --git a/runtime/gc/accounting/mod_union_table.cc b/runtime/gc/accounting/mod_union_table.cc
index 24a2c17..3b6750e 100644
--- a/runtime/gc/accounting/mod_union_table.cc
+++ b/runtime/gc/accounting/mod_union_table.cc
@@ -283,7 +283,7 @@
<< from_space->GetGcRetentionPolicy();
LOG(INFO) << "ToSpace " << to_space->GetName() << " type "
<< to_space->GetGcRetentionPolicy();
- heap->DumpSpaces(LOG(INFO));
+ heap->DumpSpaces(LOG_STREAM(INFO));
LOG(FATAL) << "FATAL ERROR";
}
}
diff --git a/runtime/gc/allocator/dlmalloc.cc b/runtime/gc/allocator/dlmalloc.cc
index dc4e312..0c84224 100644
--- a/runtime/gc/allocator/dlmalloc.cc
+++ b/runtime/gc/allocator/dlmalloc.cc
@@ -37,6 +37,9 @@
#pragma GCC diagnostic ignored "-Wempty-body"
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#include "../../../external/dlmalloc/malloc.c"
+// Note: malloc.c uses a DEBUG define to drive debug code. This interferes with the DEBUG severity
+// of libbase, so undefine it now.
+#undef DEBUG
#pragma GCC diagnostic pop
static void* art_heap_morecore(void* m, intptr_t increment) {
@@ -44,11 +47,11 @@
}
static void art_heap_corruption(const char* function) {
- LOG(::art::FATAL) << "Corrupt heap detected in: " << function;
+ LOG(FATAL) << "Corrupt heap detected in: " << function;
}
static void art_heap_usage_error(const char* function, void* p) {
- LOG(::art::FATAL) << "Incorrect use of function '" << function << "' argument " << p
+ LOG(FATAL) << "Incorrect use of function '" << function << "' argument " << p
<< " not expected";
}
@@ -69,7 +72,7 @@
int rc = madvise(start, length, MADV_DONTNEED);
if (UNLIKELY(rc != 0)) {
errno = rc;
- PLOG(::art::FATAL) << "madvise failed during heap trimming";
+ PLOG(FATAL) << "madvise failed during heap trimming";
}
size_t* reclaimed = reinterpret_cast<size_t*>(arg);
*reclaimed += length;
diff --git a/runtime/gc/collector/concurrent_copying.cc b/runtime/gc/collector/concurrent_copying.cc
index 2750fea..ab8942a 100644
--- a/runtime/gc/collector/concurrent_copying.cc
+++ b/runtime/gc/collector/concurrent_copying.cc
@@ -430,7 +430,7 @@
TimingLogger::ScopedTiming split("FlipThreadRoots", GetTimings());
if (kVerboseMode) {
LOG(INFO) << "time=" << region_space_->Time();
- region_space_->DumpNonFreeRegions(LOG(INFO));
+ region_space_->DumpNonFreeRegions(LOG_STREAM(INFO));
}
Thread* self = Thread::Current();
Locks::mutator_lock_->AssertNotHeld(self);
@@ -447,7 +447,7 @@
QuasiAtomic::ThreadFenceForConstructor();
if (kVerboseMode) {
LOG(INFO) << "time=" << region_space_->Time();
- region_space_->DumpNonFreeRegions(LOG(INFO));
+ region_space_->DumpNonFreeRegions(LOG_STREAM(INFO));
LOG(INFO) << "GC end of FlipThreadRoots";
}
}
@@ -1622,7 +1622,7 @@
if (obj != nullptr) {
LogFromSpaceRefHolder(obj, offset);
}
- ref->GetLockWord(false).Dump(LOG(INTERNAL_FATAL));
+ ref->GetLockWord(false).Dump(LOG_STREAM(FATAL_WITHOUT_ABORT));
CHECK(false) << "Found from-space ref " << ref << " " << PrettyTypeOf(ref);
} else {
AssertToSpaceInvariantInNonMovingSpace(obj, ref);
@@ -1645,13 +1645,13 @@
template <class MirrorType>
void VisitRoot(mirror::Object** root)
REQUIRES_SHARED(Locks::mutator_lock_) {
- LOG(INTERNAL_FATAL) << "root=" << root << " ref=" << *root;
+ LOG(FATAL_WITHOUT_ABORT) << "root=" << root << " ref=" << *root;
}
template <class MirrorType>
void VisitRoot(mirror::CompressedReference<MirrorType>* root)
REQUIRES_SHARED(Locks::mutator_lock_) {
- LOG(INTERNAL_FATAL) << "root=" << root << " ref=" << root->AsMirrorPtr();
+ LOG(FATAL_WITHOUT_ABORT) << "root=" << root << " ref=" << root->AsMirrorPtr();
}
};
@@ -1670,19 +1670,19 @@
// No info.
} else if (gc_root_source->HasArtField()) {
ArtField* field = gc_root_source->GetArtField();
- LOG(INTERNAL_FATAL) << "gc root in field " << field << " " << PrettyField(field);
+ LOG(FATAL_WITHOUT_ABORT) << "gc root in field " << field << " " << PrettyField(field);
RootPrinter root_printer;
field->VisitRoots(root_printer);
} else if (gc_root_source->HasArtMethod()) {
ArtMethod* method = gc_root_source->GetArtMethod();
- LOG(INTERNAL_FATAL) << "gc root in method " << method << " " << PrettyMethod(method);
+ LOG(FATAL_WITHOUT_ABORT) << "gc root in method " << method << " " << PrettyMethod(method);
RootPrinter root_printer;
method->VisitRoots(root_printer, kRuntimePointerSize);
}
- ref->GetLockWord(false).Dump(LOG(INTERNAL_FATAL));
- region_space_->DumpNonFreeRegions(LOG(INTERNAL_FATAL));
- PrintFileToLog("/proc/self/maps", LogSeverity::INTERNAL_FATAL);
- MemMap::DumpMaps(LOG(INTERNAL_FATAL), true);
+ ref->GetLockWord(false).Dump(LOG_STREAM(FATAL_WITHOUT_ABORT));
+ region_space_->DumpNonFreeRegions(LOG_STREAM(FATAL_WITHOUT_ABORT));
+ PrintFileToLog("/proc/self/maps", LogSeverity::FATAL_WITHOUT_ABORT);
+ MemMap::DumpMaps(LOG_STREAM(FATAL_WITHOUT_ABORT), true);
CHECK(false) << "Found from-space ref " << ref << " " << PrettyTypeOf(ref);
} else {
AssertToSpaceInvariantInNonMovingSpace(nullptr, ref);
diff --git a/runtime/gc/collector/mark_compact.cc b/runtime/gc/collector/mark_compact.cc
index d866106..6d2f009 100644
--- a/runtime/gc/collector/mark_compact.cc
+++ b/runtime/gc/collector/mark_compact.cc
@@ -139,7 +139,7 @@
REQUIRES_SHARED(Locks::mutator_lock_) {
// Marking a large object, make sure its aligned as a sanity check.
if (!IsAligned<kPageSize>(ref)) {
- Runtime::Current()->GetHeap()->DumpSpaces(LOG(ERROR));
+ Runtime::Current()->GetHeap()->DumpSpaces(LOG_STREAM(ERROR));
LOG(FATAL) << ref;
}
};
diff --git a/runtime/gc/collector/mark_sweep.cc b/runtime/gc/collector/mark_sweep.cc
index cbc4dc1..ad3dd33 100644
--- a/runtime/gc/collector/mark_sweep.cc
+++ b/runtime/gc/collector/mark_sweep.cc
@@ -413,11 +413,11 @@
if (UNLIKELY(obj == nullptr || !IsAligned<kPageSize>(obj) ||
(kIsDebugBuild && large_object_space != nullptr &&
!large_object_space->Contains(obj)))) {
- LOG(INTERNAL_FATAL) << "Tried to mark " << obj << " not contained by any spaces";
+ LOG(FATAL_WITHOUT_ABORT) << "Tried to mark " << obj << " not contained by any spaces";
if (holder_ != nullptr) {
size_t holder_size = holder_->SizeOf();
ArtField* field = holder_->FindFieldByOffset(offset_);
- LOG(INTERNAL_FATAL) << "Field info: "
+ LOG(FATAL_WITHOUT_ABORT) << "Field info: "
<< " holder=" << holder_
<< " holder is "
<< (mark_sweep_->GetHeap()->IsLiveObjectLocked(holder_)
@@ -440,13 +440,13 @@
// Print the memory content of the holder.
for (size_t i = 0; i < holder_size / sizeof(uint32_t); ++i) {
uint32_t* p = reinterpret_cast<uint32_t*>(holder_);
- LOG(INTERNAL_FATAL) << &p[i] << ": " << "holder+" << (i * sizeof(uint32_t)) << " = "
+ LOG(FATAL_WITHOUT_ABORT) << &p[i] << ": " << "holder+" << (i * sizeof(uint32_t)) << " = "
<< std::hex << p[i];
}
}
- PrintFileToLog("/proc/self/maps", LogSeverity::INTERNAL_FATAL);
- MemMap::DumpMaps(LOG(INTERNAL_FATAL), true);
- LOG(INTERNAL_FATAL) << "Attempting see if it's a bad thread root";
+ PrintFileToLog("/proc/self/maps", LogSeverity::FATAL_WITHOUT_ABORT);
+ MemMap::DumpMaps(LOG_STREAM(FATAL_WITHOUT_ABORT), true);
+ LOG(FATAL_WITHOUT_ABORT) << "Attempting see if it's a bad thread root";
mark_sweep_->VerifySuspendedThreadRoots();
LOG(FATAL) << "Can't mark invalid object";
}
@@ -574,7 +574,7 @@
if (heap->GetLiveBitmap()->GetContinuousSpaceBitmap(root) == nullptr) {
space::LargeObjectSpace* large_object_space = heap->GetLargeObjectsSpace();
if (large_object_space != nullptr && !large_object_space->Contains(root)) {
- LOG(INTERNAL_FATAL) << "Found invalid root: " << root << " " << info;
+ LOG(FATAL_WITHOUT_ABORT) << "Found invalid root: " << root << " " << info;
}
}
}
diff --git a/runtime/gc/collector/semi_space.cc b/runtime/gc/collector/semi_space.cc
index 47e6ca3..2e97172 100644
--- a/runtime/gc/collector/semi_space.cc
+++ b/runtime/gc/collector/semi_space.cc
@@ -296,7 +296,7 @@
REQUIRES_SHARED(Locks::mutator_lock_) ALWAYS_INLINE {
mirror::Object* ref = obj->GetFieldObject<mirror::Object>(offset);
if (from_space_->HasAddress(ref)) {
- Runtime::Current()->GetHeap()->DumpObject(LOG(INFO), obj);
+ Runtime::Current()->GetHeap()->DumpObject(LOG_STREAM(INFO), obj);
LOG(FATAL) << ref << " found in from space";
}
}
diff --git a/runtime/gc/heap-inl.h b/runtime/gc/heap-inl.h
index b0ca18e..6d61c64 100644
--- a/runtime/gc/heap-inl.h
+++ b/runtime/gc/heap-inl.h
@@ -50,6 +50,7 @@
CHECK_EQ(self->GetState(), kRunnable);
self->AssertThreadSuspensionIsAllowable();
self->AssertNoPendingException();
+ self->PoisonObjectPointers();
}
// Need to check that we arent the large object allocator since the large object allocation code
// path this function. If we didn't check we would have an infinite loop.
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 11d4af8..4e6dd2b 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -630,7 +630,7 @@
bool no_gap = MemMap::CheckNoGaps(first_space->GetMemMap(), non_moving_space_->GetMemMap());
if (!no_gap) {
PrintFileToLog("/proc/self/maps", LogSeverity::ERROR);
- MemMap::DumpMaps(LOG(ERROR), true);
+ MemMap::DumpMaps(LOG_STREAM(ERROR), true);
LOG(FATAL) << "There's a gap between the image space and the non-moving space";
}
}
@@ -3157,14 +3157,14 @@
// Dump mod-union tables.
for (const auto& table_pair : mod_union_tables_) {
accounting::ModUnionTable* mod_union_table = table_pair.second;
- mod_union_table->Dump(LOG(ERROR) << mod_union_table->GetName() << ": ");
+ mod_union_table->Dump(LOG_STREAM(ERROR) << mod_union_table->GetName() << ": ");
}
// Dump remembered sets.
for (const auto& table_pair : remembered_sets_) {
accounting::RememberedSet* remembered_set = table_pair.second;
- remembered_set->Dump(LOG(ERROR) << remembered_set->GetName() << ": ");
+ remembered_set->Dump(LOG_STREAM(ERROR) << remembered_set->GetName() << ": ");
}
- DumpSpaces(LOG(ERROR));
+ DumpSpaces(LOG_STREAM(ERROR));
}
return visitor.GetFailureCount();
}
diff --git a/runtime/gc/reference_queue_test.cc b/runtime/gc/reference_queue_test.cc
index 35bf718..2a1635d 100644
--- a/runtime/gc/reference_queue_test.cc
+++ b/runtime/gc/reference_queue_test.cc
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <sstream>
+
#include "common_runtime_test.h"
#include "reference_queue.h"
#include "handle_scope-inl.h"
@@ -65,7 +67,9 @@
StackHandleScope<20> hs(self);
Mutex lock("Reference queue lock");
ReferenceQueue queue(&lock);
- queue.Dump(LOG(INFO));
+ std::ostringstream oss;
+ queue.Dump(oss);
+ LOG(INFO) << oss.str();
auto weak_ref_class = hs.NewHandle(
Runtime::Current()->GetClassLinker()->FindClass(self, "Ljava/lang/ref/WeakReference;",
ScopedNullHandle<mirror::ClassLoader>()));
@@ -78,10 +82,16 @@
ASSERT_TRUE(ref1.Get() != nullptr);
auto ref2(hs.NewHandle(finalizer_ref_class->AllocObject(self)->AsReference()));
ASSERT_TRUE(ref2.Get() != nullptr);
+
queue.EnqueueReference(ref1.Get());
- queue.Dump(LOG(INFO));
+ oss.str("");
+ queue.Dump(oss);
+ LOG(INFO) << oss.str();
+
queue.EnqueueReference(ref2.Get());
- queue.Dump(LOG(INFO));
+ oss.str("");
+ queue.Dump(oss);
+ LOG(INFO) << oss.str();
}
} // namespace gc
diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc
index 9c91732..a40e408 100644
--- a/runtime/gc/space/image_space.cc
+++ b/runtime/gc/space/image_space.cc
@@ -728,7 +728,7 @@
VLOG(image) << "ImageSpace::Init exiting " << *space.get();
if (VLOG_IS_ON(image)) {
- logger.Dump(LOG(INFO));
+ logger.Dump(LOG_STREAM(INFO));
}
return space;
}
@@ -1298,7 +1298,7 @@
}
}
if (VLOG_IS_ON(image)) {
- logger.Dump(LOG(INFO));
+ logger.Dump(LOG_STREAM(INFO));
}
return true;
}
diff --git a/runtime/gc/space/large_object_space.cc b/runtime/gc/space/large_object_space.cc
index 010f677..16d1f93 100644
--- a/runtime/gc/space/large_object_space.cc
+++ b/runtime/gc/space/large_object_space.cc
@@ -192,7 +192,7 @@
auto it = large_objects_.find(ptr);
if (UNLIKELY(it == large_objects_.end())) {
ScopedObjectAccess soa(self);
- Runtime::Current()->GetHeap()->DumpSpaces(LOG(INTERNAL_FATAL));
+ Runtime::Current()->GetHeap()->DumpSpaces(LOG_STREAM(FATAL_WITHOUT_ABORT));
LOG(FATAL) << "Attempted to free large object " << ptr << " which was not live";
}
MemMap* mem_map = it->second.mem_map;
diff --git a/runtime/gc/space/large_object_space_test.cc b/runtime/gc/space/large_object_space_test.cc
index ad38724..2544914 100644
--- a/runtime/gc/space/large_object_space_test.cc
+++ b/runtime/gc/space/large_object_space_test.cc
@@ -98,7 +98,9 @@
}
}
// Test that dump doesn't crash.
- los->Dump(LOG(INFO));
+ std::ostringstream oss;
+ los->Dump(oss);
+ LOG(INFO) << oss.str();
size_t bytes_allocated = 0, bytes_tl_bulk_allocated;
// Checks that the coalescing works.
diff --git a/runtime/gc/space/region_space.cc b/runtime/gc/space/region_space.cc
index e24741a..23cae7c 100644
--- a/runtime/gc/space/region_space.cc
+++ b/runtime/gc/space/region_space.cc
@@ -38,7 +38,7 @@
if (mem_map.get() == nullptr) {
LOG(ERROR) << "Failed to allocate pages for alloc space (" << name << ") of size "
<< PrettySize(capacity) << " with message " << error_msg;
- MemMap::DumpMaps(LOG(ERROR));
+ MemMap::DumpMaps(LOG_STREAM(ERROR));
return nullptr;
}
return new RegionSpace(name, mem_map.release());
diff --git a/runtime/handle.h b/runtime/handle.h
index d4c13d4..c41010a 100644
--- a/runtime/handle.h
+++ b/runtime/handle.h
@@ -23,6 +23,7 @@
#include "base/mutex.h"
#include "base/value_object.h"
#include "jni.h"
+#include "obj_ptr.h"
#include "stack_reference.h"
namespace art {
@@ -130,6 +131,14 @@
return old;
}
+ ALWAYS_INLINE T* Assign(ObjPtr<T> reference) REQUIRES_SHARED(Locks::mutator_lock_) {
+ StackReference<mirror::Object>* ref = Handle<T>::GetReference();
+ T* old = down_cast<T*>(ref->AsMirrorPtr());
+ ref->Assign(reference.Decode());
+ return old;
+ }
+
+
template<typename S>
explicit MutableHandle(const MutableHandle<S>& handle) REQUIRES_SHARED(Locks::mutator_lock_)
: Handle<T>(handle) {
diff --git a/runtime/image-inl.h b/runtime/image-inl.h
index 669649e..da18ae5 100644
--- a/runtime/image-inl.h
+++ b/runtime/image-inl.h
@@ -20,6 +20,7 @@
#include "image.h"
#include "art_method.h"
+#include "imt_conflict_table.h"
#include "imtable.h"
#include "read_barrier-inl.h"
diff --git a/runtime/imt_conflict_table.h b/runtime/imt_conflict_table.h
new file mode 100644
index 0000000..fdd10fe
--- /dev/null
+++ b/runtime/imt_conflict_table.h
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#ifndef ART_RUNTIME_IMT_CONFLICT_TABLE_H_
+#define ART_RUNTIME_IMT_CONFLICT_TABLE_H_
+
+#include <cstddef>
+
+#include "base/casts.h"
+#include "base/enums.h"
+#include "base/macros.h"
+
+namespace art {
+
+class ArtMethod;
+
+// Table to resolve IMT conflicts at runtime. The table is attached to
+// the jni entrypoint of IMT conflict ArtMethods.
+// The table contains a list of pairs of { interface_method, implementation_method }
+// with the last entry being null to make an assembly implementation of a lookup
+// faster.
+class ImtConflictTable {
+ enum MethodIndex {
+ kMethodInterface,
+ kMethodImplementation,
+ kMethodCount, // Number of elements in enum.
+ };
+
+ public:
+ // Build a new table copying `other` and adding the new entry formed of
+ // the pair { `interface_method`, `implementation_method` }
+ ImtConflictTable(ImtConflictTable* other,
+ ArtMethod* interface_method,
+ ArtMethod* implementation_method,
+ PointerSize pointer_size) {
+ const size_t count = other->NumEntries(pointer_size);
+ for (size_t i = 0; i < count; ++i) {
+ SetInterfaceMethod(i, pointer_size, other->GetInterfaceMethod(i, pointer_size));
+ SetImplementationMethod(i, pointer_size, other->GetImplementationMethod(i, pointer_size));
+ }
+ SetInterfaceMethod(count, pointer_size, interface_method);
+ SetImplementationMethod(count, pointer_size, implementation_method);
+ // Add the null marker.
+ SetInterfaceMethod(count + 1, pointer_size, nullptr);
+ SetImplementationMethod(count + 1, pointer_size, nullptr);
+ }
+
+ // num_entries excludes the header.
+ ImtConflictTable(size_t num_entries, PointerSize pointer_size) {
+ SetInterfaceMethod(num_entries, pointer_size, nullptr);
+ SetImplementationMethod(num_entries, pointer_size, nullptr);
+ }
+
+ // Set an entry at an index.
+ void SetInterfaceMethod(size_t index, PointerSize pointer_size, ArtMethod* method) {
+ SetMethod(index * kMethodCount + kMethodInterface, pointer_size, method);
+ }
+
+ void SetImplementationMethod(size_t index, PointerSize pointer_size, ArtMethod* method) {
+ SetMethod(index * kMethodCount + kMethodImplementation, pointer_size, method);
+ }
+
+ ArtMethod* GetInterfaceMethod(size_t index, PointerSize pointer_size) const {
+ return GetMethod(index * kMethodCount + kMethodInterface, pointer_size);
+ }
+
+ ArtMethod* GetImplementationMethod(size_t index, PointerSize pointer_size) const {
+ return GetMethod(index * kMethodCount + kMethodImplementation, pointer_size);
+ }
+
+ // Return true if two conflict tables are the same.
+ bool Equals(ImtConflictTable* other, PointerSize pointer_size) const {
+ size_t num = NumEntries(pointer_size);
+ if (num != other->NumEntries(pointer_size)) {
+ return false;
+ }
+ for (size_t i = 0; i < num; ++i) {
+ if (GetInterfaceMethod(i, pointer_size) != other->GetInterfaceMethod(i, pointer_size) ||
+ GetImplementationMethod(i, pointer_size) !=
+ other->GetImplementationMethod(i, pointer_size)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ // Visit all of the entries.
+ // NO_THREAD_SAFETY_ANALYSIS for calling with held locks. Visitor is passed a pair of ArtMethod*
+ // and also returns one. The order is <interface, implementation>.
+ template<typename Visitor>
+ void Visit(const Visitor& visitor, PointerSize pointer_size) NO_THREAD_SAFETY_ANALYSIS {
+ uint32_t table_index = 0;
+ for (;;) {
+ ArtMethod* interface_method = GetInterfaceMethod(table_index, pointer_size);
+ if (interface_method == nullptr) {
+ break;
+ }
+ ArtMethod* implementation_method = GetImplementationMethod(table_index, pointer_size);
+ auto input = std::make_pair(interface_method, implementation_method);
+ std::pair<ArtMethod*, ArtMethod*> updated = visitor(input);
+ if (input.first != updated.first) {
+ SetInterfaceMethod(table_index, pointer_size, updated.first);
+ }
+ if (input.second != updated.second) {
+ SetImplementationMethod(table_index, pointer_size, updated.second);
+ }
+ ++table_index;
+ }
+ }
+
+ // Lookup the implementation ArtMethod associated to `interface_method`. Return null
+ // if not found.
+ ArtMethod* Lookup(ArtMethod* interface_method, PointerSize pointer_size) const {
+ uint32_t table_index = 0;
+ for (;;) {
+ ArtMethod* current_interface_method = GetInterfaceMethod(table_index, pointer_size);
+ if (current_interface_method == nullptr) {
+ break;
+ }
+ if (current_interface_method == interface_method) {
+ return GetImplementationMethod(table_index, pointer_size);
+ }
+ ++table_index;
+ }
+ return nullptr;
+ }
+
+ // Compute the number of entries in this table.
+ size_t NumEntries(PointerSize pointer_size) const {
+ uint32_t table_index = 0;
+ while (GetInterfaceMethod(table_index, pointer_size) != nullptr) {
+ ++table_index;
+ }
+ return table_index;
+ }
+
+ // Compute the size in bytes taken by this table.
+ size_t ComputeSize(PointerSize pointer_size) const {
+ // Add the end marker.
+ return ComputeSize(NumEntries(pointer_size), pointer_size);
+ }
+
+ // Compute the size in bytes needed for copying the given `table` and add
+ // one more entry.
+ static size_t ComputeSizeWithOneMoreEntry(ImtConflictTable* table, PointerSize pointer_size) {
+ return table->ComputeSize(pointer_size) + EntrySize(pointer_size);
+ }
+
+ // Compute size with a fixed number of entries.
+ static size_t ComputeSize(size_t num_entries, PointerSize pointer_size) {
+ return (num_entries + 1) * EntrySize(pointer_size); // Add one for null terminator.
+ }
+
+ static size_t EntrySize(PointerSize pointer_size) {
+ return static_cast<size_t>(pointer_size) * static_cast<size_t>(kMethodCount);
+ }
+
+ private:
+ ArtMethod* GetMethod(size_t index, PointerSize pointer_size) const {
+ if (pointer_size == PointerSize::k64) {
+ return reinterpret_cast<ArtMethod*>(static_cast<uintptr_t>(data64_[index]));
+ } else {
+ return reinterpret_cast<ArtMethod*>(static_cast<uintptr_t>(data32_[index]));
+ }
+ }
+
+ void SetMethod(size_t index, PointerSize pointer_size, ArtMethod* method) {
+ if (pointer_size == PointerSize::k64) {
+ data64_[index] = dchecked_integral_cast<uint64_t>(reinterpret_cast<uintptr_t>(method));
+ } else {
+ data32_[index] = dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(method));
+ }
+ }
+
+ // Array of entries that the assembly stubs will iterate over. Note that this is
+ // not fixed size, and we allocate data prior to calling the constructor
+ // of ImtConflictTable.
+ union {
+ uint32_t data32_[0];
+ uint64_t data64_[0];
+ };
+
+ DISALLOW_COPY_AND_ASSIGN(ImtConflictTable);
+};
+
+} // namespace art
+
+#endif // ART_RUNTIME_IMT_CONFLICT_TABLE_H_
diff --git a/runtime/imtable-inl.h b/runtime/imtable-inl.h
new file mode 100644
index 0000000..0cb9b5e
--- /dev/null
+++ b/runtime/imtable-inl.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#ifndef ART_RUNTIME_IMTABLE_INL_H_
+#define ART_RUNTIME_IMTABLE_INL_H_
+
+#include "imtable.h"
+
+#include "art_method-inl.h"
+
+namespace art {
+
+inline uint32_t ImTable::GetBaseImtHash(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_) {
+ return method->GetDexMethodIndex();
+}
+
+inline uint32_t ImTable::GetImtIndex(ArtMethod* method) {
+ return GetBaseImtHash(method) % ImTable::kSize;
+}
+
+} // namespace art
+
+#endif // ART_RUNTIME_IMTABLE_INL_H_
+
diff --git a/runtime/imtable.h b/runtime/imtable.h
index 2416621..6df890d 100644
--- a/runtime/imtable.h
+++ b/runtime/imtable.h
@@ -21,9 +21,13 @@
#error IMT_SIZE not defined
#endif
+#include "base/enums.h"
+#include "base/macros.h"
+
namespace art {
class ArtMethod;
+class DexFile;
class ImTable {
public:
@@ -69,6 +73,19 @@
constexpr static size_t SizeInBytes(PointerSize pointer_size) {
return kSize * static_cast<size_t>(pointer_size);
}
+
+ // Converts a method to the base hash used in GetImtIndex.
+ ALWAYS_INLINE static inline uint32_t GetBaseImtHash(ArtMethod* method)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+ ALWAYS_INLINE static inline uint32_t GetBaseImtHash(const DexFile* dex_file, uint32_t method_idx)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+
+ // The (complete) hashing scheme to map an ArtMethod to a slot in the Interface Method Table
+ // (IMT).
+ ALWAYS_INLINE static inline uint32_t GetImtIndex(ArtMethod* method)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+ ALWAYS_INLINE static inline uint32_t GetImtIndex(const DexFile* dex_file, uint32_t method_idx)
+ REQUIRES_SHARED(Locks::mutator_lock_);
};
} // namespace art
diff --git a/runtime/indirect_reference_table.cc b/runtime/indirect_reference_table.cc
index 4f81b59..1f39a1e 100644
--- a/runtime/indirect_reference_table.cc
+++ b/runtime/indirect_reference_table.cc
@@ -188,7 +188,7 @@
ScopedObjectAccess soa(self);
LOG(WARNING) << "Attempt to remove non-JNI local reference, dumping thread";
if (kDumpStackOnNonLocalReference) {
- self->Dump(LOG(WARNING));
+ self->Dump(LOG_STREAM(WARNING));
}
}
return true;
diff --git a/runtime/interpreter/interpreter_common.cc b/runtime/interpreter/interpreter_common.cc
index 77c3f0f..5934f13 100644
--- a/runtime/interpreter/interpreter_common.cc
+++ b/runtime/interpreter/interpreter_common.cc
@@ -576,9 +576,7 @@
// Replace calls to String.<init> with equivalent StringFactory call.
if (UNLIKELY(called_method->GetDeclaringClass()->IsStringClass()
&& called_method->IsConstructor())) {
- ScopedObjectAccessUnchecked soa(self);
- jmethodID mid = soa.EncodeMethod(called_method);
- called_method = soa.DecodeMethod(WellKnownClasses::StringInitToStringFactoryMethodID(mid));
+ called_method = WellKnownClasses::StringInitToStringFactory(called_method);
string_init = true;
}
diff --git a/runtime/interpreter/mterp/mterp.cc b/runtime/interpreter/mterp/mterp.cc
index a8c7d15..cf8d4bd 100644
--- a/runtime/interpreter/mterp/mterp.cc
+++ b/runtime/interpreter/mterp/mterp.cc
@@ -38,8 +38,8 @@
int interp_size = (uintptr_t) artMterpAsmInstructionEnd -
(uintptr_t) artMterpAsmInstructionStart;
if ((interp_size == 0) || (interp_size != (art::kNumPackedOpcodes * width))) {
- LOG(art::FATAL) << "ERROR: unexpected asm interp size " << interp_size
- << "(did an instruction handler exceed " << width << " bytes?)";
+ LOG(FATAL) << "ERROR: unexpected asm interp size " << interp_size
+ << "(did an instruction handler exceed " << width << " bytes?)";
}
}
diff --git a/runtime/interpreter/unstarted_runtime.cc b/runtime/interpreter/unstarted_runtime.cc
index d505aea..98e358b 100644
--- a/runtime/interpreter/unstarted_runtime.cc
+++ b/runtime/interpreter/unstarted_runtime.cc
@@ -858,7 +858,7 @@
ArtMethod* init_method = h_real_to_string_class->FindDirectMethod(
"<init>", "()V", cl->GetImagePointerSize());
if (init_method == nullptr) {
- h_real_to_string_class->DumpClass(LOG(FATAL), mirror::Class::kDumpClassFullDetail);
+ h_real_to_string_class->DumpClass(LOG_STREAM(FATAL), mirror::Class::kDumpClassFullDetail);
} else {
JValue invoke_result;
EnterInterpreterFromInvoke(self, init_method, h_real_to_string_obj.Get(), nullptr,
diff --git a/runtime/jdwp/jdwp_socket.cc b/runtime/jdwp/jdwp_socket.cc
index 2507fe9..3be7fd6 100644
--- a/runtime/jdwp/jdwp_socket.cc
+++ b/runtime/jdwp/jdwp_socket.cc
@@ -121,7 +121,7 @@
netState->listenSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (netState->listenSock < 0) {
- PLOG(probe ? ERROR : FATAL) << "Socket create failed";
+ PLOG(probe ? ::android::base::ERROR : ::android::base::FATAL) << "Socket create failed";
goto fail;
}
@@ -129,7 +129,8 @@
{
int one = 1;
if (setsockopt(netState->listenSock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) {
- PLOG(probe ? ERROR : FATAL) << "setsockopt(SO_REUSEADDR) failed";
+ PLOG(probe ? ::android::base::ERROR : ::android::base::FATAL)
+ << "setsockopt(SO_REUSEADDR) failed";
goto fail;
}
}
@@ -143,14 +144,15 @@
inet_aton("127.0.0.1", &addr.addrInet.sin_addr);
if (bind(netState->listenSock, &addr.addrPlain, sizeof(addr)) != 0) {
- PLOG(probe ? ERROR : FATAL) << "Attempt to bind to port " << port << " failed";
+ PLOG(probe ? ::android::base::ERROR : ::android::base::FATAL)
+ << "Attempt to bind to port " << port << " failed";
goto fail;
}
netState->listenPort = port;
if (listen(netState->listenSock, 5) != 0) {
- PLOG(probe ? ERROR : FATAL) << "Listen failed";
+ PLOG(probe ? ::android::base::ERROR : ::android::base::FATAL) << "Listen failed";
goto fail;
}
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index d984f45..afa52ca 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -337,7 +337,7 @@
Jit::~Jit() {
DCHECK(!profile_saver_options_.IsEnabled() || !ProfileSaver::IsStarted());
if (dump_info_on_shutdown_) {
- DumpInfo(LOG(INFO));
+ DumpInfo(LOG_STREAM(INFO));
}
DeleteThreadPool();
if (jit_compiler_handle_ != nullptr) {
diff --git a/runtime/jit/profile_saver.cc b/runtime/jit/profile_saver.cc
index 42916c3..a4bc3fc 100644
--- a/runtime/jit/profile_saver.cc
+++ b/runtime/jit/profile_saver.cc
@@ -447,7 +447,7 @@
}
instance_->shutting_down_ = true;
if (dump_info) {
- instance_->DumpInfo(LOG(INFO));
+ instance_->DumpInfo(LOG_STREAM(INFO));
}
}
diff --git a/runtime/jni_env_ext-inl.h b/runtime/jni_env_ext-inl.h
index dc6a3e8..685b056 100644
--- a/runtime/jni_env_ext-inl.h
+++ b/runtime/jni_env_ext-inl.h
@@ -32,9 +32,10 @@
if (check_jni) {
size_t entry_count = locals.Capacity();
if (entry_count > 16) {
- locals.Dump(LOG(WARNING) << "Warning: more than 16 JNI local references: "
- << entry_count << " (most recent was a " << PrettyTypeOf(obj) << ")\n");
- // TODO: LOG(FATAL) in a later release?
+ locals.Dump(LOG_STREAM(WARNING) << "Warning: more than 16 JNI local references: "
+ << entry_count << " (most recent was a "
+ << PrettyTypeOf(obj) << ")\n");
+ // TODO: LOG(FATAL) in a later release?
}
}
}
diff --git a/runtime/jni_internal.cc b/runtime/jni_internal.cc
index d9cb1c6..a11f9ab 100644
--- a/runtime/jni_internal.cc
+++ b/runtime/jni_internal.cc
@@ -100,8 +100,9 @@
static void ReportInvalidJNINativeMethod(const ScopedObjectAccess& soa, mirror::Class* c,
const char* kind, jint idx, bool return_errors)
REQUIRES_SHARED(Locks::mutator_lock_) {
- LOG(return_errors ? ERROR : FATAL) << "Failed to register native method in "
- << PrettyDescriptor(c) << " in " << c->GetDexCache()->GetLocation()->ToModifiedUtf8()
+ LOG(return_errors ? ::android::base::ERROR : ::android::base::FATAL)
+ << "Failed to register native method in " << PrettyDescriptor(c)
+ << " in " << c->GetDexCache()->GetLocation()->ToModifiedUtf8()
<< ": " << kind << " is null at index " << idx;
soa.Self()->ThrowNewExceptionF("Ljava/lang/NoSuchMethodError;",
"%s is null at index %d", kind, idx);
@@ -618,7 +619,8 @@
}
if (c->IsStringClass()) {
// Replace calls to String.<init> with equivalent StringFactory call.
- jmethodID sf_mid = WellKnownClasses::StringInitToStringFactoryMethodID(mid);
+ jmethodID sf_mid = soa.EncodeMethod(
+ WellKnownClasses::StringInitToStringFactory(soa.DecodeMethod(mid)));
return CallStaticObjectMethodV(env, WellKnownClasses::java_lang_StringFactory, sf_mid, args);
}
mirror::Object* result = c->AllocObject(soa.Self());
@@ -643,7 +645,8 @@
}
if (c->IsStringClass()) {
// Replace calls to String.<init> with equivalent StringFactory call.
- jmethodID sf_mid = WellKnownClasses::StringInitToStringFactoryMethodID(mid);
+ jmethodID sf_mid = soa.EncodeMethod(
+ WellKnownClasses::StringInitToStringFactory(soa.DecodeMethod(mid)));
return CallStaticObjectMethodA(env, WellKnownClasses::java_lang_StringFactory, sf_mid, args);
}
mirror::Object* result = c->AllocObject(soa.Self());
@@ -2226,16 +2229,20 @@
}
if (m == nullptr) {
- LOG(return_errors ? ERROR : INTERNAL_FATAL) << "Failed to register native method "
+ c->DumpClass(
+ LOG_STREAM(return_errors
+ ? ::android::base::ERROR
+ : ::android::base::FATAL_WITHOUT_ABORT),
+ mirror::Class::kDumpClassFullDetail);
+ LOG(return_errors ? ::android::base::ERROR : ::android::base::FATAL)
+ << "Failed to register native method "
<< PrettyDescriptor(c) << "." << name << sig << " in "
<< c->GetDexCache()->GetLocation()->ToModifiedUtf8();
- // Safe to pass in LOG(FATAL) since the log object aborts in destructor and only goes
- // out of scope after the DumpClass is done executing.
- c->DumpClass(LOG(return_errors ? ERROR : FATAL), mirror::Class::kDumpClassFullDetail);
ThrowNoSuchMethodError(soa, c, name, sig, "static or non-static");
return JNI_ERR;
} else if (!m->IsNative()) {
- LOG(return_errors ? ERROR : FATAL) << "Failed to register non-native method "
+ LOG(return_errors ? ::android::base::ERROR : ::android::base::FATAL)
+ << "Failed to register non-native method "
<< PrettyDescriptor(c) << "." << name << sig
<< " as native";
ThrowNoSuchMethodError(soa, c, name, sig, "native");
@@ -2478,7 +2485,7 @@
} else if (kWarnJniAbort && memcmp(array_data, elements, bytes) != 0) {
// Warn if we have JNI_ABORT and the arrays don't match since this is usually an error.
LOG(WARNING) << "Possible incorrect JNI_ABORT in Release*ArrayElements";
- soa.Self()->DumpJavaStack(LOG(WARNING));
+ soa.Self()->DumpJavaStack(LOG_STREAM(WARNING));
}
}
if (mode != JNI_COMMIT) {
@@ -3042,7 +3049,7 @@
os << "JNIWeakGlobalRefType";
return os;
default:
- LOG(::art::FATAL) << "jobjectRefType[" << static_cast<int>(rhs) << "]";
+ LOG(FATAL) << "jobjectRefType[" << static_cast<int>(rhs) << "]";
UNREACHABLE();
}
}
diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc
index f21baed..2e5f532 100644
--- a/runtime/mirror/class.cc
+++ b/runtime/mirror/class.cc
@@ -147,8 +147,8 @@
void Class::SetClassSize(uint32_t new_class_size) {
if (kIsDebugBuild && new_class_size < GetClassSize()) {
- DumpClass(LOG(INTERNAL_FATAL), kDumpClassFullDetail);
- LOG(INTERNAL_FATAL) << new_class_size << " vs " << GetClassSize();
+ DumpClass(LOG_STREAM(FATAL_WITHOUT_ABORT), kDumpClassFullDetail);
+ LOG(FATAL_WITHOUT_ABORT) << new_class_size << " vs " << GetClassSize();
LOG(FATAL) << "class=" << PrettyTypeOf(this);
}
// Not called within a transaction.
diff --git a/runtime/mirror/object-inl.h b/runtime/mirror/object-inl.h
index 0f5cbb2..ad7558c 100644
--- a/runtime/mirror/object-inl.h
+++ b/runtime/mirror/object-inl.h
@@ -31,6 +31,7 @@
#include "lock_word-inl.h"
#include "monitor.h"
#include "object_array-inl.h"
+#include "obj_ptr-inl.h"
#include "read_barrier-inl.h"
#include "reference.h"
#include "runtime.h"
@@ -281,7 +282,7 @@
}
template<VerifyObjectFlags kVerifyFlags>
-inline bool Object::InstanceOf(Class* klass) {
+inline bool Object::InstanceOf(ObjPtr<Class> klass) {
DCHECK(klass != nullptr);
DCHECK(GetClass<kVerifyNone>() != nullptr);
return klass->IsAssignableFrom(GetClass<kVerifyFlags>());
@@ -509,7 +510,7 @@
template GetObjectSize<kNewFlags, kReadBarrierOption>();
}
DCHECK_GE(result, sizeof(Object))
- << " class=" << PrettyTypeOf(GetClass<kNewFlags, kReadBarrierOption>());
+ << " class=" << PrettyClass(GetClass<kNewFlags, kReadBarrierOption>());
return result;
}
diff --git a/runtime/mirror/object.h b/runtime/mirror/object.h
index 262cb57..10faf60 100644
--- a/runtime/mirror/object.h
+++ b/runtime/mirror/object.h
@@ -20,6 +20,7 @@
#include "base/casts.h"
#include "base/enums.h"
#include "globals.h"
+#include "obj_ptr.h"
#include "object_reference.h"
#include "offsets.h"
#include "verify_object.h"
@@ -120,7 +121,7 @@
template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
bool VerifierInstanceOf(Class* klass) REQUIRES_SHARED(Locks::mutator_lock_);
template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
- ALWAYS_INLINE bool InstanceOf(Class* klass) REQUIRES_SHARED(Locks::mutator_lock_);
+ ALWAYS_INLINE bool InstanceOf(ObjPtr<Class> klass) REQUIRES_SHARED(Locks::mutator_lock_);
template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
diff --git a/runtime/mirror/object_test.cc b/runtime/mirror/object_test.cc
index afd6115..0f3447e 100644
--- a/runtime/mirror/object_test.cc
+++ b/runtime/mirror/object_test.cc
@@ -35,6 +35,7 @@
#include "gc/heap.h"
#include "handle_scope-inl.h"
#include "iftable-inl.h"
+#include "obj_ptr.h"
#include "object-inl.h"
#include "object_array-inl.h"
#include "scoped_thread_state_change.h"
@@ -738,5 +739,62 @@
EXPECT_NE(hash_code, 0);
}
+TEST_F(ObjectTest, ObjectPointer) {
+ ScopedObjectAccess soa(Thread::Current());
+ jobject jclass_loader = LoadDex("XandY");
+ StackHandleScope<2> hs(soa.Self());
+ ObjPtr<mirror::Object, /*kPoison*/ true> null_ptr;
+ EXPECT_TRUE(null_ptr.IsNull());
+ EXPECT_TRUE(null_ptr.IsValid());
+ EXPECT_TRUE(null_ptr.Decode() == nullptr);
+ EXPECT_TRUE(null_ptr == nullptr);
+ EXPECT_TRUE(null_ptr == null_ptr);
+ EXPECT_FALSE(null_ptr != null_ptr);
+ EXPECT_FALSE(null_ptr != nullptr);
+ null_ptr.AssertValid();
+ Handle<ClassLoader> class_loader(hs.NewHandle(soa.Decode<ClassLoader*>(jclass_loader)));
+ Handle<mirror::Class> h_X(
+ hs.NewHandle(class_linker_->FindClass(soa.Self(), "LX;", class_loader)));
+ ObjPtr<Class, /*kPoison*/ true> X(h_X.Get());
+ EXPECT_TRUE(!X.IsNull());
+ EXPECT_TRUE(X.IsValid());
+ EXPECT_TRUE(X.Decode() != nullptr);
+ EXPECT_EQ(h_X.Get(), X.Decode());
+ // FindClass may cause thread suspension, it should invalidate X.
+ ObjPtr<Class, /*kPoison*/ true> Y(class_linker_->FindClass(soa.Self(), "LY;", class_loader));
+ EXPECT_TRUE(!Y.IsNull());
+ EXPECT_TRUE(Y.IsValid());
+ EXPECT_TRUE(Y.Decode() != nullptr);
+
+ // Should IsNull be safe to call on null ObjPtr? I'll allow it for now.
+ EXPECT_TRUE(!X.IsNull());
+ EXPECT_TRUE(!X.IsValid());
+ // Make X valid again by copying out of handle.
+ X.Assign(h_X.Get());
+ EXPECT_TRUE(!X.IsNull());
+ EXPECT_TRUE(X.IsValid());
+ EXPECT_EQ(h_X.Get(), X.Decode());
+
+ // Allow thread suspension to invalidate Y.
+ soa.Self()->AllowThreadSuspension();
+ EXPECT_TRUE(!Y.IsNull());
+ EXPECT_TRUE(!Y.IsValid());
+
+ // Test unpoisoned.
+ ObjPtr<mirror::Object, /*kPoison*/ false> unpoisoned;
+ EXPECT_TRUE(unpoisoned.IsNull());
+ EXPECT_TRUE(unpoisoned.IsValid());
+ EXPECT_TRUE(unpoisoned.Decode() == nullptr);
+ EXPECT_TRUE(unpoisoned == nullptr);
+ EXPECT_TRUE(unpoisoned == unpoisoned);
+ EXPECT_FALSE(unpoisoned != unpoisoned);
+ EXPECT_FALSE(unpoisoned != nullptr);
+
+ unpoisoned = h_X.Get();
+ EXPECT_FALSE(unpoisoned.IsNull());
+ EXPECT_TRUE(unpoisoned == h_X.Get());
+ EXPECT_EQ(unpoisoned.Decode(), h_X.Get());
+}
+
} // namespace mirror
} // namespace art
diff --git a/runtime/monitor.cc b/runtime/monitor.cc
index 22cc197..49b83a7 100644
--- a/runtime/monitor.cc
+++ b/runtime/monitor.cc
@@ -457,7 +457,7 @@
if (!Runtime::Current()->IsStarted() || VLOG_IS_ON(monitor)) {
std::ostringstream ss;
self->Dump(ss);
- LOG(Runtime::Current()->IsStarted() ? INFO : ERROR)
+ LOG(Runtime::Current()->IsStarted() ? ::android::base::INFO : ::android::base::ERROR)
<< self->GetException()->Dump() << "\n" << ss.str();
}
va_end(args);
diff --git a/runtime/native/dalvik_system_VMDebug.cc b/runtime/native/dalvik_system_VMDebug.cc
index 8f108fa..f09c067 100644
--- a/runtime/native/dalvik_system_VMDebug.cc
+++ b/runtime/native/dalvik_system_VMDebug.cc
@@ -240,8 +240,8 @@
ScopedObjectAccess soa(env);
LOG(INFO) << "--- reference table dump ---";
- soa.Env()->DumpReferenceTables(LOG(INFO));
- soa.Vm()->DumpReferenceTables(LOG(INFO));
+ soa.Env()->DumpReferenceTables(LOG_STREAM(INFO));
+ soa.Vm()->DumpReferenceTables(LOG_STREAM(INFO));
LOG(INFO) << "---";
}
diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc
index af9b68f..b6260e9 100644
--- a/runtime/native/java_lang_Class.cc
+++ b/runtime/native/java_lang_Class.cc
@@ -33,6 +33,7 @@
#include "mirror/object-inl.h"
#include "mirror/object_array-inl.h"
#include "mirror/string-inl.h"
+#include "obj_ptr-inl.h"
#include "reflection.h"
#include "scoped_thread_state_change.h"
#include "scoped_fast_native_object_access.h"
@@ -669,7 +670,10 @@
caller.Assign(GetCallingClass(soa.Self(), 1));
}
if (UNLIKELY(caller.Get() != nullptr && !VerifyAccess(
- receiver.Get(), declaring_class, constructor->GetAccessFlags(), caller.Get()))) {
+ MakeObjPtr(receiver.Get()),
+ MakeObjPtr(declaring_class),
+ constructor->GetAccessFlags(),
+ MakeObjPtr(caller.Get())))) {
soa.Self()->ThrowNewExceptionF(
"Ljava/lang/IllegalAccessException;", "%s is not accessible from %s",
PrettyMethod(constructor).c_str(), PrettyClass(caller.Get()).c_str());
diff --git a/runtime/native/java_lang_reflect_Constructor.cc b/runtime/native/java_lang_reflect_Constructor.cc
index d001d0c..47c49d5 100644
--- a/runtime/native/java_lang_reflect_Constructor.cc
+++ b/runtime/native/java_lang_reflect_Constructor.cc
@@ -73,7 +73,7 @@
if (!m->IsAccessible() && !c->IsPublic()) {
// Go 2 frames back, this method is always called from newInstance0, which is called from
// Constructor.newInstance(Object... args).
- auto* caller = GetCallingClass(soa.Self(), 2);
+ ObjPtr<mirror::Class> caller = GetCallingClass(soa.Self(), 2);
// If caller is null, then we called from JNI, just avoid the check since JNI avoids most
// access checks anyways. TODO: Investigate if this the correct behavior.
if (caller != nullptr && !caller->CanAccess(c.Get())) {
diff --git a/runtime/native/java_lang_reflect_Executable.cc b/runtime/native/java_lang_reflect_Executable.cc
index 8fcf6ac..f345c09 100644
--- a/runtime/native/java_lang_reflect_Executable.cc
+++ b/runtime/native/java_lang_reflect_Executable.cc
@@ -18,8 +18,10 @@
#include "art_method-inl.h"
#include "dex_file_annotations.h"
+#include "handle.h"
#include "jni_internal.h"
#include "mirror/class-inl.h"
+#include "mirror/method.h"
#include "mirror/object-inl.h"
#include "mirror/object_array-inl.h"
#include "reflection.h"
@@ -43,8 +45,8 @@
}
static jobject Executable_getAnnotationNative(JNIEnv* env,
- jobject javaMethod,
- jclass annotationType) {
+ jobject javaMethod,
+ jclass annotationType) {
ScopedFastNativeObjectAccess soa(env);
StackHandleScope<1> hs(soa.Self());
ArtMethod* method = ArtMethod::FromReflectedMethod(soa, javaMethod);
@@ -77,9 +79,107 @@
}
}
+static jobjectArray Executable_getParameters0(JNIEnv* env, jobject javaMethod) {
+ ScopedFastNativeObjectAccess soa(env);
+ Thread* self = soa.Self();
+ StackHandleScope<8> hs(self);
+
+ Handle<mirror::Method> executable = hs.NewHandle(soa.Decode<mirror::Method*>(javaMethod));
+ ArtMethod* art_method = executable.Get()->GetArtMethod();
+ if (art_method->GetDeclaringClass()->IsProxyClass()) {
+ return nullptr;
+ }
+
+ // Find the MethodParameters system annotation.
+ MutableHandle<mirror::ObjectArray<mirror::String>> names =
+ hs.NewHandle<mirror::ObjectArray<mirror::String>>(nullptr);
+ MutableHandle<mirror::IntArray> access_flags = hs.NewHandle<mirror::IntArray>(nullptr);
+ if (!annotations::GetParametersMetadataForMethod(art_method, &names, &access_flags)) {
+ return nullptr;
+ }
+
+ // Validate the MethodParameters system annotation data.
+ if (UNLIKELY(names.Get() == nullptr || access_flags.Get() == nullptr)) {
+ ThrowIllegalArgumentException(
+ StringPrintf("Missing parameter metadata for names or access flags for %s",
+ PrettyMethod(art_method).c_str()).c_str());
+ return nullptr;
+ }
+
+ // Check array sizes match each other
+ int32_t names_count = names.Get()->GetLength();
+ int32_t access_flags_count = access_flags.Get()->GetLength();
+ if (names_count != access_flags_count) {
+ ThrowIllegalArgumentException(
+ StringPrintf(
+ "Inconsistent parameter metadata for %s. names length: %d, access flags length: %d",
+ PrettyMethod(art_method).c_str(),
+ names_count,
+ access_flags_count).c_str());
+ return nullptr;
+ }
+
+ // Instantiate a Parameter[] to hold the result.
+ Handle<mirror::Class> parameter_array_class =
+ hs.NewHandle(
+ soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_reflect_Parameter__array));
+ Handle<mirror::ObjectArray<mirror::Object>> parameter_array =
+ hs.NewHandle(
+ mirror::ObjectArray<mirror::Object>::Alloc(self,
+ parameter_array_class.Get(),
+ names_count));
+ if (UNLIKELY(parameter_array.Get() == nullptr)) {
+ self->AssertPendingException();
+ return nullptr;
+ }
+
+ Handle<mirror::Class> parameter_class =
+ hs.NewHandle(soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_reflect_Parameter));
+ ArtMethod* parameter_init =
+ soa.DecodeMethod(WellKnownClasses::java_lang_reflect_Parameter_init);
+
+ // Mutable handles used in the loop below to ensure cleanup without scaling the number of
+ // handles by the number of parameters.
+ MutableHandle<mirror::String> name = hs.NewHandle<mirror::String>(nullptr);
+ MutableHandle<mirror::Object> parameter = hs.NewHandle<mirror::Object>(nullptr);
+
+ // Populate the Parameter[] to return.
+ for (int32_t parameter_index = 0; parameter_index < names_count; parameter_index++) {
+ name.Assign(names.Get()->Get(parameter_index));
+ int32_t modifiers = access_flags.Get()->Get(parameter_index);
+
+ // Allocate / initialize the Parameter to add to parameter_array.
+ parameter.Assign(parameter_class->AllocObject(self));
+ if (UNLIKELY(parameter.Get() == nullptr)) {
+ self->AssertPendingOOMException();
+ return nullptr;
+ }
+
+ uint32_t args[5] = { PointerToLowMemUInt32(parameter.Get()),
+ PointerToLowMemUInt32(name.Get()),
+ static_cast<uint32_t>(modifiers),
+ PointerToLowMemUInt32(executable.Get()),
+ static_cast<uint32_t>(parameter_index)
+ };
+ JValue result;
+ static const char* method_signature = "VLILI"; // return + parameter types
+ parameter_init->Invoke(self, args, sizeof(args), &result, method_signature);
+ if (UNLIKELY(self->IsExceptionPending())) {
+ return nullptr;
+ }
+
+ // Store the Parameter in the Parameter[].
+ parameter_array.Get()->Set(parameter_index, parameter.Get());
+ if (UNLIKELY(self->IsExceptionPending())) {
+ return nullptr;
+ }
+ }
+ return soa.AddLocalReference<jobjectArray>(parameter_array.Get());
+}
+
static jboolean Executable_isAnnotationPresentNative(JNIEnv* env,
- jobject javaMethod,
- jclass annotationType) {
+ jobject javaMethod,
+ jclass annotationType) {
ScopedFastNativeObjectAccess soa(env);
ArtMethod* method = ArtMethod::FromReflectedMethod(soa, javaMethod);
if (method->GetDeclaringClass()->IsProxyClass()) {
@@ -96,6 +196,7 @@
NATIVE_METHOD(Executable, getDeclaredAnnotationsNative, "!()[Ljava/lang/annotation/Annotation;"),
NATIVE_METHOD(Executable, getParameterAnnotationsNative,
"!()[[Ljava/lang/annotation/Annotation;"),
+ NATIVE_METHOD(Executable, getParameters0, "!()[Ljava/lang/reflect/Parameter;"),
NATIVE_METHOD(Executable, getSignatureAnnotation, "!()[Ljava/lang/String;"),
NATIVE_METHOD(Executable, isAnnotationPresentNative, "!(Ljava/lang/Class;)Z"),
};
diff --git a/runtime/native/java_lang_reflect_Field.cc b/runtime/native/java_lang_reflect_Field.cc
index 412445f..dab510d 100644
--- a/runtime/native/java_lang_reflect_Field.cc
+++ b/runtime/native/java_lang_reflect_Field.cc
@@ -43,9 +43,13 @@
PrettyClass(field->GetDeclaringClass()).c_str()).c_str());
return false;
}
- mirror::Class* calling_class = nullptr;
- if (!VerifyAccess(self, obj, field->GetDeclaringClass(), field->GetAccessFlags(),
- &calling_class, 1)) {
+ ObjPtr<mirror::Class> calling_class;
+ if (!VerifyAccess(self,
+ MakeObjPtr(obj),
+ MakeObjPtr(field->GetDeclaringClass()),
+ field->GetAccessFlags(),
+ &calling_class,
+ 1)) {
ThrowIllegalAccessException(
StringPrintf("Class %s cannot access %s field %s of class %s",
calling_class == nullptr ? "null" : PrettyClass(calling_class).c_str(),
@@ -124,7 +128,7 @@
return true;
}
*class_or_rcvr = soa.Decode<mirror::Object*>(j_rcvr);
- if (!VerifyObjectIsClass(*class_or_rcvr, declaringClass)) {
+ if (!VerifyObjectIsClass(MakeObjPtr(*class_or_rcvr), MakeObjPtr(declaringClass))) {
DCHECK(soa.Self()->IsExceptionPending());
return false;
}
@@ -152,7 +156,7 @@
DCHECK(soa.Self()->IsExceptionPending());
return nullptr;
}
- return soa.AddLocalReference<jobject>(BoxPrimitive(field_type, value));
+ return soa.AddLocalReference<jobject>(BoxPrimitive(field_type, value).Decode());
}
template<Primitive::Type kPrimitiveType>
@@ -323,7 +327,10 @@
// Unbox the value, if necessary.
mirror::Object* boxed_value = soa.Decode<mirror::Object*>(javaValue);
JValue unboxed_value;
- if (!UnboxPrimitiveForField(boxed_value, field_type, f->GetArtField(), &unboxed_value)) {
+ if (!UnboxPrimitiveForField(MakeObjPtr(boxed_value),
+ MakeObjPtr(field_type),
+ f->GetArtField(),
+ &unboxed_value)) {
DCHECK(soa.Self()->IsExceptionPending());
return;
}
diff --git a/runtime/obj_ptr-inl.h b/runtime/obj_ptr-inl.h
new file mode 100644
index 0000000..3dfcf9e
--- /dev/null
+++ b/runtime/obj_ptr-inl.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#ifndef ART_RUNTIME_OBJ_PTR_INL_H_
+#define ART_RUNTIME_OBJ_PTR_INL_H_
+
+#include "obj_ptr.h"
+#include "thread-inl.h"
+
+namespace art {
+
+template<class MirrorType, bool kPoison>
+inline bool ObjPtr<MirrorType, kPoison>::IsValid() const {
+ if (!kPoison || IsNull()) {
+ return true;
+ }
+ return GetCookie() == TrimCookie(Thread::Current()->GetPoisonObjectCookie());
+}
+
+template<class MirrorType, bool kPoison>
+inline void ObjPtr<MirrorType, kPoison>::AssertValid() const {
+ if (kPoison) {
+ CHECK(IsValid()) << "Stale object pointer " << DecodeUnchecked() << " , expected cookie "
+ << TrimCookie(Thread::Current()->GetPoisonObjectCookie()) << " but got " << GetCookie();
+ }
+}
+
+template<class MirrorType, bool kPoison>
+inline uintptr_t ObjPtr<MirrorType, kPoison>::Encode(MirrorType* ptr) {
+ uintptr_t ref = reinterpret_cast<uintptr_t>(ptr);
+ if (kPoison && ref != 0) {
+ DCHECK_LE(ref, 0xFFFFFFFFU);
+ ref >>= kObjectAlignmentShift;
+ // Put cookie in high bits.
+ Thread* self = Thread::Current();
+ DCHECK(self != nullptr);
+ ref |= self->GetPoisonObjectCookie() << kCookieShift;
+ }
+ return ref;
+}
+
+} // namespace art
+
+#endif // ART_RUNTIME_OBJ_PTR_INL_H_
diff --git a/runtime/obj_ptr.h b/runtime/obj_ptr.h
new file mode 100644
index 0000000..d4076be
--- /dev/null
+++ b/runtime/obj_ptr.h
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#ifndef ART_RUNTIME_OBJ_PTR_H_
+#define ART_RUNTIME_OBJ_PTR_H_
+
+#include "base/mutex.h" // For Locks::mutator_lock_.
+#include "globals.h"
+#include "mirror/object_reference.h"
+
+namespace art {
+
+// Value type representing a pointer to a mirror::Object of type MirrorType
+// Pass kPoison as a template boolean for testing in non-debug builds.
+// Since the cookie is thread based, it is not safe to share an ObjPtr between threads.
+template<class MirrorType, bool kPoison = kIsDebugBuild>
+class ObjPtr {
+ static constexpr size_t kCookieShift =
+ sizeof(mirror::HeapReference<mirror::Object>) * kBitsPerByte - kObjectAlignmentShift;
+ static constexpr size_t kCookieBits = sizeof(uintptr_t) * kBitsPerByte - kCookieShift;
+ static constexpr uintptr_t kCookieMask = (static_cast<uintptr_t>(1u) << kCookieBits) - 1;
+
+ static_assert(kCookieBits >= kObjectAlignmentShift,
+ "must have a least kObjectAlignmentShift bits");
+
+ public:
+ ALWAYS_INLINE ObjPtr() REQUIRES_SHARED(Locks::mutator_lock_) : reference_(0u) {}
+
+ ALWAYS_INLINE ObjPtr(std::nullptr_t) REQUIRES_SHARED(Locks::mutator_lock_) : reference_(0u) {}
+
+ template <typename Type>
+ ALWAYS_INLINE ObjPtr(Type* ptr) REQUIRES_SHARED(Locks::mutator_lock_)
+ : reference_(Encode(static_cast<MirrorType*>(ptr))) {}
+
+ ALWAYS_INLINE ObjPtr(const ObjPtr& other) REQUIRES_SHARED(Locks::mutator_lock_) = default;
+
+ ALWAYS_INLINE ObjPtr& operator=(const ObjPtr& other) {
+ reference_ = other.reference_;
+ return *this;
+ }
+
+ ALWAYS_INLINE ObjPtr& operator=(MirrorType* ptr) REQUIRES_SHARED(Locks::mutator_lock_) {
+ Assign(ptr);
+ return *this;
+ }
+
+ ALWAYS_INLINE void Assign(MirrorType* ptr) REQUIRES_SHARED(Locks::mutator_lock_) {
+ reference_ = Encode(ptr);
+ }
+
+ ALWAYS_INLINE MirrorType* operator->() const REQUIRES_SHARED(Locks::mutator_lock_) {
+ return Decode();
+ }
+
+
+ ALWAYS_INLINE bool IsNull() const {
+ return reference_ == 0;
+ }
+
+ // Decode makes sure that the object pointer is valid.
+ ALWAYS_INLINE MirrorType* Decode() const REQUIRES_SHARED(Locks::mutator_lock_) {
+ AssertValid();
+ return DecodeUnchecked();
+ }
+
+ ALWAYS_INLINE bool IsValid() const REQUIRES_SHARED(Locks::mutator_lock_);
+
+ ALWAYS_INLINE void AssertValid() const REQUIRES_SHARED(Locks::mutator_lock_);
+
+ ALWAYS_INLINE bool operator==(const ObjPtr& ptr) const REQUIRES_SHARED(Locks::mutator_lock_) {
+ return Decode() == ptr.Decode();
+ }
+
+ ALWAYS_INLINE bool operator==(const MirrorType* ptr) const REQUIRES_SHARED(Locks::mutator_lock_) {
+ return Decode() == ptr;
+ }
+
+ ALWAYS_INLINE bool operator==(std::nullptr_t) const REQUIRES_SHARED(Locks::mutator_lock_) {
+ return IsNull();
+ }
+
+ ALWAYS_INLINE bool operator!=(const ObjPtr& ptr) const REQUIRES_SHARED(Locks::mutator_lock_) {
+ return Decode() != ptr.Decode();
+ }
+
+ ALWAYS_INLINE bool operator!=(const MirrorType* ptr) const REQUIRES_SHARED(Locks::mutator_lock_) {
+ return Decode() != ptr;
+ }
+
+ ALWAYS_INLINE bool operator!=(std::nullptr_t) const REQUIRES_SHARED(Locks::mutator_lock_) {
+ return !IsNull();
+ }
+
+ private:
+ // Trim off high bits of thread local cookie.
+ ALWAYS_INLINE static uintptr_t TrimCookie(uintptr_t cookie) {
+ return cookie & kCookieMask;
+ }
+
+ ALWAYS_INLINE uintptr_t GetCookie() const {
+ return reference_ >> kCookieShift;
+ }
+
+ // Decode makes sure that the object pointer is valid.
+ ALWAYS_INLINE MirrorType* DecodeUnchecked() const REQUIRES_SHARED(Locks::mutator_lock_) {
+ if (kPoison) {
+ return reinterpret_cast<MirrorType*>(
+ static_cast<uintptr_t>(static_cast<uint32_t>(reference_ << kObjectAlignmentShift)));
+ } else {
+ return reinterpret_cast<MirrorType*>(reference_);
+ }
+ }
+
+ ALWAYS_INLINE static uintptr_t Encode(MirrorType* ptr) REQUIRES_SHARED(Locks::mutator_lock_);
+ // The encoded reference and cookie.
+ uintptr_t reference_;
+};
+
+template<class MirrorType, bool kPoison = kIsDebugBuild>
+static inline ObjPtr<MirrorType, kPoison> MakeObjPtr(MirrorType* ptr) {
+ return ObjPtr<MirrorType, kPoison>(ptr);
+}
+
+} // namespace art
+
+#endif // ART_RUNTIME_OBJ_PTR_H_
diff --git a/runtime/openjdkjvm/Android.bp b/runtime/openjdkjvm/Android.bp
index 5ed1615..37112b6 100644
--- a/runtime/openjdkjvm/Android.bp
+++ b/runtime/openjdkjvm/Android.bp
@@ -19,7 +19,10 @@
host_supported: true,
srcs: ["OpenjdkJvm.cc"],
include_dirs: ["art/runtime"],
- shared_libs: ["libnativehelper"],
+ shared_libs: [
+ "libbase",
+ "libnativehelper"
+ ],
}
art_cc_library {
diff --git a/runtime/openjdkjvm/OpenjdkJvm.cc b/runtime/openjdkjvm/OpenjdkJvm.cc
index 54ec5d3..4a62ecd 100644
--- a/runtime/openjdkjvm/OpenjdkJvm.cc
+++ b/runtime/openjdkjvm/OpenjdkJvm.cc
@@ -61,10 +61,10 @@
#undef LOG_TAG
#define LOG_TAG "artopenjdk"
-using art::WARNING;
-using art::INFO;
-using art::ERROR;
-using art::FATAL;
+using ::android::base::WARNING;
+using ::android::base::INFO;
+using ::android::base::ERROR;
+using ::android::base::FATAL;
/* posix open() with extensions; used by e.g. ZipFile */
JNIEXPORT jint JVM_Open(const char* fname, jint flags, jint mode) {
diff --git a/runtime/openjdkjvmti/Android.bp b/runtime/openjdkjvmti/Android.bp
index 08272fa..d7a6c0a 100644
--- a/runtime/openjdkjvmti/Android.bp
+++ b/runtime/openjdkjvmti/Android.bp
@@ -20,7 +20,10 @@
srcs: ["OpenjdkJvmTi.cc",
"transform.cc"],
include_dirs: ["art/runtime"],
- shared_libs: ["libnativehelper"],
+ shared_libs: [
+ "libbase",
+ "libnativehelper",
+ ],
}
art_cc_library {
diff --git a/runtime/openjdkjvmti/transform.cc b/runtime/openjdkjvmti/transform.cc
index a0d79f3..b5622b5 100644
--- a/runtime/openjdkjvmti/transform.cc
+++ b/runtime/openjdkjvmti/transform.cc
@@ -201,8 +201,8 @@
art::Handle<art::mirror::Class> loader_class(hs.NewHandle(h_class_loader->GetClass()));
// Check if loader is a BaseDexClassLoader
if (!loader_class->IsSubClass(base_dex_loader_class.Get())) {
- LOG(art::ERROR) << "The classloader is not a BaseDexClassLoader which is currently the only "
- << "supported class loader type!";
+ LOG(ERROR) << "The classloader is not a BaseDexClassLoader which is currently the only "
+ << "supported class loader type!";
return false;
}
art::Handle<art::mirror::Object> path_list(
@@ -333,7 +333,7 @@
// Find dalvik.system.DexFile that represents the dex file we are changing.
if (!FindDalvikSystemDexFileAndLoaderForClass(klass, &dex_file_ptr, &class_loader_ptr)) {
self->TransitionFromRunnableToSuspended(old_state);
- LOG(art::ERROR) << "Could not find DexFile.";
+ LOG(ERROR) << "Could not find DexFile.";
return ERR(INTERNAL);
}
art::Handle<art::mirror::Object> dex_file_obj(hs.NewHandle(dex_file_ptr));
diff --git a/runtime/quick_exception_handler.cc b/runtime/quick_exception_handler.cc
index b3f29c2..9056d96 100644
--- a/runtime/quick_exception_handler.cc
+++ b/runtime/quick_exception_handler.cc
@@ -145,7 +145,7 @@
if (kDebugExceptionDelivery) {
mirror::String* msg = exception->GetDetailMessage();
std::string str_msg(msg != nullptr ? msg->ToModifiedUtf8() : "");
- self_->DumpStack(LOG(INFO) << "Delivering exception: " << PrettyTypeOf(exception)
+ self_->DumpStack(LOG_STREAM(INFO) << "Delivering exception: " << PrettyTypeOf(exception)
<< ": " << str_msg << "\n");
}
StackHandleScope<1> hs(self_);
@@ -218,7 +218,7 @@
DCHECK(handler_method_ != nullptr && handler_method_header_->IsOptimized());
if (kDebugExceptionDelivery) {
- self_->DumpStack(LOG(INFO) << "Setting catch phis: ");
+ self_->DumpStack(LOG_STREAM(INFO) << "Setting catch phis: ");
}
const size_t number_of_vregs = handler_method_->GetCodeItem()->registers_size_;
@@ -520,7 +520,7 @@
void QuickExceptionHandler::DeoptimizeStack() {
DCHECK(is_deoptimization_);
if (kDebugExceptionDelivery) {
- self_->DumpStack(LOG(INFO) << "Deoptimizing: ");
+ self_->DumpStack(LOG_STREAM(INFO) << "Deoptimizing: ");
}
DeoptimizeStackVisitor visitor(self_, context_, this, false);
diff --git a/runtime/reference_table.cc b/runtime/reference_table.cc
index f04d41d..0be79ef 100644
--- a/runtime/reference_table.cc
+++ b/runtime/reference_table.cc
@@ -192,6 +192,13 @@
} else {
StringAppendF(&extras, " \"%.16s... (%d chars)", utf8.c_str(), s->GetLength());
}
+ } else if (ref->IsReferenceInstance()) {
+ mirror::Object* referent = ref->AsReference()->GetReferent();
+ if (referent == nullptr) {
+ extras = " (referent is null)";
+ } else {
+ extras = StringPrintf(" (referent is a %s)", PrettyTypeOf(referent).c_str());
+ }
}
os << StringPrintf(" %5d: ", idx) << ref << " " << className << extras << "\n";
}
diff --git a/runtime/reference_table_test.cc b/runtime/reference_table_test.cc
index fae8e72..819e17a 100644
--- a/runtime/reference_table_test.cc
+++ b/runtime/reference_table_test.cc
@@ -16,11 +16,15 @@
#include "reference_table.h"
+#include "class_linker.h"
#include "common_runtime_test.h"
+#include "handle_scope-inl.h"
#include "mirror/array-inl.h"
#include "mirror/class-inl.h"
+#include "mirror/class_loader.h"
#include "mirror/string.h"
#include "primitive.h"
+#include "runtime.h"
#include "scoped_thread_state_change.h"
#include "thread-inl.h"
@@ -28,6 +32,39 @@
class ReferenceTableTest : public CommonRuntimeTest {};
+static mirror::Object* CreateWeakReference(mirror::Object* referent)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ Thread* self = Thread::Current();
+ ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
+
+ StackHandleScope<3> scope(self);
+ Handle<mirror::Object> h_referent(scope.NewHandle<mirror::Object>(referent));
+
+ Handle<mirror::Class> h_ref_class(scope.NewHandle<mirror::Class>(
+ class_linker->FindClass(self,
+ "Ljava/lang/ref/WeakReference;",
+ ScopedNullHandle<mirror::ClassLoader>())));
+ CHECK(h_ref_class.Get() != nullptr);
+ CHECK(class_linker->EnsureInitialized(self, h_ref_class, true, true));
+
+ Handle<mirror::Object> h_ref_instance(scope.NewHandle<mirror::Object>(
+ h_ref_class->AllocObject(self)));
+ CHECK(h_ref_instance.Get() != nullptr);
+
+ ArtMethod* constructor = h_ref_class->FindDeclaredDirectMethod(
+ "<init>", "(Ljava/lang/Object;)V", class_linker->GetImagePointerSize());
+ CHECK(constructor != nullptr);
+
+ uint32_t args[2];
+ args[0] = PointerToLowMemUInt32(h_ref_instance.Get());
+ args[1] = PointerToLowMemUInt32(h_referent.Get());
+ JValue result;
+ constructor->Invoke(self, args, sizeof(uint32_t), &result, constructor->GetShorty());
+ CHECK(!self->IsExceptionPending());
+
+ return h_ref_instance.Get();
+}
+
TEST_F(ReferenceTableTest, Basics) {
ScopedObjectAccess soa(Thread::Current());
mirror::Object* o1 = mirror::String::AllocFromModifiedUtf8(soa.Self(), "hello");
@@ -104,6 +141,29 @@
std::string::npos) << oss.str();
}
}
+
+ // Add a reference and check that the type of the referent is dumped.
+ {
+ mirror::Object* empty_reference = CreateWeakReference(nullptr);
+ ASSERT_TRUE(empty_reference->IsReferenceInstance());
+ rt.Add(empty_reference);
+ std::ostringstream oss;
+ rt.Dump(oss);
+ EXPECT_NE(oss.str().find("java.lang.ref.WeakReference (referent is null)"), std::string::npos)
+ << oss.str();
+ }
+
+ {
+ mirror::Object* string_referent = mirror::String::AllocFromModifiedUtf8(Thread::Current(), "A");
+ mirror::Object* non_empty_reference = CreateWeakReference(string_referent);
+ ASSERT_TRUE(non_empty_reference->IsReferenceInstance());
+ rt.Add(non_empty_reference);
+ std::ostringstream oss;
+ rt.Dump(oss);
+ EXPECT_NE(oss.str().find("java.lang.ref.WeakReference (referent is a java.lang.String)"),
+ std::string::npos)
+ << oss.str();
+ }
}
} // namespace art
diff --git a/runtime/reflection-inl.h b/runtime/reflection-inl.h
index f54d4ca..d7db8a4 100644
--- a/runtime/reflection-inl.h
+++ b/runtime/reflection-inl.h
@@ -23,14 +23,17 @@
#include "common_throws.h"
#include "jvalue.h"
#include "mirror/object-inl.h"
+#include "obj_ptr-inl.h"
#include "primitive.h"
#include "utils.h"
namespace art {
inline bool ConvertPrimitiveValue(bool unbox_for_result,
- Primitive::Type srcType, Primitive::Type dstType,
- const JValue& src, JValue* dst) {
+ Primitive::Type srcType,
+ Primitive::Type dstType,
+ const JValue& src,
+ JValue* dst) {
DCHECK(srcType != Primitive::kPrimNot && dstType != Primitive::kPrimNot);
if (LIKELY(srcType == dstType)) {
dst->SetJ(src.GetJ());
@@ -100,11 +103,11 @@
return false;
}
-inline bool VerifyObjectIsClass(mirror::Object* o, mirror::Class* c) {
+inline bool VerifyObjectIsClass(ObjPtr<mirror::Object> o, ObjPtr<mirror::Class> c) {
if (UNLIKELY(o == nullptr)) {
ThrowNullPointerException("null receiver");
return false;
- } else if (UNLIKELY(!o->InstanceOf(c))) {
+ } else if (UNLIKELY(!o->InstanceOf(c.Decode()))) {
InvalidReceiverError(o, c);
return false;
}
diff --git a/runtime/reflection.cc b/runtime/reflection.cc
index c69e98c..7c0f2b5 100644
--- a/runtime/reflection.cc
+++ b/runtime/reflection.cc
@@ -72,8 +72,8 @@
num_bytes_ += 4;
}
- void Append(mirror::Object* obj) REQUIRES_SHARED(Locks::mutator_lock_) {
- Append(StackReference<mirror::Object>::FromMirrorPtr(obj).AsVRegValue());
+ void Append(ObjPtr<mirror::Object> obj) REQUIRES_SHARED(Locks::mutator_lock_) {
+ Append(StackReference<mirror::Object>::FromMirrorPtr(obj.Decode()).AsVRegValue());
}
void AppendWide(uint64_t value) {
@@ -95,7 +95,8 @@
}
void BuildArgArrayFromVarArgs(const ScopedObjectAccessAlreadyRunnable& soa,
- mirror::Object* receiver, va_list ap)
+ ObjPtr<mirror::Object> receiver,
+ va_list ap)
REQUIRES_SHARED(Locks::mutator_lock_) {
// Set receiver if non-null (method is not static)
if (receiver != nullptr) {
@@ -131,7 +132,7 @@
}
void BuildArgArrayFromJValues(const ScopedObjectAccessAlreadyRunnable& soa,
- mirror::Object* receiver, jvalue* args)
+ ObjPtr<mirror::Object> receiver, jvalue* args)
REQUIRES_SHARED(Locks::mutator_lock_) {
// Set receiver if non-null (method is not static)
if (receiver != nullptr) {
@@ -212,8 +213,9 @@
PrettyDescriptor(found_descriptor).c_str()).c_str());
}
- bool BuildArgArrayFromObjectArray(mirror::Object* receiver,
- mirror::ObjectArray<mirror::Object>* args, ArtMethod* m)
+ bool BuildArgArrayFromObjectArray(ObjPtr<mirror::Object> receiver,
+ ObjPtr<mirror::ObjectArray<mirror::Object>> args,
+ ArtMethod* m)
REQUIRES_SHARED(Locks::mutator_lock_) {
const DexFile::TypeList* classes = m->GetParameterTypeList();
// Set receiver if non-null (method is not static)
@@ -221,13 +223,13 @@
Append(receiver);
}
for (size_t i = 1, args_offset = 0; i < shorty_len_; ++i, ++args_offset) {
- mirror::Object* arg = args->Get(args_offset);
+ ObjPtr<mirror::Object> arg(args->Get(args_offset));
if (((shorty_[i] == 'L') && (arg != nullptr)) || ((arg == nullptr && shorty_[i] != 'L'))) {
PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
- mirror::Class* dst_class =
+ ObjPtr<mirror::Class> dst_class(
m->GetClassFromTypeIndex(classes->GetTypeItem(args_offset).type_idx_,
true /* resolve */,
- pointer_size);
+ pointer_size));
if (UNLIKELY(arg == nullptr || !arg->InstanceOf(dst_class))) {
ThrowIllegalArgumentException(
StringPrintf("method %s argument %zd has type %s, got %s",
@@ -240,15 +242,15 @@
}
#define DO_FIRST_ARG(match_descriptor, get_fn, append) { \
- if (LIKELY(arg != nullptr && arg->GetClass<>()->DescriptorEquals(match_descriptor))) { \
+ if (LIKELY(arg != nullptr && arg->GetClass()->DescriptorEquals(match_descriptor))) { \
ArtField* primitive_field = arg->GetClass()->GetInstanceField(0); \
- append(primitive_field-> get_fn(arg));
+ append(primitive_field-> get_fn(arg.Decode()));
#define DO_ARG(match_descriptor, get_fn, append) \
} else if (LIKELY(arg != nullptr && \
arg->GetClass<>()->DescriptorEquals(match_descriptor))) { \
ArtField* primitive_field = arg->GetClass()->GetInstanceField(0); \
- append(primitive_field-> get_fn(arg));
+ append(primitive_field-> get_fn(arg.Decode()));
#define DO_FAIL(expected) \
} else { \
@@ -362,9 +364,9 @@
PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
for (uint32_t i = 0; i < num_params; i++) {
uint16_t type_idx = params->GetTypeItem(i).type_idx_;
- mirror::Class* param_type = m->GetClassFromTypeIndex(type_idx,
- true /* resolve*/,
- pointer_size);
+ ObjPtr<mirror::Class> param_type(m->GetClassFromTypeIndex(type_idx,
+ true /* resolve*/,
+ pointer_size));
if (param_type == nullptr) {
CHECK(self->IsExceptionPending());
LOG(ERROR) << "Internal error: unresolvable type for argument type in JNI invoke: "
@@ -376,7 +378,7 @@
// TODO: There is a compaction bug here since GetClassFromTypeIdx can cause thread suspension,
// this is a hard to fix problem since the args can contain Object*, we need to save and
// restore them by using a visitor similar to the ones used in the trampoline entrypoints.
- mirror::Object* argument =
+ ObjPtr<mirror::Object> argument =
(reinterpret_cast<StackReference<mirror::Object>*>(&args[i + offset]))->AsMirrorPtr();
if (argument != nullptr && !argument->InstanceOf(param_type)) {
LOG(ERROR) << "JNI ERROR (app bug): attempt to pass an instance of "
@@ -423,7 +425,7 @@
}
}
-static ArtMethod* FindVirtualMethod(mirror::Object* receiver, ArtMethod* method)
+static ArtMethod* FindVirtualMethod(ObjPtr<mirror::Object> receiver, ArtMethod* method)
REQUIRES_SHARED(Locks::mutator_lock_) {
return receiver->GetClass()->FindVirtualMethodForVirtualOrInterface(method, kRuntimePointerSize);
}
@@ -455,9 +457,9 @@
bool is_string_init = method->GetDeclaringClass()->IsStringClass() && method->IsConstructor();
if (is_string_init) {
// Replace calls to String.<init> with equivalent StringFactory call.
- method = soa.DecodeMethod(WellKnownClasses::StringInitToStringFactoryMethodID(mid));
+ method = WellKnownClasses::StringInitToStringFactory(method);
}
- mirror::Object* receiver = method->IsStatic() ? nullptr : soa.Decode<mirror::Object*>(obj);
+ ObjPtr<mirror::Object> receiver = method->IsStatic() ? nullptr : soa.Decode<mirror::Object*>(obj);
uint32_t shorty_len = 0;
const char* shorty =
method->GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetShorty(&shorty_len);
@@ -486,9 +488,9 @@
bool is_string_init = method->GetDeclaringClass()->IsStringClass() && method->IsConstructor();
if (is_string_init) {
// Replace calls to String.<init> with equivalent StringFactory call.
- method = soa.DecodeMethod(WellKnownClasses::StringInitToStringFactoryMethodID(mid));
+ method = WellKnownClasses::StringInitToStringFactory(method);
}
- mirror::Object* receiver = method->IsStatic() ? nullptr : soa.Decode<mirror::Object*>(obj);
+ ObjPtr<mirror::Object> receiver = method->IsStatic() ? nullptr : soa.Decode<mirror::Object*>(obj);
uint32_t shorty_len = 0;
const char* shorty =
method->GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetShorty(&shorty_len);
@@ -513,12 +515,12 @@
return JValue();
}
- mirror::Object* receiver = soa.Decode<mirror::Object*>(obj);
+ ObjPtr<mirror::Object> receiver = soa.Decode<mirror::Object*>(obj);
ArtMethod* method = FindVirtualMethod(receiver, soa.DecodeMethod(mid));
bool is_string_init = method->GetDeclaringClass()->IsStringClass() && method->IsConstructor();
if (is_string_init) {
// Replace calls to String.<init> with equivalent StringFactory call.
- method = soa.DecodeMethod(WellKnownClasses::StringInitToStringFactoryMethodID(mid));
+ method = WellKnownClasses::StringInitToStringFactory(method);
receiver = nullptr;
}
uint32_t shorty_len = 0;
@@ -545,12 +547,12 @@
return JValue();
}
- mirror::Object* receiver = soa.Decode<mirror::Object*>(obj);
+ ObjPtr<mirror::Object> receiver = soa.Decode<mirror::Object*>(obj);
ArtMethod* method = FindVirtualMethod(receiver, soa.DecodeMethod(mid));
bool is_string_init = method->GetDeclaringClass()->IsStringClass() && method->IsConstructor();
if (is_string_init) {
// Replace calls to String.<init> with equivalent StringFactory call.
- method = soa.DecodeMethod(WellKnownClasses::StringInitToStringFactoryMethodID(mid));
+ method = WellKnownClasses::StringInitToStringFactory(method);
receiver = nullptr;
}
uint32_t shorty_len = 0;
@@ -578,26 +580,25 @@
return nullptr;
}
- auto* executable = soa.Decode<mirror::Executable*>(javaMethod);
+ ObjPtr<mirror::Executable> executable = soa.Decode<mirror::Executable*>(javaMethod);
const bool accessible = executable->IsAccessible();
ArtMethod* m = executable->GetArtMethod();
- mirror::Class* declaring_class = m->GetDeclaringClass();
+ ObjPtr<mirror::Class> declaring_class = m->GetDeclaringClass();
if (UNLIKELY(!declaring_class->IsInitialized())) {
StackHandleScope<1> hs(soa.Self());
- Handle<mirror::Class> h_class(hs.NewHandle(declaring_class));
+ Handle<mirror::Class> h_class(hs.NewHandle(declaring_class.Decode()));
if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(soa.Self(), h_class, true, true)) {
return nullptr;
}
declaring_class = h_class.Get();
}
- mirror::Object* receiver = nullptr;
+ ObjPtr<mirror::Object> receiver;
if (!m->IsStatic()) {
// Replace calls to String.<init> with equivalent StringFactory call.
if (declaring_class->IsStringClass() && m->IsConstructor()) {
- jmethodID mid = soa.EncodeMethod(m);
- m = soa.DecodeMethod(WellKnownClasses::StringInitToStringFactoryMethodID(mid));
+ m = WellKnownClasses::StringInitToStringFactory(m);
CHECK(javaReceiver == nullptr);
} else {
// Check that the receiver is non-null and an instance of the field's declaring class.
@@ -624,7 +625,7 @@
}
// If method is not set to be accessible, verify it can be accessed by the caller.
- mirror::Class* calling_class = nullptr;
+ ObjPtr<mirror::Class> calling_class;
if (!accessible && !VerifyAccess(soa.Self(),
receiver,
declaring_class,
@@ -675,10 +676,11 @@
}
// Box if necessary and return.
- return soa.AddLocalReference<jobject>(BoxPrimitive(Primitive::GetType(shorty[0]), result));
+ return soa.AddLocalReference<jobject>(
+ BoxPrimitive(Primitive::GetType(shorty[0]), result).Decode());
}
-mirror::Object* BoxPrimitive(Primitive::Type src_class, const JValue& value) {
+ObjPtr<mirror::Object> BoxPrimitive(Primitive::Type src_class, const JValue& value) {
if (src_class == Primitive::kPrimNot) {
return value.GetL();
}
@@ -751,8 +753,9 @@
return "result";
}
-static bool UnboxPrimitive(mirror::Object* o,
- mirror::Class* dst_class, ArtField* f,
+static bool UnboxPrimitive(ObjPtr<mirror::Object> o,
+ ObjPtr<mirror::Class> dst_class,
+ ArtField* f,
JValue* unboxed_value)
REQUIRES_SHARED(Locks::mutator_lock_) {
bool unbox_for_result = (f == nullptr);
@@ -770,7 +773,7 @@
}
return false;
}
- unboxed_value->SetL(o);
+ unboxed_value->SetL(o.Decode());
return true;
}
if (UNLIKELY(dst_class->GetPrimitiveType() == Primitive::kPrimVoid)) {
@@ -792,34 +795,34 @@
}
JValue boxed_value;
- mirror::Class* klass = o->GetClass();
- mirror::Class* src_class = nullptr;
+ ObjPtr<mirror::Class> klass = o->GetClass();
+ ObjPtr<mirror::Class> src_class = nullptr;
ClassLinker* const class_linker = Runtime::Current()->GetClassLinker();
ArtField* primitive_field = &klass->GetIFieldsPtr()->At(0);
if (klass->DescriptorEquals("Ljava/lang/Boolean;")) {
src_class = class_linker->FindPrimitiveClass('Z');
- boxed_value.SetZ(primitive_field->GetBoolean(o));
+ boxed_value.SetZ(primitive_field->GetBoolean(o.Decode()));
} else if (klass->DescriptorEquals("Ljava/lang/Byte;")) {
src_class = class_linker->FindPrimitiveClass('B');
- boxed_value.SetB(primitive_field->GetByte(o));
+ boxed_value.SetB(primitive_field->GetByte(o.Decode()));
} else if (klass->DescriptorEquals("Ljava/lang/Character;")) {
src_class = class_linker->FindPrimitiveClass('C');
- boxed_value.SetC(primitive_field->GetChar(o));
+ boxed_value.SetC(primitive_field->GetChar(o.Decode()));
} else if (klass->DescriptorEquals("Ljava/lang/Float;")) {
src_class = class_linker->FindPrimitiveClass('F');
- boxed_value.SetF(primitive_field->GetFloat(o));
+ boxed_value.SetF(primitive_field->GetFloat(o.Decode()));
} else if (klass->DescriptorEquals("Ljava/lang/Double;")) {
src_class = class_linker->FindPrimitiveClass('D');
- boxed_value.SetD(primitive_field->GetDouble(o));
+ boxed_value.SetD(primitive_field->GetDouble(o.Decode()));
} else if (klass->DescriptorEquals("Ljava/lang/Integer;")) {
src_class = class_linker->FindPrimitiveClass('I');
- boxed_value.SetI(primitive_field->GetInt(o));
+ boxed_value.SetI(primitive_field->GetInt(o.Decode()));
} else if (klass->DescriptorEquals("Ljava/lang/Long;")) {
src_class = class_linker->FindPrimitiveClass('J');
- boxed_value.SetJ(primitive_field->GetLong(o));
+ boxed_value.SetJ(primitive_field->GetLong(o.Decode()));
} else if (klass->DescriptorEquals("Ljava/lang/Short;")) {
src_class = class_linker->FindPrimitiveClass('S');
- boxed_value.SetS(primitive_field->GetShort(o));
+ boxed_value.SetS(primitive_field->GetShort(o.Decode()));
} else {
std::string temp;
ThrowIllegalArgumentException(
@@ -834,28 +837,36 @@
boxed_value, unboxed_value);
}
-bool UnboxPrimitiveForField(mirror::Object* o, mirror::Class* dst_class, ArtField* f,
+bool UnboxPrimitiveForField(ObjPtr<mirror::Object> o,
+ ObjPtr<mirror::Class> dst_class,
+ ArtField* f,
JValue* unboxed_value) {
DCHECK(f != nullptr);
return UnboxPrimitive(o, dst_class, f, unboxed_value);
}
-bool UnboxPrimitiveForResult(mirror::Object* o, mirror::Class* dst_class, JValue* unboxed_value) {
+bool UnboxPrimitiveForResult(ObjPtr<mirror::Object> o,
+ ObjPtr<mirror::Class> dst_class,
+ JValue* unboxed_value) {
return UnboxPrimitive(o, dst_class, nullptr, unboxed_value);
}
-mirror::Class* GetCallingClass(Thread* self, size_t num_frames) {
+ObjPtr<mirror::Class> GetCallingClass(Thread* self, size_t num_frames) {
NthCallerVisitor visitor(self, num_frames);
visitor.WalkStack();
return visitor.caller != nullptr ? visitor.caller->GetDeclaringClass() : nullptr;
}
-bool VerifyAccess(Thread* self, mirror::Object* obj, mirror::Class* declaring_class,
- uint32_t access_flags, mirror::Class** calling_class, size_t num_frames) {
+bool VerifyAccess(Thread* self,
+ ObjPtr<mirror::Object> obj,
+ ObjPtr<mirror::Class> declaring_class,
+ uint32_t access_flags,
+ ObjPtr<mirror::Class>* calling_class,
+ size_t num_frames) {
if ((access_flags & kAccPublic) != 0) {
return true;
}
- auto* klass = GetCallingClass(self, num_frames);
+ ObjPtr<mirror::Class> klass = GetCallingClass(self, num_frames);
if (UNLIKELY(klass == nullptr)) {
// The caller is an attached native thread.
return false;
@@ -864,10 +875,10 @@
return VerifyAccess(obj, declaring_class, access_flags, klass);
}
-bool VerifyAccess(mirror::Object* obj,
- mirror::Class* declaring_class,
+bool VerifyAccess(ObjPtr<mirror::Object> obj,
+ ObjPtr<mirror::Class> declaring_class,
uint32_t access_flags,
- mirror::Class* calling_class) {
+ ObjPtr<mirror::Class> calling_class) {
if (calling_class == declaring_class) {
return true;
}
@@ -877,16 +888,16 @@
}
if ((access_flags & kAccProtected) != 0) {
if (obj != nullptr && !obj->InstanceOf(calling_class) &&
- !declaring_class->IsInSamePackage(calling_class)) {
+ !declaring_class->IsInSamePackage(calling_class.Decode())) {
return false;
- } else if (declaring_class->IsAssignableFrom(calling_class)) {
+ } else if (declaring_class->IsAssignableFrom(calling_class.Decode())) {
return true;
}
}
- return declaring_class->IsInSamePackage(calling_class);
+ return declaring_class->IsInSamePackage(calling_class.Decode());
}
-void InvalidReceiverError(mirror::Object* o, mirror::Class* c) {
+void InvalidReceiverError(ObjPtr<mirror::Object> o, ObjPtr<mirror::Class> c) {
std::string expected_class_name(PrettyDescriptor(c));
std::string actual_class_name(PrettyTypeOf(o));
ThrowIllegalArgumentException(StringPrintf("Expected receiver of type %s, but got %s",
@@ -896,18 +907,18 @@
// This only works if there's one reference which points to the object in obj.
// Will need to be fixed if there's cases where it's not.
-void UpdateReference(Thread* self, jobject obj, mirror::Object* result) {
+void UpdateReference(Thread* self, jobject obj, ObjPtr<mirror::Object> result) {
IndirectRef ref = reinterpret_cast<IndirectRef>(obj);
IndirectRefKind kind = GetIndirectRefKind(ref);
if (kind == kLocal) {
- self->GetJniEnv()->locals.Update(obj, result);
+ self->GetJniEnv()->locals.Update(obj, result.Decode());
} else if (kind == kHandleScopeOrInvalid) {
LOG(FATAL) << "Unsupported UpdateReference for kind kHandleScopeOrInvalid";
} else if (kind == kGlobal) {
- self->GetJniEnv()->vm->UpdateGlobal(self, ref, result);
+ self->GetJniEnv()->vm->UpdateGlobal(self, ref, result.Decode());
} else {
DCHECK_EQ(kind, kWeakGlobal);
- self->GetJniEnv()->vm->UpdateWeakGlobal(self, ref, result);
+ self->GetJniEnv()->vm->UpdateWeakGlobal(self, ref, result.Decode());
}
}
diff --git a/runtime/reflection.h b/runtime/reflection.h
index 208b533..6e5ef71 100644
--- a/runtime/reflection.h
+++ b/runtime/reflection.h
@@ -19,6 +19,7 @@
#include "base/mutex.h"
#include "jni.h"
+#include "obj_ptr.h"
#include "primitive.h"
namespace art {
@@ -32,62 +33,85 @@
class ScopedObjectAccessAlreadyRunnable;
class ShadowFrame;
-mirror::Object* BoxPrimitive(Primitive::Type src_class, const JValue& value)
+ObjPtr<mirror::Object> BoxPrimitive(Primitive::Type src_class, const JValue& value)
REQUIRES_SHARED(Locks::mutator_lock_);
-bool UnboxPrimitiveForField(mirror::Object* o, mirror::Class* dst_class, ArtField* f,
+
+bool UnboxPrimitiveForField(ObjPtr<mirror::Object> o,
+ ObjPtr<mirror::Class> dst_class,
+ ArtField* f,
JValue* unboxed_value)
REQUIRES_SHARED(Locks::mutator_lock_);
-bool UnboxPrimitiveForResult(mirror::Object* o, mirror::Class* dst_class, JValue* unboxed_value)
+
+bool UnboxPrimitiveForResult(ObjPtr<mirror::Object> o,
+ ObjPtr<mirror::Class> dst_class,
+ JValue* unboxed_value)
REQUIRES_SHARED(Locks::mutator_lock_);
ALWAYS_INLINE bool ConvertPrimitiveValue(bool unbox_for_result,
- Primitive::Type src_class, Primitive::Type dst_class,
- const JValue& src, JValue* dst)
+ Primitive::Type src_class,
+ Primitive::Type dst_class,
+ const JValue& src,
+ JValue* dst)
REQUIRES_SHARED(Locks::mutator_lock_);
-JValue InvokeWithVarArgs(const ScopedObjectAccessAlreadyRunnable& soa, jobject obj, jmethodID mid,
+JValue InvokeWithVarArgs(const ScopedObjectAccessAlreadyRunnable& soa,
+ jobject obj,
+ jmethodID mid,
va_list args)
REQUIRES_SHARED(Locks::mutator_lock_);
-JValue InvokeWithJValues(const ScopedObjectAccessAlreadyRunnable& soa, jobject obj, jmethodID mid,
+JValue InvokeWithJValues(const ScopedObjectAccessAlreadyRunnable& soa,
+ jobject obj,
+ jmethodID mid,
jvalue* args)
REQUIRES_SHARED(Locks::mutator_lock_);
JValue InvokeVirtualOrInterfaceWithJValues(const ScopedObjectAccessAlreadyRunnable& soa,
- jobject obj, jmethodID mid, jvalue* args)
+ jobject obj,
+ jmethodID mid,
+ jvalue* args)
REQUIRES_SHARED(Locks::mutator_lock_);
JValue InvokeVirtualOrInterfaceWithVarArgs(const ScopedObjectAccessAlreadyRunnable& soa,
- jobject obj, jmethodID mid, va_list args)
+ jobject obj,
+ jmethodID mid,
+ va_list args)
REQUIRES_SHARED(Locks::mutator_lock_);
// num_frames is number of frames we look up for access check.
-jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa, jobject method, jobject receiver,
- jobject args, size_t num_frames = 1)
+jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa,
+ jobject method,
+ jobject receiver,
+ jobject args,
+ size_t num_frames = 1)
REQUIRES_SHARED(Locks::mutator_lock_);
-ALWAYS_INLINE bool VerifyObjectIsClass(mirror::Object* o, mirror::Class* c)
+ALWAYS_INLINE bool VerifyObjectIsClass(ObjPtr<mirror::Object> o, ObjPtr<mirror::Class> c)
REQUIRES_SHARED(Locks::mutator_lock_);
-bool VerifyAccess(Thread* self, mirror::Object* obj, mirror::Class* declaring_class,
- uint32_t access_flags, mirror::Class** calling_class, size_t num_frames)
+bool VerifyAccess(Thread* self,
+ ObjPtr<mirror::Object> obj,
+ ObjPtr<mirror::Class> declaring_class,
+ uint32_t access_flags,
+ ObjPtr<mirror::Class>* calling_class,
+ size_t num_frames)
REQUIRES_SHARED(Locks::mutator_lock_);
// This version takes a known calling class.
-bool VerifyAccess(mirror::Object* obj,
- mirror::Class* declaring_class,
+bool VerifyAccess(ObjPtr<mirror::Object> obj,
+ ObjPtr<mirror::Class> declaring_class,
uint32_t access_flags,
- mirror::Class* calling_class)
+ ObjPtr<mirror::Class> calling_class)
REQUIRES_SHARED(Locks::mutator_lock_);
// Get the calling class by using a stack visitor, may return null for unattached native threads.
-mirror::Class* GetCallingClass(Thread* self, size_t num_frames)
+ObjPtr<mirror::Class> GetCallingClass(Thread* self, size_t num_frames)
REQUIRES_SHARED(Locks::mutator_lock_);
-void InvalidReceiverError(mirror::Object* o, mirror::Class* c)
+void InvalidReceiverError(ObjPtr<mirror::Object> o, ObjPtr<mirror::Class> c)
REQUIRES_SHARED(Locks::mutator_lock_);
-void UpdateReference(Thread* self, jobject obj, mirror::Object* result)
+void UpdateReference(Thread* self, jobject obj, ObjPtr<mirror::Object> result)
REQUIRES_SHARED(Locks::mutator_lock_);
} // namespace art
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 2be3b52..5bb38f5 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -255,7 +255,7 @@
// This can't be called from the Heap destructor below because it
// could call RosAlloc::InspectAll() which needs the thread_list
// to be still alive.
- heap_->DumpGcPerformanceInfo(LOG(INFO));
+ heap_->DumpGcPerformanceInfo(LOG_STREAM(INFO));
}
Thread* self = Thread::Current();
@@ -433,14 +433,14 @@
// Many people have difficulty distinguish aborts from crashes,
// so be explicit.
AbortState state;
- LOG(INTERNAL_FATAL) << Dumpable<AbortState>(state);
+ LOG(FATAL_WITHOUT_ABORT) << Dumpable<AbortState>(state);
// Call the abort hook if we have one.
if (Runtime::Current() != nullptr && Runtime::Current()->abort_ != nullptr) {
- LOG(INTERNAL_FATAL) << "Calling abort hook...";
+ LOG(FATAL_WITHOUT_ABORT) << "Calling abort hook...";
Runtime::Current()->abort_();
// notreached
- LOG(INTERNAL_FATAL) << "Unexpectedly returned from abort hook!";
+ LOG(FATAL_WITHOUT_ABORT) << "Unexpectedly returned from abort hook!";
}
#if defined(__GLIBC__)
diff --git a/runtime/runtime_android.cc b/runtime/runtime_android.cc
index 33600dd..aed6a2b 100644
--- a/runtime/runtime_android.cc
+++ b/runtime/runtime_android.cc
@@ -34,7 +34,10 @@
void HandleUnexpectedSignal(int signal_number, siginfo_t* info, void* raw_context) {
static bool handling_unexpected_signal = false;
if (handling_unexpected_signal) {
- LogMessage::LogLine(__FILE__, __LINE__, INTERNAL_FATAL, "HandleUnexpectedSignal reentered\n");
+ LogHelper::LogLineLowStack(__FILE__,
+ __LINE__,
+ ::android::base::FATAL_WITHOUT_ABORT,
+ "HandleUnexpectedSignal reentered\n");
_exit(1);
}
handling_unexpected_signal = true;
@@ -44,11 +47,11 @@
Runtime* runtime = Runtime::Current();
if (runtime != nullptr) {
// Print this out first in case DumpObject faults.
- LOG(INTERNAL_FATAL) << "Fault message: " << runtime->GetFaultMessage();
+ LOG(FATAL_WITHOUT_ABORT) << "Fault message: " << runtime->GetFaultMessage();
gc::Heap* heap = runtime->GetHeap();
if (kDumpHeapObjectOnSigsevg && heap != nullptr && info != nullptr) {
- LOG(INTERNAL_FATAL) << "Dump heap object at fault address: ";
- heap->DumpObject(LOG(INTERNAL_FATAL), reinterpret_cast<mirror::Object*>(info->si_addr));
+ LOG(FATAL_WITHOUT_ABORT) << "Dump heap object at fault address: ";
+ heap->DumpObject(LOG_STREAM(FATAL_WITHOUT_ABORT), reinterpret_cast<mirror::Object*>(info->si_addr));
}
}
// Run the old signal handler.
diff --git a/runtime/runtime_linux.cc b/runtime/runtime_linux.cc
index 60ebabc..cee73e1 100644
--- a/runtime/runtime_linux.cc
+++ b/runtime/runtime_linux.cc
@@ -309,7 +309,10 @@
void HandleUnexpectedSignal(int signal_number, siginfo_t* info, void* raw_context) {
static bool handlingUnexpectedSignal = false;
if (handlingUnexpectedSignal) {
- LogMessage::LogLine(__FILE__, __LINE__, INTERNAL_FATAL, "HandleUnexpectedSignal reentered\n");
+ LogHelper::LogLineLowStack(__FILE__,
+ __LINE__,
+ ::android::base::FATAL_WITHOUT_ABORT,
+ "HandleUnexpectedSignal reentered\n");
if (IsTimeoutSignal(signal_number)) {
// Ignore a recursive timeout.
return;
@@ -334,7 +337,7 @@
UContext thread_context(raw_context);
Backtrace thread_backtrace(raw_context);
- LOG(INTERNAL_FATAL) << "*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\n"
+ LOG(FATAL_WITHOUT_ABORT) << "*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\n"
<< StringPrintf("Fatal signal %d (%s), code %d (%s)",
signal_number, GetSignalName(signal_number),
info->si_code,
@@ -346,7 +349,7 @@
<< "Registers:\n" << Dumpable<UContext>(thread_context) << "\n"
<< "Backtrace:\n" << Dumpable<Backtrace>(thread_backtrace);
if (kIsDebugBuild && signal_number == SIGSEGV) {
- PrintFileToLog("/proc/self/maps", LogSeverity::INTERNAL_FATAL);
+ PrintFileToLog("/proc/self/maps", LogSeverity::FATAL_WITHOUT_ABORT);
}
Runtime* runtime = Runtime::Current();
if (runtime != nullptr) {
@@ -354,17 +357,17 @@
// Special timeout signal. Try to dump all threads.
// Note: Do not use DumpForSigQuit, as that might disable native unwind, but the native parts
// are of value here.
- runtime->GetThreadList()->Dump(LOG(INTERNAL_FATAL), kDumpNativeStackOnTimeout);
+ runtime->GetThreadList()->Dump(LOG_STREAM(FATAL_WITHOUT_ABORT), kDumpNativeStackOnTimeout);
}
gc::Heap* heap = runtime->GetHeap();
- LOG(INTERNAL_FATAL) << "Fault message: " << runtime->GetFaultMessage();
+ LOG(FATAL_WITHOUT_ABORT) << "Fault message: " << runtime->GetFaultMessage();
if (kDumpHeapObjectOnSigsevg && heap != nullptr && info != nullptr) {
- LOG(INTERNAL_FATAL) << "Dump heap object at fault address: ";
- heap->DumpObject(LOG(INTERNAL_FATAL), reinterpret_cast<mirror::Object*>(info->si_addr));
+ LOG(FATAL_WITHOUT_ABORT) << "Dump heap object at fault address: ";
+ heap->DumpObject(LOG_STREAM(FATAL_WITHOUT_ABORT), reinterpret_cast<mirror::Object*>(info->si_addr));
}
}
if (getenv("debug_db_uid") != nullptr || getenv("art_wait_for_gdb_on_crash") != nullptr) {
- LOG(INTERNAL_FATAL) << "********************************************************\n"
+ LOG(FATAL_WITHOUT_ABORT) << "********************************************************\n"
<< "* Process " << getpid() << " thread " << tid << " \"" << thread_name
<< "\""
<< " has been suspended while crashing.\n"
diff --git a/runtime/signal_catcher.cc b/runtime/signal_catcher.cc
index 6cb7950..848c0e3 100644
--- a/runtime/signal_catcher.cc
+++ b/runtime/signal_catcher.cc
@@ -172,7 +172,7 @@
LOG(INFO) << *self << ": reacting to signal " << signal_number;
// If anyone's holding locks (which might prevent us from getting back into state Runnable), say so...
- Runtime::Current()->DumpLockHolders(LOG(INFO));
+ Runtime::Current()->DumpLockHolders(LOG_STREAM(INFO));
}
return signal_number;
diff --git a/runtime/simulator/Android.bp b/runtime/simulator/Android.bp
index 49322fc..03e3f15 100644
--- a/runtime/simulator/Android.bp
+++ b/runtime/simulator/Android.bp
@@ -25,6 +25,7 @@
"code_simulator_arm64.cc",
],
shared_libs: [
+ "libbase",
"liblog",
],
cflags: ["-DVIXL_INCLUDE_SIMULATOR_AARCH64"],
diff --git a/runtime/thread-inl.h b/runtime/thread-inl.h
index 216d8a7..bb6eb79 100644
--- a/runtime/thread-inl.h
+++ b/runtime/thread-inl.h
@@ -59,6 +59,9 @@
if (UNLIKELY(TestAllFlags())) {
CheckSuspend();
}
+ // Invalidate the current thread's object pointers (ObjPtr) to catch possible moving GC bugs due
+ // to missing handles.
+ PoisonObjectPointers();
}
inline void Thread::CheckSuspend() {
@@ -172,6 +175,9 @@
inline void Thread::TransitionFromRunnableToSuspended(ThreadState new_state) {
AssertThreadSuspensionIsAllowable();
+ if (kIsDebugBuild) {
+ PoisonObjectPointers();
+ }
DCHECK_EQ(this, Thread::Current());
// Change to non-runnable state, thereby appearing suspended to the system.
TransitionToSuspendedAndRunCheckpoints(new_state);
@@ -302,6 +308,12 @@
tlsPtr_.thread_local_alloc_stack_top = nullptr;
}
+inline void Thread::PoisonObjectPointersIfDebug() {
+ if (kIsDebugBuild) {
+ Thread::Current()->PoisonObjectPointers();
+ }
+}
+
} // namespace art
#endif // ART_RUNTIME_THREAD_INL_H_
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 8940354..d0ea2d7 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -127,43 +127,6 @@
InitEntryPoints(&tlsPtr_.jni_entrypoints, &tlsPtr_.quick_entrypoints);
}
-void Thread::InitStringEntryPoints() {
- ScopedObjectAccess soa(this);
- QuickEntryPoints* qpoints = &tlsPtr_.quick_entrypoints;
- qpoints->pNewEmptyString = reinterpret_cast<void(*)()>(
- soa.DecodeMethod(WellKnownClasses::java_lang_StringFactory_newEmptyString));
- qpoints->pNewStringFromBytes_B = reinterpret_cast<void(*)()>(
- soa.DecodeMethod(WellKnownClasses::java_lang_StringFactory_newStringFromBytes_B));
- qpoints->pNewStringFromBytes_BI = reinterpret_cast<void(*)()>(
- soa.DecodeMethod(WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BI));
- qpoints->pNewStringFromBytes_BII = reinterpret_cast<void(*)()>(
- soa.DecodeMethod(WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BII));
- qpoints->pNewStringFromBytes_BIII = reinterpret_cast<void(*)()>(
- soa.DecodeMethod(WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BIII));
- qpoints->pNewStringFromBytes_BIIString = reinterpret_cast<void(*)()>(
- soa.DecodeMethod(WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BIIString));
- qpoints->pNewStringFromBytes_BString = reinterpret_cast<void(*)()>(
- soa.DecodeMethod(WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BString));
- qpoints->pNewStringFromBytes_BIICharset = reinterpret_cast<void(*)()>(
- soa.DecodeMethod(WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BIICharset));
- qpoints->pNewStringFromBytes_BCharset = reinterpret_cast<void(*)()>(
- soa.DecodeMethod(WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BCharset));
- qpoints->pNewStringFromChars_C = reinterpret_cast<void(*)()>(
- soa.DecodeMethod(WellKnownClasses::java_lang_StringFactory_newStringFromChars_C));
- qpoints->pNewStringFromChars_CII = reinterpret_cast<void(*)()>(
- soa.DecodeMethod(WellKnownClasses::java_lang_StringFactory_newStringFromChars_CII));
- qpoints->pNewStringFromChars_IIC = reinterpret_cast<void(*)()>(
- soa.DecodeMethod(WellKnownClasses::java_lang_StringFactory_newStringFromChars_IIC));
- qpoints->pNewStringFromCodePoints = reinterpret_cast<void(*)()>(
- soa.DecodeMethod(WellKnownClasses::java_lang_StringFactory_newStringFromCodePoints));
- qpoints->pNewStringFromString = reinterpret_cast<void(*)()>(
- soa.DecodeMethod(WellKnownClasses::java_lang_StringFactory_newStringFromString));
- qpoints->pNewStringFromStringBuffer = reinterpret_cast<void(*)()>(
- soa.DecodeMethod(WellKnownClasses::java_lang_StringFactory_newStringFromStringBuffer));
- qpoints->pNewStringFromStringBuilder = reinterpret_cast<void(*)()>(
- soa.DecodeMethod(WellKnownClasses::java_lang_StringFactory_newStringFromStringBuilder));
-}
-
void Thread::ResetQuickAllocEntryPointsForThread() {
ResetQuickAllocEntryPoints(&tlsPtr_.quick_entrypoints);
}
@@ -609,7 +572,7 @@
}
VLOG(threads) << "Creating native thread for " << thread_name;
- self->Dump(LOG(INFO));
+ self->Dump(LOG_STREAM(INFO));
}
Runtime* runtime = Runtime::Current();
@@ -804,7 +767,7 @@
VLOG(threads) << "Attaching unnamed thread.";
}
ScopedObjectAccess soa(self);
- self->Dump(LOG(INFO));
+ self->Dump(LOG_STREAM(INFO));
}
{
@@ -911,8 +874,10 @@
+ 4 * KB;
if (read_stack_size <= min_stack) {
// Note, as we know the stack is small, avoid operations that could use a lot of stack.
- LogMessage::LogLineLowStack(__PRETTY_FUNCTION__, __LINE__, ERROR,
- "Attempt to attach a thread with a too-small stack");
+ LogHelper::LogLineLowStack(__PRETTY_FUNCTION__,
+ __LINE__,
+ ::android::base::ERROR,
+ "Attempt to attach a thread with a too-small stack");
return false;
}
@@ -2382,7 +2347,7 @@
ThrowNewException("Ljava/lang/OutOfMemoryError;", msg);
tls32_.throwing_OutOfMemoryError = false;
} else {
- Dump(LOG(WARNING)); // The pre-allocated OOME has no stack, so help out and log one.
+ Dump(LOG_STREAM(WARNING)); // The pre-allocated OOME has no stack, so help out and log one.
SetException(Runtime::Current()->GetPreAllocatedOutOfMemoryError());
}
}
@@ -2775,16 +2740,16 @@
bool failed = false;
if (!space->GetLiveBitmap()->Test(klass)) {
failed = true;
- LOG(INTERNAL_FATAL) << "Unmarked object in image " << *space;
+ LOG(FATAL_WITHOUT_ABORT) << "Unmarked object in image " << *space;
} else if (!heap->GetLiveBitmap()->Test(klass)) {
failed = true;
- LOG(INTERNAL_FATAL) << "Unmarked object in image through live bitmap " << *space;
+ LOG(FATAL_WITHOUT_ABORT) << "Unmarked object in image through live bitmap " << *space;
}
if (failed) {
- GetThread()->Dump(LOG(INTERNAL_FATAL));
- space->AsImageSpace()->DumpSections(LOG(INTERNAL_FATAL));
- LOG(INTERNAL_FATAL) << "Method@" << method->GetDexMethodIndex() << ":" << method
- << " klass@" << klass;
+ GetThread()->Dump(LOG_STREAM(FATAL_WITHOUT_ABORT));
+ space->AsImageSpace()->DumpSections(LOG_STREAM(FATAL_WITHOUT_ABORT));
+ LOG(FATAL_WITHOUT_ABORT) << "Method@" << method->GetDexMethodIndex() << ":" << method
+ << " klass@" << klass;
// Pretty info last in case it crashes.
LOG(FATAL) << "Method " << PrettyMethod(method) << " klass " << PrettyClass(klass);
}
@@ -2838,7 +2803,7 @@
if (kIsDebugBuild && ref_addr == nullptr) {
std::string thread_name;
GetThread()->GetThreadName(thread_name);
- LOG(INTERNAL_FATAL) << "On thread " << thread_name;
+ LOG(FATAL_WITHOUT_ABORT) << "On thread " << thread_name;
DescribeStack(GetThread());
LOG(FATAL) << "Found an unsaved callee-save register " << i << " (null GPRAddress) "
<< "set in register_mask=" << register_mask << " at " << DescribeLocation();
@@ -2953,7 +2918,7 @@
// However, we seem to have already extended to use the full stack.
LOG(ERROR) << "Need to increase kStackOverflowReservedBytes (currently "
<< GetStackOverflowReservedBytes(kRuntimeISA) << ")?";
- DumpStack(LOG(ERROR));
+ DumpStack(LOG_STREAM(ERROR));
LOG(FATAL) << "Recursive stack overflow.";
}
diff --git a/runtime/thread.h b/runtime/thread.h
index 016c2bc..55f1489 100644
--- a/runtime/thread.h
+++ b/runtime/thread.h
@@ -471,6 +471,16 @@
}
void Notify() REQUIRES(!*wait_mutex_);
+ ALWAYS_INLINE void PoisonObjectPointers() {
+ ++poison_object_cookie_;
+ }
+
+ ALWAYS_INLINE static void PoisonObjectPointersIfDebug();
+
+ ALWAYS_INLINE uintptr_t GetPoisonObjectCookie() const {
+ return poison_object_cookie_;
+ }
+
private:
void NotifyLocked(Thread* self) REQUIRES(wait_mutex_);
@@ -1528,6 +1538,9 @@
// Debug disable read barrier count, only is checked for debug builds and only in the runtime.
uint8_t debug_disallow_read_barrier_ = 0;
+ // Note that it is not in the packed struct, may not be accessed for cross compilation.
+ uintptr_t poison_object_cookie_ = 0;
+
// Pending extra checkpoints if checkpoint_function_ is already used.
std::list<Closure*> checkpoint_overflow_ GUARDED_BY(Locks::thread_suspend_count_lock_);
diff --git a/runtime/thread_list.cc b/runtime/thread_list.cc
index 5e6c8a4..17c6c2e 100644
--- a/runtime/thread_list.cc
+++ b/runtime/thread_list.cc
@@ -214,7 +214,7 @@
bool timed_out = barrier_.Increment(self, threads_running_checkpoint, kDumpWaitTimeout);
if (timed_out) {
// Avoid a recursive abort.
- LOG((kIsDebugBuild && (gAborting == 0)) ? FATAL : ERROR)
+ LOG((kIsDebugBuild && (gAborting == 0)) ? ::android::base::FATAL : ::android::base::ERROR)
<< "Unexpected time out during dump checkpoint.";
}
}
@@ -441,8 +441,8 @@
// runnable (both cases waiting inside Thread::TransitionFromSuspendedToRunnable), or waiting
// for the thread flip to end at the JNI critical section entry (kWaitingForGcThreadFlip),
ThreadState state = thread->GetState();
- if (state == kWaitingForGcThreadFlip ||
- thread->IsTransitioningToRunnable()) {
+ if ((state == kWaitingForGcThreadFlip || thread->IsTransitioningToRunnable()) &&
+ thread->GetSuspendCount() == 1) {
// The thread will resume right after the broadcast.
thread->ModifySuspendCount(self, -1, nullptr, false);
++runnable_thread_count;
@@ -628,7 +628,8 @@
// EAGAIN and EINTR both indicate a spurious failure, try again from the beginning.
if ((errno != EAGAIN) && (errno != EINTR)) {
if (errno == ETIMEDOUT) {
- LOG(kIsDebugBuild ? FATAL : ERROR) << "Unexpected time out during suspend all.";
+ LOG(kIsDebugBuild ? ::android::base::FATAL : ::android::base::ERROR)
+ << "Unexpected time out during suspend all.";
} else {
PLOG(FATAL) << "futex wait failed for SuspendAllInternal()";
}
@@ -775,7 +776,10 @@
// ThreadList::WaitForOtherNonDaemonThreadsToExit.
suspended_thread->ModifySuspendCount(soa.Self(), -1, nullptr, debug_suspension);
}
- ThreadSuspendByPeerWarning(self, WARNING, "No such thread for suspend", peer);
+ ThreadSuspendByPeerWarning(self,
+ ::android::base::WARNING,
+ "No such thread for suspend",
+ peer);
return nullptr;
}
if (!Contains(thread)) {
@@ -822,7 +826,10 @@
}
const uint64_t total_delay = NanoTime() - start_time;
if (total_delay >= MsToNs(kThreadSuspendTimeoutMs)) {
- ThreadSuspendByPeerWarning(self, FATAL, "Thread suspension timed out", peer);
+ ThreadSuspendByPeerWarning(self,
+ ::android::base::FATAL,
+ "Thread suspension timed out",
+ peer);
if (suspended_thread != nullptr) {
CHECK_EQ(suspended_thread, thread);
suspended_thread->ModifySuspendCount(soa.Self(), -1, nullptr, debug_suspension);
@@ -882,7 +889,9 @@
CHECK(suspended_thread == nullptr) << "Suspended thread " << suspended_thread
<< " no longer in thread list";
// There's a race in inflating a lock and the owner giving up ownership and then dying.
- ThreadSuspendByThreadIdWarning(WARNING, "No such thread id for suspend", thread_id);
+ ThreadSuspendByThreadIdWarning(::android::base::WARNING,
+ "No such thread id for suspend",
+ thread_id);
return nullptr;
}
VLOG(threads) << "SuspendThreadByThreadId found thread: " << *thread;
@@ -923,7 +932,9 @@
}
const uint64_t total_delay = NanoTime() - start_time;
if (total_delay >= MsToNs(kThreadSuspendTimeoutMs)) {
- ThreadSuspendByThreadIdWarning(WARNING, "Thread suspension timed out", thread_id);
+ ThreadSuspendByThreadIdWarning(::android::base::WARNING,
+ "Thread suspension timed out",
+ thread_id);
if (suspended_thread != nullptr) {
thread->ModifySuspendCount(soa.Self(), -1, nullptr, debug_suspension);
}
diff --git a/runtime/utils.cc b/runtime/utils.cc
index b52e2f2..0803ca7 100644
--- a/runtime/utils.cc
+++ b/runtime/utils.cc
@@ -37,6 +37,7 @@
#include "mirror/object_array-inl.h"
#include "mirror/string.h"
#include "oat_quick_method_header.h"
+#include "obj_ptr-inl.h"
#include "os.h"
#include "scoped_thread_state_change.h"
#include "utf-inl.h"
@@ -270,14 +271,14 @@
}
}
-std::string PrettyDescriptor(mirror::String* java_descriptor) {
+std::string PrettyStringDescriptor(ObjPtr<mirror::String> java_descriptor) {
if (java_descriptor == nullptr) {
return "null";
}
return PrettyDescriptor(java_descriptor->ToModifiedUtf8().c_str());
}
-std::string PrettyDescriptor(mirror::Class* klass) {
+std::string PrettyDescriptor(ObjPtr<mirror::Class> klass) {
if (klass == nullptr) {
return "null";
}
@@ -456,7 +457,7 @@
return result;
}
-std::string PrettyTypeOf(mirror::Object* obj) {
+std::string PrettyTypeOf(ObjPtr<mirror::Object> obj) {
if (obj == nullptr) {
return "null";
}
@@ -471,7 +472,7 @@
return result;
}
-std::string PrettyClass(mirror::Class* c) {
+std::string PrettyClass(ObjPtr<mirror::Class> c) {
if (c == nullptr) {
return "null";
}
@@ -482,7 +483,7 @@
return result;
}
-std::string PrettyClassAndClassLoader(mirror::Class* c) {
+std::string PrettyClassAndClassLoader(ObjPtr<mirror::Class> c) {
if (c == nullptr) {
return "null";
}
diff --git a/runtime/utils.h b/runtime/utils.h
index e65b947..ea9e8f7 100644
--- a/runtime/utils.h
+++ b/runtime/utils.h
@@ -33,6 +33,7 @@
#include "base/mutex.h"
#include "base/stringpiece.h"
#include "globals.h"
+#include "obj_ptr.h"
#include "primitive.h"
class BacktraceMap;
@@ -135,10 +136,10 @@
// Returns a human-readable equivalent of 'descriptor'. So "I" would be "int",
// "[[I" would be "int[][]", "[Ljava/lang/String;" would be
// "java.lang.String[]", and so forth.
-std::string PrettyDescriptor(mirror::String* descriptor)
+std::string PrettyStringDescriptor(ObjPtr<mirror::String> descriptor)
REQUIRES_SHARED(Locks::mutator_lock_);
std::string PrettyDescriptor(const char* descriptor);
-std::string PrettyDescriptor(mirror::Class* klass)
+std::string PrettyDescriptor(ObjPtr<mirror::Class> klass)
REQUIRES_SHARED(Locks::mutator_lock_);
std::string PrettyDescriptor(Primitive::Type type);
@@ -158,7 +159,7 @@
// So given an instance of java.lang.String, the output would
// be "java.lang.String". Given an array of int, the output would be "int[]".
// Given String.class, the output would be "java.lang.Class<java.lang.String>".
-std::string PrettyTypeOf(mirror::Object* obj)
+std::string PrettyTypeOf(ObjPtr<mirror::Object> obj)
REQUIRES_SHARED(Locks::mutator_lock_);
// Returns a human-readable form of the type at an index in the specified dex file.
@@ -167,11 +168,11 @@
// Returns a human-readable form of the name of the given class.
// Given String.class, the output would be "java.lang.Class<java.lang.String>".
-std::string PrettyClass(mirror::Class* c)
+std::string PrettyClass(ObjPtr<mirror::Class> c)
REQUIRES_SHARED(Locks::mutator_lock_);
// Returns a human-readable form of the name of the given class with its class loader.
-std::string PrettyClassAndClassLoader(mirror::Class* c)
+std::string PrettyClassAndClassLoader(ObjPtr<mirror::Class> c)
REQUIRES_SHARED(Locks::mutator_lock_);
// Returns a human-readable version of the Java part of the access flags, e.g., "private static "
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc
index abd741c..13ef043 100644
--- a/runtime/verifier/method_verifier.cc
+++ b/runtime/verifier/method_verifier.cc
@@ -434,14 +434,15 @@
severity = LogSeverity::WARNING;
break;
case HardFailLogMode::kLogInternalFatal:
- severity = LogSeverity::INTERNAL_FATAL;
+ severity = LogSeverity::FATAL_WITHOUT_ABORT;
break;
default:
LOG(FATAL) << "Unsupported log-level " << static_cast<uint32_t>(log_level);
UNREACHABLE();
}
- verifier.DumpFailures(LOG(severity) << "Verification error in "
- << PrettyMethod(method_idx, *dex_file) << "\n");
+ verifier.DumpFailures(LOG_STREAM(severity) << "Verification error in "
+ << PrettyMethod(method_idx, *dex_file)
+ << "\n");
}
if (hard_failure_msg != nullptr) {
CHECK(!verifier.failure_messages_.empty());
diff --git a/runtime/verifier/verifier_log_mode.h b/runtime/verifier/verifier_log_mode.h
index 3744b9b..e83d174 100644
--- a/runtime/verifier/verifier_log_mode.h
+++ b/runtime/verifier/verifier_log_mode.h
@@ -24,7 +24,7 @@
kLogNone, // Don't log hard failures at all.
kLogVerbose, // Log with severity VERBOSE.
kLogWarning, // Log with severity WARNING.
- kLogInternalFatal, // Log with severity INTERNAL_FATAL
+ kLogInternalFatal, // Log with severity FATAL_WITHOUT_ABORT
};
} // namespace verifier
diff --git a/runtime/well_known_classes.cc b/runtime/well_known_classes.cc
index 16c7f77..e5216fb 100644
--- a/runtime/well_known_classes.cc
+++ b/runtime/well_known_classes.cc
@@ -21,6 +21,7 @@
#include <sstream>
#include "base/logging.h"
+#include "entrypoints/quick/quick_entrypoints_enum.h"
#include "mirror/class.h"
#include "mirror/throwable.h"
#include "ScopedLocalRef.h"
@@ -52,6 +53,8 @@
jclass WellKnownClasses::java_lang_reflect_Executable;
jclass WellKnownClasses::java_lang_reflect_Field;
jclass WellKnownClasses::java_lang_reflect_Method;
+jclass WellKnownClasses::java_lang_reflect_Parameter;
+jclass WellKnownClasses::java_lang_reflect_Parameter__array;
jclass WellKnownClasses::java_lang_reflect_Proxy;
jclass WellKnownClasses::java_lang_RuntimeException;
jclass WellKnownClasses::java_lang_StackOverflowError;
@@ -86,41 +89,10 @@
jmethodID WellKnownClasses::java_lang_Long_valueOf;
jmethodID WellKnownClasses::java_lang_ref_FinalizerReference_add;
jmethodID WellKnownClasses::java_lang_ref_ReferenceQueue_add;
+jmethodID WellKnownClasses::java_lang_reflect_Parameter_init;
jmethodID WellKnownClasses::java_lang_reflect_Proxy_invoke;
jmethodID WellKnownClasses::java_lang_Runtime_nativeLoad;
jmethodID WellKnownClasses::java_lang_Short_valueOf;
-jmethodID WellKnownClasses::java_lang_String_init;
-jmethodID WellKnownClasses::java_lang_String_init_B;
-jmethodID WellKnownClasses::java_lang_String_init_BI;
-jmethodID WellKnownClasses::java_lang_String_init_BII;
-jmethodID WellKnownClasses::java_lang_String_init_BIII;
-jmethodID WellKnownClasses::java_lang_String_init_BIIString;
-jmethodID WellKnownClasses::java_lang_String_init_BString;
-jmethodID WellKnownClasses::java_lang_String_init_BIICharset;
-jmethodID WellKnownClasses::java_lang_String_init_BCharset;
-jmethodID WellKnownClasses::java_lang_String_init_C;
-jmethodID WellKnownClasses::java_lang_String_init_CII;
-jmethodID WellKnownClasses::java_lang_String_init_IIC;
-jmethodID WellKnownClasses::java_lang_String_init_String;
-jmethodID WellKnownClasses::java_lang_String_init_StringBuffer;
-jmethodID WellKnownClasses::java_lang_String_init_III;
-jmethodID WellKnownClasses::java_lang_String_init_StringBuilder;
-jmethodID WellKnownClasses::java_lang_StringFactory_newEmptyString;
-jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromBytes_B;
-jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BI;
-jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BII;
-jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BIII;
-jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BIIString;
-jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BString;
-jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BIICharset;
-jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BCharset;
-jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromChars_C;
-jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromChars_CII;
-jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromChars_IIC;
-jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromString;
-jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromStringBuffer;
-jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromCodePoints;
-jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromStringBuilder;
jmethodID WellKnownClasses::java_lang_System_runFinalization = nullptr;
jmethodID WellKnownClasses::java_lang_Thread_dispatchUncaughtException;
jmethodID WellKnownClasses::java_lang_Thread_init;
@@ -182,7 +154,7 @@
if (fid == nullptr) {
ScopedObjectAccess soa(env);
if (soa.Self()->IsExceptionPending()) {
- LOG(INTERNAL_FATAL) << soa.Self()->GetException()->Dump();
+ LOG(FATAL_WITHOUT_ABORT) << soa.Self()->GetException()->Dump();
}
std::ostringstream os;
WellKnownClasses::ToClass(c)->DumpClass(os, mirror::Class::kDumpClassFullDetail);
@@ -199,7 +171,7 @@
if (mid == nullptr) {
ScopedObjectAccess soa(env);
if (soa.Self()->IsExceptionPending()) {
- LOG(INTERNAL_FATAL) << soa.Self()->GetException()->Dump();
+ LOG(FATAL_WITHOUT_ABORT) << soa.Self()->GetException()->Dump();
}
std::ostringstream os;
WellKnownClasses::ToClass(c)->DumpClass(os, mirror::Class::kDumpClassFullDetail);
@@ -215,6 +187,76 @@
StringPrintf("(%c)L%s;", prim_name, boxed_name).c_str());
}
+#define STRING_INIT_LIST(V) \
+ V(java_lang_String_init, "()V", newEmptyString, "newEmptyString", "()Ljava/lang/String;", NewEmptyString) \
+ V(java_lang_String_init_B, "([B)V", newStringFromBytes_B, "newStringFromBytes", "([B)Ljava/lang/String;", NewStringFromBytes_B) \
+ V(java_lang_String_init_BI, "([BI)V", newStringFromBytes_BI, "newStringFromBytes", "([BI)Ljava/lang/String;", NewStringFromBytes_BI) \
+ V(java_lang_String_init_BII, "([BII)V", newStringFromBytes_BII, "newStringFromBytes", "([BII)Ljava/lang/String;", NewStringFromBytes_BII) \
+ V(java_lang_String_init_BIII, "([BIII)V", newStringFromBytes_BIII, "newStringFromBytes", "([BIII)Ljava/lang/String;", NewStringFromBytes_BIII) \
+ V(java_lang_String_init_BIIString, "([BIILjava/lang/String;)V", newStringFromBytes_BIIString, "newStringFromBytes", "([BIILjava/lang/String;)Ljava/lang/String;", NewStringFromBytes_BIIString) \
+ V(java_lang_String_init_BString, "([BLjava/lang/String;)V", newStringFromBytes_BString, "newStringFromBytes", "([BLjava/lang/String;)Ljava/lang/String;", NewStringFromBytes_BString) \
+ V(java_lang_String_init_BIICharset, "([BIILjava/nio/charset/Charset;)V", newStringFromBytes_BIICharset, "newStringFromBytes", "([BIILjava/nio/charset/Charset;)Ljava/lang/String;", NewStringFromBytes_BIICharset) \
+ V(java_lang_String_init_BCharset, "([BLjava/nio/charset/Charset;)V", newStringFromBytes_BCharset, "newStringFromBytes", "([BLjava/nio/charset/Charset;)Ljava/lang/String;", NewStringFromBytes_BCharset) \
+ V(java_lang_String_init_C, "([C)V", newStringFromChars_C, "newStringFromChars", "([C)Ljava/lang/String;", NewStringFromChars_C) \
+ V(java_lang_String_init_CII, "([CII)V", newStringFromChars_CII, "newStringFromChars", "([CII)Ljava/lang/String;", NewStringFromChars_CII) \
+ V(java_lang_String_init_IIC, "(II[C)V", newStringFromChars_IIC, "newStringFromChars", "(II[C)Ljava/lang/String;", NewStringFromChars_IIC) \
+ V(java_lang_String_init_String, "(Ljava/lang/String;)V", newStringFromString, "newStringFromString", "(Ljava/lang/String;)Ljava/lang/String;", NewStringFromString) \
+ V(java_lang_String_init_StringBuffer, "(Ljava/lang/StringBuffer;)V", newStringFromStringBuffer, "newStringFromStringBuffer", "(Ljava/lang/StringBuffer;)Ljava/lang/String;", NewStringFromStringBuffer) \
+ V(java_lang_String_init_III, "([III)V", newStringFromCodePoints, "newStringFromCodePoints", "([III)Ljava/lang/String;", NewStringFromCodePoints) \
+ V(java_lang_String_init_StringBuilder, "(Ljava/lang/StringBuilder;)V", newStringFromStringBuilder, "newStringFromStringBuilder", "(Ljava/lang/StringBuilder;)Ljava/lang/String;", NewStringFromStringBuilder) \
+
+#define STATIC_STRING_INIT(init_runtime_name, init_signature, new_runtime_name, ...) \
+ static ArtMethod* init_runtime_name; \
+ static ArtMethod* new_runtime_name;
+ STRING_INIT_LIST(STATIC_STRING_INIT)
+#undef STATIC_STRING_INIT
+
+void WellKnownClasses::InitStringInit(JNIEnv* env) {
+ ScopedObjectAccess soa(Thread::Current());
+ #define LOAD_STRING_INIT(init_runtime_name, init_signature, new_runtime_name, \
+ new_java_name, new_signature, ...) \
+ init_runtime_name = soa.DecodeMethod( \
+ CacheMethod(env, java_lang_String, false, "<init>", init_signature)); \
+ new_runtime_name = soa.DecodeMethod( \
+ CacheMethod(env, java_lang_StringFactory, true, new_java_name, new_signature));
+ STRING_INIT_LIST(LOAD_STRING_INIT)
+ #undef LOAD_STRING_INIT
+}
+
+void Thread::InitStringEntryPoints() {
+ QuickEntryPoints* qpoints = &tlsPtr_.quick_entrypoints;
+ #define SET_ENTRY_POINT(init_runtime_name, init_signature, new_runtime_name, \
+ new_java_name, new_signature, entry_point_name) \
+ qpoints->p ## entry_point_name = reinterpret_cast<void(*)()>(new_runtime_name);
+ STRING_INIT_LIST(SET_ENTRY_POINT)
+ #undef SET_ENTRY_POINT
+}
+
+ArtMethod* WellKnownClasses::StringInitToStringFactory(ArtMethod* string_init) {
+ #define TO_STRING_FACTORY(init_runtime_name, init_signature, new_runtime_name, \
+ new_java_name, new_signature, entry_point_name) \
+ if (string_init == init_runtime_name) { \
+ return new_runtime_name; \
+ }
+ STRING_INIT_LIST(TO_STRING_FACTORY)
+ #undef TO_STRING_FACTORY
+ LOG(FATAL) << "Could not find StringFactory method for String.<init>";
+ return nullptr;
+}
+
+uint32_t WellKnownClasses::StringInitToEntryPoint(ArtMethod* string_init) {
+ #define TO_ENTRY_POINT(init_runtime_name, init_signature, new_runtime_name, \
+ new_java_name, new_signature, entry_point_name) \
+ if (string_init == init_runtime_name) { \
+ return kQuick ## entry_point_name; \
+ }
+ STRING_INIT_LIST(TO_ENTRY_POINT)
+ #undef TO_STRING_FACTORY
+ LOG(FATAL) << "Could not find StringFactory method for String.<init>";
+ return 0;
+}
+#undef STRING_INIT_LIST
+
void WellKnownClasses::Init(JNIEnv* env) {
com_android_dex_Dex = CacheClass(env, "com/android/dex/Dex");
dalvik_annotation_optimization_CriticalNative =
@@ -241,6 +283,8 @@
java_lang_reflect_Executable = CacheClass(env, "java/lang/reflect/Executable");
java_lang_reflect_Field = CacheClass(env, "java/lang/reflect/Field");
java_lang_reflect_Method = CacheClass(env, "java/lang/reflect/Method");
+ java_lang_reflect_Parameter = CacheClass(env, "java/lang/reflect/Parameter");
+ java_lang_reflect_Parameter__array = CacheClass(env, "[Ljava/lang/reflect/Parameter;");
java_lang_reflect_Proxy = CacheClass(env, "java/lang/reflect/Proxy");
java_lang_RuntimeException = CacheClass(env, "java/lang/RuntimeException");
java_lang_StackOverflowError = CacheClass(env, "java/lang/StackOverflowError");
@@ -273,6 +317,7 @@
ScopedLocalRef<jclass> java_lang_ref_ReferenceQueue(env, env->FindClass("java/lang/ref/ReferenceQueue"));
java_lang_ref_ReferenceQueue_add = CacheMethod(env, java_lang_ref_ReferenceQueue.get(), true, "add", "(Ljava/lang/ref/Reference;)V");
+ java_lang_reflect_Parameter_init = CacheMethod(env, java_lang_reflect_Parameter, false, "<init>", "(Ljava/lang/String;ILjava/lang/reflect/Executable;I)V");
java_lang_reflect_Proxy_invoke = CacheMethod(env, java_lang_reflect_Proxy, true, "invoke", "(Ljava/lang/reflect/Proxy;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;");
java_lang_Thread_dispatchUncaughtException = CacheMethod(env, java_lang_Thread, false, "dispatchUncaughtException", "(Ljava/lang/Throwable;)V");
java_lang_Thread_init = CacheMethod(env, java_lang_Thread, false, "<init>", "(Ljava/lang/ThreadGroup;Ljava/lang/String;IZ)V");
@@ -284,62 +329,6 @@
org_apache_harmony_dalvik_ddmc_DdmServer_broadcast = CacheMethod(env, org_apache_harmony_dalvik_ddmc_DdmServer, true, "broadcast", "(I)V");
org_apache_harmony_dalvik_ddmc_DdmServer_dispatch = CacheMethod(env, org_apache_harmony_dalvik_ddmc_DdmServer, true, "dispatch", "(I[BII)Lorg/apache/harmony/dalvik/ddmc/Chunk;");
- java_lang_String_init = CacheMethod(env, java_lang_String, false, "<init>", "()V");
- java_lang_String_init_B = CacheMethod(env, java_lang_String, false, "<init>", "([B)V");
- java_lang_String_init_BI = CacheMethod(env, java_lang_String, false, "<init>", "([BI)V");
- java_lang_String_init_BII = CacheMethod(env, java_lang_String, false, "<init>", "([BII)V");
- java_lang_String_init_BIII = CacheMethod(env, java_lang_String, false, "<init>", "([BIII)V");
- java_lang_String_init_BIIString = CacheMethod(env, java_lang_String, false, "<init>",
- "([BIILjava/lang/String;)V");
- java_lang_String_init_BString = CacheMethod(env, java_lang_String, false, "<init>",
- "([BLjava/lang/String;)V");
- java_lang_String_init_BIICharset = CacheMethod(env, java_lang_String, false, "<init>",
- "([BIILjava/nio/charset/Charset;)V");
- java_lang_String_init_BCharset = CacheMethod(env, java_lang_String, false, "<init>",
- "([BLjava/nio/charset/Charset;)V");
- java_lang_String_init_C = CacheMethod(env, java_lang_String, false, "<init>", "([C)V");
- java_lang_String_init_CII = CacheMethod(env, java_lang_String, false, "<init>", "([CII)V");
- java_lang_String_init_IIC = CacheMethod(env, java_lang_String, false, "<init>", "(II[C)V");
- java_lang_String_init_String = CacheMethod(env, java_lang_String, false, "<init>",
- "(Ljava/lang/String;)V");
- java_lang_String_init_StringBuffer = CacheMethod(env, java_lang_String, false, "<init>",
- "(Ljava/lang/StringBuffer;)V");
- java_lang_String_init_III = CacheMethod(env, java_lang_String, false, "<init>", "([III)V");
- java_lang_String_init_StringBuilder = CacheMethod(env, java_lang_String, false, "<init>",
- "(Ljava/lang/StringBuilder;)V");
- java_lang_StringFactory_newEmptyString = CacheMethod(env, java_lang_StringFactory, true,
- "newEmptyString", "()Ljava/lang/String;");
- java_lang_StringFactory_newStringFromBytes_B = CacheMethod(env, java_lang_StringFactory, true,
- "newStringFromBytes", "([B)Ljava/lang/String;");
- java_lang_StringFactory_newStringFromBytes_BI = CacheMethod(env, java_lang_StringFactory, true,
- "newStringFromBytes", "([BI)Ljava/lang/String;");
- java_lang_StringFactory_newStringFromBytes_BII = CacheMethod(env, java_lang_StringFactory, true,
- "newStringFromBytes", "([BII)Ljava/lang/String;");
- java_lang_StringFactory_newStringFromBytes_BIII = CacheMethod(env, java_lang_StringFactory, true,
- "newStringFromBytes", "([BIII)Ljava/lang/String;");
- java_lang_StringFactory_newStringFromBytes_BIIString = CacheMethod(env, java_lang_StringFactory,
- true, "newStringFromBytes", "([BIILjava/lang/String;)Ljava/lang/String;");
- java_lang_StringFactory_newStringFromBytes_BString = CacheMethod(env, java_lang_StringFactory,
- true, "newStringFromBytes", "([BLjava/lang/String;)Ljava/lang/String;");
- java_lang_StringFactory_newStringFromBytes_BIICharset = CacheMethod(env, java_lang_StringFactory,
- true, "newStringFromBytes", "([BIILjava/nio/charset/Charset;)Ljava/lang/String;");
- java_lang_StringFactory_newStringFromBytes_BCharset = CacheMethod(env, java_lang_StringFactory,
- true, "newStringFromBytes", "([BLjava/nio/charset/Charset;)Ljava/lang/String;");
- java_lang_StringFactory_newStringFromChars_C = CacheMethod(env, java_lang_StringFactory, true,
- "newStringFromChars", "([C)Ljava/lang/String;");
- java_lang_StringFactory_newStringFromChars_CII = CacheMethod(env, java_lang_StringFactory, true,
- "newStringFromChars", "([CII)Ljava/lang/String;");
- java_lang_StringFactory_newStringFromChars_IIC = CacheMethod(env, java_lang_StringFactory, true,
- "newStringFromChars", "(II[C)Ljava/lang/String;");
- java_lang_StringFactory_newStringFromString = CacheMethod(env, java_lang_StringFactory, true,
- "newStringFromString", "(Ljava/lang/String;)Ljava/lang/String;");
- java_lang_StringFactory_newStringFromStringBuffer = CacheMethod(env, java_lang_StringFactory,
- true, "newStringFromStringBuffer", "(Ljava/lang/StringBuffer;)Ljava/lang/String;");
- java_lang_StringFactory_newStringFromCodePoints = CacheMethod(env, java_lang_StringFactory,
- true, "newStringFromCodePoints", "([III)Ljava/lang/String;");
- java_lang_StringFactory_newStringFromStringBuilder = CacheMethod(env, java_lang_StringFactory,
- true, "newStringFromStringBuilder", "(Ljava/lang/StringBuilder;)Ljava/lang/String;");
-
dalvik_system_DexFile_cookie = CacheField(env, dalvik_system_DexFile, false, "mCookie", "Ljava/lang/Object;");
dalvik_system_DexFile_fileName = CacheField(env, dalvik_system_DexFile, false, "mFileName", "Ljava/lang/String;");
dalvik_system_PathClassLoader_pathList = CacheField(env, dalvik_system_PathClassLoader, false, "pathList", "Ldalvik/system/DexPathList;");
@@ -384,6 +373,7 @@
java_lang_Long_valueOf = CachePrimitiveBoxingMethod(env, 'J', "java/lang/Long");
java_lang_Short_valueOf = CachePrimitiveBoxingMethod(env, 'S', "java/lang/Short");
+ InitStringInit(env);
Thread::Current()->InitStringEntryPoints();
}
@@ -399,43 +389,4 @@
return reinterpret_cast<mirror::Class*>(Thread::Current()->DecodeJObject(global_jclass));
}
-jmethodID WellKnownClasses::StringInitToStringFactoryMethodID(jmethodID string_init) {
- // TODO: Prioritize ordering.
- if (string_init == java_lang_String_init) {
- return java_lang_StringFactory_newEmptyString;
- } else if (string_init == java_lang_String_init_B) {
- return java_lang_StringFactory_newStringFromBytes_B;
- } else if (string_init == java_lang_String_init_BI) {
- return java_lang_StringFactory_newStringFromBytes_BI;
- } else if (string_init == java_lang_String_init_BII) {
- return java_lang_StringFactory_newStringFromBytes_BII;
- } else if (string_init == java_lang_String_init_BIII) {
- return java_lang_StringFactory_newStringFromBytes_BIII;
- } else if (string_init == java_lang_String_init_BIIString) {
- return java_lang_StringFactory_newStringFromBytes_BIIString;
- } else if (string_init == java_lang_String_init_BString) {
- return java_lang_StringFactory_newStringFromBytes_BString;
- } else if (string_init == java_lang_String_init_BIICharset) {
- return java_lang_StringFactory_newStringFromBytes_BIICharset;
- } else if (string_init == java_lang_String_init_BCharset) {
- return java_lang_StringFactory_newStringFromBytes_BCharset;
- } else if (string_init == java_lang_String_init_C) {
- return java_lang_StringFactory_newStringFromChars_C;
- } else if (string_init == java_lang_String_init_CII) {
- return java_lang_StringFactory_newStringFromChars_CII;
- } else if (string_init == java_lang_String_init_IIC) {
- return java_lang_StringFactory_newStringFromChars_IIC;
- } else if (string_init == java_lang_String_init_String) {
- return java_lang_StringFactory_newStringFromString;
- } else if (string_init == java_lang_String_init_StringBuffer) {
- return java_lang_StringFactory_newStringFromStringBuffer;
- } else if (string_init == java_lang_String_init_III) {
- return java_lang_StringFactory_newStringFromCodePoints;
- } else if (string_init == java_lang_String_init_StringBuilder) {
- return java_lang_StringFactory_newStringFromStringBuilder;
- }
- LOG(FATAL) << "Could not find StringFactory method for String.<init>";
- return nullptr;
-}
-
} // namespace art
diff --git a/runtime/well_known_classes.h b/runtime/well_known_classes.h
index b4d179c..ddfc5b8 100644
--- a/runtime/well_known_classes.h
+++ b/runtime/well_known_classes.h
@@ -21,6 +21,9 @@
#include "jni.h"
namespace art {
+
+class ArtMethod;
+
namespace mirror {
class Class;
} // namespace mirror
@@ -35,7 +38,8 @@
public:
static void Init(JNIEnv* env); // Run before native methods are registered.
static void LateInit(JNIEnv* env); // Run after native methods are registered.
- static jmethodID StringInitToStringFactoryMethodID(jmethodID string_init);
+ static ArtMethod* StringInitToStringFactory(ArtMethod* method);
+ static uint32_t StringInitToEntryPoint(ArtMethod* method);
static mirror::Class* ToClass(jclass global_jclass)
REQUIRES_SHARED(Locks::mutator_lock_);
@@ -63,6 +67,8 @@
static jclass java_lang_reflect_Executable;
static jclass java_lang_reflect_Field;
static jclass java_lang_reflect_Method;
+ static jclass java_lang_reflect_Parameter;
+ static jclass java_lang_reflect_Parameter__array;
static jclass java_lang_reflect_Proxy;
static jclass java_lang_RuntimeException;
static jclass java_lang_StackOverflowError;
@@ -97,41 +103,10 @@
static jmethodID java_lang_Long_valueOf;
static jmethodID java_lang_ref_FinalizerReference_add;
static jmethodID java_lang_ref_ReferenceQueue_add;
+ static jmethodID java_lang_reflect_Parameter_init;
static jmethodID java_lang_reflect_Proxy_invoke;
static jmethodID java_lang_Runtime_nativeLoad;
static jmethodID java_lang_Short_valueOf;
- static jmethodID java_lang_String_init;
- static jmethodID java_lang_String_init_B;
- static jmethodID java_lang_String_init_BI;
- static jmethodID java_lang_String_init_BII;
- static jmethodID java_lang_String_init_BIII;
- static jmethodID java_lang_String_init_BIIString;
- static jmethodID java_lang_String_init_BString;
- static jmethodID java_lang_String_init_BIICharset;
- static jmethodID java_lang_String_init_BCharset;
- static jmethodID java_lang_String_init_C;
- static jmethodID java_lang_String_init_CII;
- static jmethodID java_lang_String_init_IIC;
- static jmethodID java_lang_String_init_String;
- static jmethodID java_lang_String_init_StringBuffer;
- static jmethodID java_lang_String_init_III;
- static jmethodID java_lang_String_init_StringBuilder;
- static jmethodID java_lang_StringFactory_newEmptyString;
- static jmethodID java_lang_StringFactory_newStringFromBytes_B;
- static jmethodID java_lang_StringFactory_newStringFromBytes_BI;
- static jmethodID java_lang_StringFactory_newStringFromBytes_BII;
- static jmethodID java_lang_StringFactory_newStringFromBytes_BIII;
- static jmethodID java_lang_StringFactory_newStringFromBytes_BIIString;
- static jmethodID java_lang_StringFactory_newStringFromBytes_BString;
- static jmethodID java_lang_StringFactory_newStringFromBytes_BIICharset;
- static jmethodID java_lang_StringFactory_newStringFromBytes_BCharset;
- static jmethodID java_lang_StringFactory_newStringFromChars_C;
- static jmethodID java_lang_StringFactory_newStringFromChars_CII;
- static jmethodID java_lang_StringFactory_newStringFromChars_IIC;
- static jmethodID java_lang_StringFactory_newStringFromString;
- static jmethodID java_lang_StringFactory_newStringFromStringBuffer;
- static jmethodID java_lang_StringFactory_newStringFromCodePoints;
- static jmethodID java_lang_StringFactory_newStringFromStringBuilder;
static jmethodID java_lang_System_runFinalization;
static jmethodID java_lang_Thread_dispatchUncaughtException;
static jmethodID java_lang_Thread_init;
@@ -177,6 +152,9 @@
static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_length;
static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_offset;
static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_type;
+
+ private:
+ static void InitStringInit(JNIEnv* env);
};
} // namespace art
diff --git a/test/099-vmdebug/check b/test/099-vmdebug/check
index 57111bc..d124ce8 100755
--- a/test/099-vmdebug/check
+++ b/test/099-vmdebug/check
@@ -15,6 +15,6 @@
# limitations under the License.
# Strip the process pids and line numbers from exact error messages.
-sed -e '/^art E.*\] /d' "$2" > "$2.tmp"
+sed -e '/^dalvikvm\(\|32\|64\) E.*\] /d' "$2" > "$2.tmp"
diff --strip-trailing-cr -q "$1" "$2.tmp" >/dev/null
diff --git a/test/118-noimage-dex2oat/check b/test/118-noimage-dex2oat/check
index 57111bc..4f46083 100755
--- a/test/118-noimage-dex2oat/check
+++ b/test/118-noimage-dex2oat/check
@@ -15,6 +15,6 @@
# limitations under the License.
# Strip the process pids and line numbers from exact error messages.
-sed -e '/^art E.*\] /d' "$2" > "$2.tmp"
+sed -e '/^dalvikvm.* E.*\] /d' "$2" > "$2.tmp"
diff --strip-trailing-cr -q "$1" "$2.tmp" >/dev/null
diff --git a/test/119-noimage-patchoat/check b/test/119-noimage-patchoat/check
index 57111bc..d124ce8 100755
--- a/test/119-noimage-patchoat/check
+++ b/test/119-noimage-patchoat/check
@@ -15,6 +15,6 @@
# limitations under the License.
# Strip the process pids and line numbers from exact error messages.
-sed -e '/^art E.*\] /d' "$2" > "$2.tmp"
+sed -e '/^dalvikvm\(\|32\|64\) E.*\] /d' "$2" > "$2.tmp"
diff --strip-trailing-cr -q "$1" "$2.tmp" >/dev/null
diff --git a/test/137-cfi/cfi.cc b/test/137-cfi/cfi.cc
index 9f1499e..113b35f 100644
--- a/test/137-cfi/cfi.cc
+++ b/test/137-cfi/cfi.cc
@@ -91,7 +91,7 @@
static void MoreErrorInfo(pid_t pid, bool sig_quit_on_fail) {
printf("Secondary pid is %d\n", pid);
- PrintFileToLog(StringPrintf("/proc/%d/maps", pid), ERROR);
+ PrintFileToLog(StringPrintf("/proc/%d/maps", pid), ::android::base::ERROR);
if (sig_quit_on_fail) {
int res = kill(pid, SIGQUIT);
diff --git a/test/143-string-value/check b/test/143-string-value/check
index 92f6e90..2a3476c 100755
--- a/test/143-string-value/check
+++ b/test/143-string-value/check
@@ -15,6 +15,6 @@
# limitations under the License.
# Strip error log messages.
-sed -e '/^art E.*\] /d' "$2" > "$2.tmp"
+sed -e '/^dalvikvm\(\|32\|64\) E.*\] /d' "$2" > "$2.tmp"
diff --strip-trailing-cr -q "$1" "$2.tmp" >/dev/null
diff --git a/test/149-suspend-all-stress/suspend_all.cc b/test/149-suspend-all-stress/suspend_all.cc
index dfd944a..c1c0ff9 100644
--- a/test/149-suspend-all-stress/suspend_all.cc
+++ b/test/149-suspend-all-stress/suspend_all.cc
@@ -42,14 +42,16 @@
break;
}
case kOPDumpStack: {
- Runtime::Current()->GetThreadList()->Dump(LOG(INFO));
+ Runtime::Current()->GetThreadList()->Dump(LOG_STREAM(INFO));
usleep(500);
break;
}
case kOPSuspendAllDumpStack: {
// Not yet supported.
- // ScopedSuspendAll ssa(__FUNCTION__);
- // Runtime::Current()->GetThreadList()->Dump(LOG(INFO));
+ if ((false)) {
+ ScopedSuspendAll ssa(__FUNCTION__);
+ Runtime::Current()->GetThreadList()->Dump(LOG_STREAM(INFO));
+ }
break;
}
case kOPNumber:
diff --git a/test/Android.bp b/test/Android.bp
index 2d61000..72dcbba 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -63,6 +63,7 @@
"libvixld-arm64",
"libart-gtest",
+ "libbase",
"libicuuc",
"libicui18n",
"libnativehelper",
@@ -204,6 +205,7 @@
],
shared_libs: [
"libbacktrace",
+ "libbase",
"libnativehelper",
],
target: {
@@ -246,6 +248,7 @@
],
shared_libs: [
"libart",
+ "libbase",
"libopenjdkjvmti",
],
}
@@ -306,6 +309,7 @@
],
shared_libs: [
"libbacktrace",
+ "libbase",
"libnativehelper",
],
target: {
diff --git a/test/run-test b/test/run-test
index c50a9ca..7a4afaf 100755
--- a/test/run-test
+++ b/test/run-test
@@ -937,6 +937,7 @@
--raw-cmd="$raw_cmd" \
--check-script="$cwd/check" \
--expected-output="$cwd/expected.txt" \
+ --logfile="$cwd/bisection_log.txt" \
--timeout=300
fi
fi
diff --git a/tools/ahat/Android.mk b/tools/ahat/Android.mk
index 4003ee0..ebf087d 100644
--- a/tools/ahat/Android.mk
+++ b/tools/ahat/Android.mk
@@ -73,7 +73,7 @@
$(ART_HOST_EXECUTABLES) \
$(ART_HOST_SHARED_LIBRARY_DEPENDENCIES) \
$(HOST_OUT_EXECUTABLES)/art \
- $(HOST_CORE_IMG_OUT_BASE)-optimizing-pic$(CORE_IMG_SUFFIX)
+ $(HOST_CORE_IMG_OUT_BASE)$(CORE_IMG_SUFFIX)
$(AHAT_TEST_DUMP_HPROF): PRIVATE_AHAT_TEST_ART := $(HOST_OUT_EXECUTABLES)/art
$(AHAT_TEST_DUMP_HPROF): PRIVATE_AHAT_TEST_DUMP_JAR := $(AHAT_TEST_DUMP_JAR)
diff --git a/tools/ahat/README.txt b/tools/ahat/README.txt
index ecf9e53..8604ff0 100644
--- a/tools/ahat/README.txt
+++ b/tools/ahat/README.txt
@@ -9,7 +9,6 @@
Serve pages on the given port. Defaults to 7100.
TODO:
- * Show GC Root paths.
* Have a way to diff two heap dumps.
* Add more tips to the help page.
@@ -76,6 +75,7 @@
Release History:
0.8 Pending
+ Show sample path from GC root with field names in place of dominator path.
0.7 Aug 16, 2016
Launch ahat server before processing the heap dump.
diff --git a/tools/ahat/src/HeapTable.java b/tools/ahat/src/HeapTable.java
index ed11d17..5b84048 100644
--- a/tools/ahat/src/HeapTable.java
+++ b/tools/ahat/src/HeapTable.java
@@ -84,10 +84,10 @@
for (Heap heap : heaps) {
long size = config.getSize(elem, heap);
total += size;
- vals.add(DocString.format("%,14d", size));
+ vals.add(size == 0 ? DocString.text("") : DocString.format("%,14d", size));
}
if (showTotal) {
- vals.add(DocString.format("%,14d", total));
+ vals.add(total == 0 ? DocString.text("") : DocString.format("%,14d", total));
}
for (ValueConfig<T> value : values) {
diff --git a/tools/ahat/src/InstanceUtils.java b/tools/ahat/src/InstanceUtils.java
index 8769d11..94934a2 100644
--- a/tools/ahat/src/InstanceUtils.java
+++ b/tools/ahat/src/InstanceUtils.java
@@ -19,11 +19,17 @@
import com.android.tools.perflib.heap.ArrayInstance;
import com.android.tools.perflib.heap.ClassInstance;
import com.android.tools.perflib.heap.ClassObj;
+import com.android.tools.perflib.heap.Field;
import com.android.tools.perflib.heap.Heap;
import com.android.tools.perflib.heap.Instance;
+import com.android.tools.perflib.heap.RootObj;
import com.android.tools.perflib.heap.Type;
import java.awt.image.BufferedImage;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
/**
* Utilities for extracting information from hprof instances.
@@ -179,7 +185,7 @@
* Read a reference field of an instance.
* Returns null if the field value is null, or if the field couldn't be read.
*/
- private static Instance getRefField(Instance inst, String fieldName) {
+ public static Instance getRefField(Instance inst, String fieldName) {
Object value = getField(inst, fieldName);
if (!(value instanceof Instance)) {
return null;
@@ -357,4 +363,90 @@
}
return new NativeAllocation(size, inst.getHeap(), pointer, referent);
}
+
+ public static class PathElement {
+ public final Instance instance;
+ public final String field;
+ public boolean isDominator;
+
+ public PathElement(Instance instance, String field) {
+ this.instance = instance;
+ this.field = field;
+ this.isDominator = false;
+ }
+ }
+
+ /**
+ * Returns a sample path from a GC root to this instance.
+ * The given instance is included as the last element of the path with an
+ * empty field description.
+ */
+ public static List<PathElement> getPathFromGcRoot(Instance inst) {
+ List<PathElement> path = new ArrayList<PathElement>();
+
+ Instance dom = inst;
+ for (PathElement elem = new PathElement(inst, ""); elem != null;
+ elem = getNextPathElementToGcRoot(elem.instance)) {
+ if (elem.instance == dom) {
+ elem.isDominator = true;
+ dom = dom.getImmediateDominator();
+ }
+ path.add(elem);
+ }
+ Collections.reverse(path);
+ return path;
+ }
+
+ /**
+ * Returns the next instance to GC root from this object and a string
+ * description of which field of that object refers to the given instance.
+ * Returns null if the given instance has no next instance to the gc root.
+ */
+ private static PathElement getNextPathElementToGcRoot(Instance inst) {
+ Instance parent = inst.getNextInstanceToGcRoot();
+ if (parent == null || parent instanceof RootObj) {
+ return null;
+ }
+
+ // Search the parent for the reference to the child.
+ // TODO: This seems terribly inefficient. Can we use data structures to
+ // help us here?
+ String description = ".???";
+ if (parent instanceof ArrayInstance) {
+ ArrayInstance array = (ArrayInstance)parent;
+ Object[] values = array.getValues();
+ for (int i = 0; i < values.length; i++) {
+ if (values[i] instanceof Instance) {
+ Instance ref = (Instance)values[i];
+ if (ref.getId() == inst.getId()) {
+ description = String.format("[%d]", i);
+ break;
+ }
+ }
+ }
+ } else if (parent instanceof ClassObj) {
+ ClassObj cls = (ClassObj)parent;
+ for (Map.Entry<Field, Object> entries : cls.getStaticFieldValues().entrySet()) {
+ if (entries.getValue() instanceof Instance) {
+ Instance ref = (Instance)entries.getValue();
+ if (ref.getId() == inst.getId()) {
+ description = "." + entries.getKey().getName();
+ break;
+ }
+ }
+ }
+ } else if (parent instanceof ClassInstance) {
+ ClassInstance obj = (ClassInstance)parent;
+ for (ClassInstance.FieldValue fields : obj.getValues()) {
+ if (fields.getValue() instanceof Instance) {
+ Instance ref = (Instance)fields.getValue();
+ if (ref.getId() == inst.getId()) {
+ description = "." + fields.getField().getName();
+ break;
+ }
+ }
+ }
+ }
+ return new PathElement(parent, description);
+ }
}
diff --git a/tools/ahat/src/ObjectHandler.java b/tools/ahat/src/ObjectHandler.java
index 4df1be5..78aac17 100644
--- a/tools/ahat/src/ObjectHandler.java
+++ b/tools/ahat/src/ObjectHandler.java
@@ -22,7 +22,6 @@
import com.android.tools.perflib.heap.Field;
import com.android.tools.perflib.heap.Heap;
import com.android.tools.perflib.heap.Instance;
-import com.android.tools.perflib.heap.RootObj;
import com.android.tools.perflib.heap.RootType;
import java.io.IOException;
import java.util.ArrayList;
@@ -32,6 +31,8 @@
import java.util.List;
import java.util.Map;
+import static com.android.ahat.InstanceUtils.PathElement;
+
class ObjectHandler implements AhatHandler {
private static final String ARRAY_ELEMENTS_ID = "elements";
@@ -62,7 +63,7 @@
doc.big(Value.render(mSnapshot, inst));
printAllocationSite(doc, query, inst);
- printDominatorPath(doc, query, inst);
+ printGcRootPath(doc, query, inst);
doc.section("Object Info");
ClassObj cls = inst.getClassObj();
@@ -202,43 +203,43 @@
}
}
- private void printDominatorPath(Doc doc, Query query, Instance inst) {
- doc.section("Dominator Path from Root");
- List<Instance> path = new ArrayList<Instance>();
- for (Instance parent = inst;
- parent != null && !(parent instanceof RootObj);
- parent = parent.getImmediateDominator()) {
- path.add(parent);
- }
+ private void printGcRootPath(Doc doc, Query query, Instance inst) {
+ doc.section("Sample Path from GC Root");
+ List<PathElement> path = InstanceUtils.getPathFromGcRoot(inst);
// Add 'null' as a marker for the root.
- path.add(null);
- Collections.reverse(path);
+ path.add(0, null);
- HeapTable.TableConfig<Instance> table = new HeapTable.TableConfig<Instance>() {
+ HeapTable.TableConfig<PathElement> table = new HeapTable.TableConfig<PathElement>() {
public String getHeapsDescription() {
- return "Bytes Retained by Heap";
+ return "Bytes Retained by Heap (Dominators Only)";
}
- public long getSize(Instance element, Heap heap) {
+ public long getSize(PathElement element, Heap heap) {
if (element == null) {
return mSnapshot.getHeapSize(heap);
}
- int index = mSnapshot.getHeapIndex(heap);
- return element.getRetainedSize(index);
+ if (element.isDominator) {
+ int index = mSnapshot.getHeapIndex(heap);
+ return element.instance.getRetainedSize(index);
+ }
+ return 0;
}
- public List<HeapTable.ValueConfig<Instance>> getValueConfigs() {
- HeapTable.ValueConfig<Instance> value = new HeapTable.ValueConfig<Instance>() {
+ public List<HeapTable.ValueConfig<PathElement>> getValueConfigs() {
+ HeapTable.ValueConfig<PathElement> value = new HeapTable.ValueConfig<PathElement>() {
public String getDescription() {
- return "Object";
+ return "Path Element";
}
- public DocString render(Instance element) {
+ public DocString render(PathElement element) {
if (element == null) {
return DocString.link(DocString.uri("rooted"), DocString.text("ROOT"));
} else {
- return DocString.text("→ ").append(Value.render(mSnapshot, element));
+ DocString label = DocString.text(" → ");
+ label.append(Value.render(mSnapshot, element.instance));
+ label.append(element.field);
+ return label;
}
}
};
diff --git a/tools/ahat/test-dump/Main.java b/tools/ahat/test-dump/Main.java
index 3936f29..e08df67 100644
--- a/tools/ahat/test-dump/Main.java
+++ b/tools/ahat/test-dump/Main.java
@@ -29,6 +29,16 @@
// collected before we take the heap dump.
public static DumpedStuff stuff;
+ public static class ObjectTree {
+ public ObjectTree left;
+ public ObjectTree right;
+
+ public ObjectTree(ObjectTree left, ObjectTree right) {
+ this.left = left;
+ this.right = right;
+ }
+ }
+
// We will take a heap dump that includes a single instance of this
// DumpedStuff class. Objects stored as fields in this class can be easily
// found in the hprof dump by searching for the instance of the DumpedStuff
@@ -42,6 +52,11 @@
public PhantomReference aPhantomReference = new PhantomReference(anObject, referenceQueue);
public WeakReference aWeakReference = new WeakReference(anObject, referenceQueue);
public byte[] bigArray;
+ public ObjectTree[] gcPathArray = new ObjectTree[]{null, null,
+ new ObjectTree(
+ new ObjectTree(null, new ObjectTree(null, null)),
+ new ObjectTree(null, null)),
+ null};
DumpedStuff() {
int N = 1000000;
@@ -53,6 +68,8 @@
NativeAllocationRegistry registry = new NativeAllocationRegistry(
Main.class.getClassLoader(), 0x12345, 42);
registry.registerNativeAllocation(anObject, 0xABCDABCD);
+
+ gcPathArray[2].right.left = gcPathArray[2].left.right;
}
}
diff --git a/tools/ahat/test/InstanceUtilsTest.java b/tools/ahat/test/InstanceUtilsTest.java
index 59b1c90..ec77e70 100644
--- a/tools/ahat/test/InstanceUtilsTest.java
+++ b/tools/ahat/test/InstanceUtilsTest.java
@@ -16,11 +16,16 @@
package com.android.ahat;
+import com.android.tools.perflib.heap.ArrayInstance;
+import com.android.tools.perflib.heap.ClassObj;
import com.android.tools.perflib.heap.Instance;
import java.io.IOException;
+import java.util.List;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class InstanceUtilsTest {
@@ -123,4 +128,55 @@
assertEquals(referent, InstanceUtils.getReferent(wref));
assertNull(InstanceUtils.getReferent(referent));
}
+
+ @Test
+ public void gcRootPath() throws IOException {
+ TestDump dump = TestDump.getTestDump();
+
+ ClassObj main = dump.getAhatSnapshot().findClass("Main");
+ ArrayInstance gcPathArray = (ArrayInstance)dump.getDumpedThing("gcPathArray");
+ Object[] values = gcPathArray.getValues();
+ Instance base = (Instance)values[2];
+ Instance left = InstanceUtils.getRefField(base, "left");
+ Instance right = InstanceUtils.getRefField(base, "right");
+ Instance target = InstanceUtils.getRefField(left, "right");
+
+ List<InstanceUtils.PathElement> path = InstanceUtils.getPathFromGcRoot(target);
+ assertEquals(6, path.size());
+
+ assertEquals(main, path.get(0).instance);
+ assertEquals(".stuff", path.get(0).field);
+ assertTrue(path.get(0).isDominator);
+
+ assertEquals(".gcPathArray", path.get(1).field);
+ assertTrue(path.get(1).isDominator);
+
+ assertEquals(gcPathArray, path.get(2).instance);
+ assertEquals("[2]", path.get(2).field);
+ assertTrue(path.get(2).isDominator);
+
+ assertEquals(base, path.get(3).instance);
+ assertTrue(path.get(3).isDominator);
+
+ // There are two possible paths. Either it can go through the 'left' node,
+ // or the 'right' node.
+ if (path.get(3).field.equals(".left")) {
+ assertEquals(".left", path.get(3).field);
+
+ assertEquals(left, path.get(4).instance);
+ assertEquals(".right", path.get(4).field);
+ assertFalse(path.get(4).isDominator);
+
+ } else {
+ assertEquals(".right", path.get(3).field);
+
+ assertEquals(right, path.get(4).instance);
+ assertEquals(".left", path.get(4).field);
+ assertFalse(path.get(4).isDominator);
+ }
+
+ assertEquals(target, path.get(5).instance);
+ assertEquals("", path.get(5).field);
+ assertTrue(path.get(5).isDominator);
+ }
}
diff --git a/tools/bisection_search/bisection_search.py b/tools/bisection_search/bisection_search.py
index c5971e6..27bd599 100755
--- a/tools/bisection_search/bisection_search.py
+++ b/tools/bisection_search/bisection_search.py
@@ -294,8 +294,7 @@
if faulty_method_idx == len(all_methods) + 1:
return (None, None)
if faulty_method_idx == 0:
- raise FatalError('Testable fails with no methods compiled. '
- 'Perhaps issue lies outside of compiler.')
+ raise FatalError('Testable fails with no methods compiled.')
faulty_method = all_methods[faulty_method_idx - 1]
all_passes = testable.GetAllPassesForMethod(faulty_method)
faulty_pass_idx = BinarySearch(
@@ -415,7 +414,11 @@
try:
testable = Dex2OatWrapperTestable(base_cmd, test_env, args.expected_retcode,
output_checker, args.verbose)
- (method, opt_pass) = BugSearch(testable)
+ if testable.Test(compiled_methods=[]):
+ (method, opt_pass) = BugSearch(testable)
+ else:
+ print('Testable fails with no methods compiled.')
+ sys.exit(1)
except Exception as e:
print('Error occurred.\nLogfile: {0}'.format(test_env.logfile.name))
test_env.logfile.write('Exception: {0}\n'.format(e))
diff --git a/tools/jfuzz/README.md b/tools/jfuzz/README.md
index 3eb41cf..c87e714 100644
--- a/tools/jfuzz/README.md
+++ b/tools/jfuzz/README.md
@@ -47,20 +47,34 @@
[--mode1=MODE] [--mode2=MODE]
[--report_script=SCRIPT]
[--jfuzz_arg=ARG]
+ [--true_divergence]
where
- --num_tests : number of tests to run (10000 by default)
- --device : target device serial number (passed to adb -s)
- --mode1 : m1
- --mode2 : m2, with m1 != m2, and values one of
+ --num_tests : number of tests to run (10000 by default)
+ --device : target device serial number (passed to adb -s)
+ --mode1 : m1
+ --mode2 : m2, with m1 != m2, and values one of
ri = reference implementation on host (default for m1)
hint = Art interpreter on host
hopt = Art optimizing on host (default for m2)
tint = Art interpreter on target
topt = Art optimizing on target
- --report_script : path to script called for each divergence
- --jfuzz_arg : argument for jfuzz
+ --report_script : path to script called for each divergence
+ --jfuzz_arg : argument for jfuzz
+ --true_divergence : don't bisect timeout divergences
+
+How to start JFuzz nightly testing
+==================================
+
+ run_jfuzz_test_nightly.py
+ [--num_proc NUM_PROC]
+
+where
+
+ --num_proc : number of run_jfuzz_test.py instances to run (8 by default)
+
+Remaining arguments are passed to run\_jfuzz_test.py.
How to start J/DexFuzz testing (multi-layered)
==============================================
diff --git a/tools/jfuzz/run_jfuzz_test.py b/tools/jfuzz/run_jfuzz_test.py
index 05e8daf..54f9bb4 100755
--- a/tools/jfuzz/run_jfuzz_test.py
+++ b/tools/jfuzz/run_jfuzz_test.py
@@ -306,7 +306,7 @@
"""Tester that runs JFuzz many times and report divergences."""
def __init__(self, num_tests, device, mode1, mode2, jfuzz_args,
- report_script):
+ report_script, true_divergence_only):
"""Constructor for the tester.
Args:
@@ -316,6 +316,7 @@
mode2: string, execution mode for second runner
jfuzz_args: list of strings, additional arguments for jfuzz
report_script: string, path to script called for each divergence
+ true_divergence_only: boolean, if True don't bisect timeout divergences
"""
self._num_tests = num_tests
self._device = device
@@ -323,6 +324,7 @@
self._runner2 = GetExecutionModeRunner(device, mode2)
self._jfuzz_args = jfuzz_args
self._report_script = report_script
+ self._true_divergence_only = true_divergence_only
self._save_dir = None
self._results_dir = None
self._jfuzz_dir = None
@@ -449,7 +451,8 @@
for f in glob('*.txt') + ['Test.java']:
shutil.copy(f, ddir)
# Maybe run bisection bug search.
- if retc1 in BISECTABLE_RET_CODES and retc2 in BISECTABLE_RET_CODES:
+ if (retc1 in BISECTABLE_RET_CODES and retc2 in BISECTABLE_RET_CODES and
+ not (self._true_divergence_only and RetCode.TIMEOUT in (retc1, retc2))):
self.MaybeBisectDivergence(retc1, retc2, is_output_divergence)
# Call reporting script.
if self._report_script:
@@ -546,12 +549,15 @@
'divergence')
parser.add_argument('--jfuzz_arg', default=[], dest='jfuzz_args',
action='append', help='argument for jfuzz')
+ parser.add_argument('--true_divergence', default=False, action='store_true',
+ help='don\'t bisect timeout divergences')
args = parser.parse_args()
if args.mode1 == args.mode2:
raise FatalError('Identical execution modes given')
# Run the JFuzz tester.
with JFuzzTester(args.num_tests, args.device, args.mode1, args.mode2,
- args.jfuzz_args, args.report_script) as fuzzer:
+ args.jfuzz_args, args.report_script,
+ args.true_divergence) as fuzzer:
fuzzer.Run()
if __name__ == '__main__':
diff --git a/tools/jfuzz/run_jfuzz_test_nightly.py b/tools/jfuzz/run_jfuzz_test_nightly.py
new file mode 100755
index 0000000..29595f2
--- /dev/null
+++ b/tools/jfuzz/run_jfuzz_test_nightly.py
@@ -0,0 +1,84 @@
+#!/usr/bin/env python3.4
+#
+# Copyright (C) 2016 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.
+
+import argparse
+import os
+import re
+import shutil
+import subprocess
+import sys
+
+from glob import glob
+
+from tempfile import mkdtemp
+from tempfile import TemporaryFile
+
+# Default arguments for run_jfuzz_test.py.
+DEFAULT_ARGS = ['--num_tests=20000']
+
+# run_jfuzz_test.py success string.
+SUCCESS_STRING = 'success (no divergences)'
+
+# Constant returned by string find() method when search fails.
+NOT_FOUND = -1
+
+def main(argv):
+ cwd = os.path.dirname(os.path.realpath(__file__))
+ cmd = [cwd + '/run_jfuzz_test.py'] + DEFAULT_ARGS
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--num_proc', default=8,
+ type=int, help='number of processes to run')
+ # Unknown arguments are passed to run_jfuzz_test.py.
+ (args, unknown_args) = parser.parse_known_args()
+ output_files = [TemporaryFile('wb+') for _ in range(args.num_proc)]
+ processes = []
+ for output_file in output_files:
+ processes.append(subprocess.Popen(cmd + unknown_args, stdout=output_file,
+ stderr=subprocess.STDOUT))
+ try:
+ # Wait for processes to terminate.
+ for proc in processes:
+ proc.wait()
+ except KeyboardInterrupt:
+ for proc in processes:
+ proc.kill()
+ # Output results.
+ output_dirs = []
+ for i, output_file in enumerate(output_files):
+ output_file.seek(0)
+ output_str = output_file.read().decode('ascii')
+ output_file.close()
+ # Extract output directory. Example match: 'Directory : /tmp/tmp8ltpfjng'.
+ directory_match = re.search(r'Directory[^:]*: ([^\n]+)\n', output_str)
+ if directory_match:
+ output_dirs.append(directory_match.group(1))
+ print('Tester', i)
+ if output_str.find(SUCCESS_STRING) == NOT_FOUND:
+ print(output_str)
+ else:
+ print(SUCCESS_STRING)
+ # Gather divergences.
+ global_out_dir = mkdtemp('jfuzz_nightly')
+ divergence_nr = 1
+ for out_dir in output_dirs:
+ for divergence_dir in glob(out_dir + '/divergence*/'):
+ shutil.copytree(divergence_dir,
+ global_out_dir + '/divergence' + str(divergence_nr))
+ divergence_nr += 1
+ print('Global output directory:', global_out_dir)
+
+if __name__ == '__main__':
+ main(sys.argv)