Snap for 11670064 from 4d45b8613f650acb36df41a6e970a9694ae464a2 to mainline-cellbroadcast-release Change-Id: I012160717ae17992492df441c86dc0e9c6f399ff
diff --git a/Android.mk b/Android.mk index d560276..5c7f19d 100644 --- a/Android.mk +++ b/Android.mk
@@ -531,7 +531,9 @@ lib64/libicuuc.so \ PRIVATE_STATSD_APEX_DEPENDENCY_LIBS := \ + lib/libstatspull.so \ lib/libstatssocket.so \ + lib64/libstatspull.so \ lib64/libstatssocket.so \ # Extracts files from an APEX into a location. The APEX can be either a .apex
diff --git a/artd/art_standalone_artd_tests.xml b/artd/art_standalone_artd_tests.xml index 8a48b84..468b200 100644 --- a/artd/art_standalone_artd_tests.xml +++ b/artd/art_standalone_artd_tests.xml
@@ -43,7 +43,6 @@ <option name="mainline-module-package-name" value="com.android.art" /> </object> - <!-- Only run tests if the device under test is SDK version 31 (Android 12) or above. --> - <!-- TODO(jiakaiz): Change this to U once `ro.build.version.sdk` is bumped. --> - <object type="module_controller" class="com.android.tradefed.testtype.suite.module.Sdk31ModuleController" /> + <!-- Only run tests if the device under test is SDK version 34 (Android 14) or above. --> + <object type="module_controller" class="com.android.tradefed.testtype.suite.module.Sdk34ModuleController" /> </configuration>
diff --git a/build/apex/Android.bp b/build/apex/Android.bp index 5b419e5..bf8f461 100644 --- a/build/apex/Android.bp +++ b/build/apex/Android.bp
@@ -326,6 +326,11 @@ apex_defaults { name: "com.android.art-devel-defaults", defaults: ["com.android.art-device-defaults"], + // Use a different manifest for the Debug & Testing ART APEXes (which have + // no prebuilts and are thus always built from sources), with a high version + // number that ensures that these packages can be installed on virtually all + // Android dessert releases. + manifest: "manifest-art-debug.json", native_shared_libs: art_runtime_base_native_device_only_debug_shared_libs + art_runtime_run_test_libs + art_runtime_debug_native_shared_libs +
diff --git a/build/apex/manifest-art-debug.json b/build/apex/manifest-art-debug.json new file mode 100644 index 0000000..5eee90c --- /dev/null +++ b/build/apex/manifest-art-debug.json
@@ -0,0 +1,17 @@ +{ + // LINT.IfChange + "name": "com.android.art", + + // High version number that ensures that packages using this manifest (Debug + // ART APEX, Testing ART APEX) can be installed on virtually all Android + // dessert releases. + "version": 990091000, + + "provideNativeLibs": [ + "libjdwp.so" + ], + "requireNativeLibs": [ + "libicu_jni.so" + ] + // LINT.ThenChange(manifest-art.json) +}
diff --git a/build/apex/manifest-art.json b/build/apex/manifest-art.json index 4f20be6..83e2950 100644 --- a/build/apex/manifest-art.json +++ b/build/apex/manifest-art.json
@@ -1,4 +1,5 @@ { + // LINT.IfChange "name": "com.android.art", // Placeholder module version to be replaced during build. @@ -11,4 +12,5 @@ "requireNativeLibs": [ "libicu_jni.so" ] + // LINT.ThenChange(manifest-art-debug.json) }
diff --git a/compiler/optimizing/instruction_builder.cc b/compiler/optimizing/instruction_builder.cc index fee9091..f50fcf3 100644 --- a/compiler/optimizing/instruction_builder.cc +++ b/compiler/optimizing/instruction_builder.cc
@@ -1364,8 +1364,7 @@ method_reference, resolved_method, resolved_method_reference, - proto_idx, - !graph_->IsDebuggable()); + proto_idx); if (!HandleInvoke(invoke, operands, shorty, /* is_unresolved= */ false)) { return false; }
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h index 28112d1..e0ff10c 100644 --- a/compiler/optimizing/nodes.h +++ b/compiler/optimizing/nodes.h
@@ -4859,8 +4859,7 @@ // to pass intrinsic information to the HInvokePolymorphic node. ArtMethod* resolved_method, MethodReference resolved_method_reference, - dex::ProtoIndex proto_idx, - bool enable_intrinsic_opt) + dex::ProtoIndex proto_idx) : HInvoke(kInvokePolymorphic, allocator, number_of_arguments, @@ -4871,9 +4870,8 @@ resolved_method, resolved_method_reference, kPolymorphic, - enable_intrinsic_opt), - proto_idx_(proto_idx) { - } + /* enable_intrinsic_opt= */ true), + proto_idx_(proto_idx) {} bool IsClonable() const override { return true; }
diff --git a/dex2oat/art_standalone_dex2oat_cts_tests.xml b/dex2oat/art_standalone_dex2oat_cts_tests.xml index a47febe..0a38fef 100644 --- a/dex2oat/art_standalone_dex2oat_cts_tests.xml +++ b/dex2oat/art_standalone_dex2oat_cts_tests.xml
@@ -52,8 +52,6 @@ <test class="com.android.tradefed.testtype.GTest" > <option name="native-test-device-path" value="/data/local/tmp/art_standalone_dex2oat_cts_tests" /> <option name="module-name" value="art_standalone_dex2oat_cts_tests" /> - <option name="ld-library-path-32" value="/apex/com.android.art/lib" /> - <option name="ld-library-path-64" value="/apex/com.android.art/lib64" /> </test> <!-- When this test is run in a Mainline context (e.g. with `mts-tradefed`), only enable it if
diff --git a/libartservice/service/java/com/android/server/art/Debouncer.java b/libartservice/service/java/com/android/server/art/Debouncer.java index 61aea81..2aa7d0a 100644 --- a/libartservice/service/java/com/android/server/art/Debouncer.java +++ b/libartservice/service/java/com/android/server/art/Debouncer.java
@@ -19,6 +19,8 @@ import android.annotation.NonNull; import android.annotation.Nullable; +import com.android.internal.annotations.GuardedBy; + import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -32,7 +34,8 @@ public class Debouncer { @NonNull private Supplier<ScheduledExecutorService> mScheduledExecutorFactory; private final long mIntervalMs; - @Nullable private ScheduledFuture<?> mCurrentTask = null; + @GuardedBy("this") @Nullable private ScheduledFuture<?> mCurrentTask = null; + @GuardedBy("this") @Nullable private ScheduledExecutorService mExecutor = null; public Debouncer( long intervalMs, @NonNull Supplier<ScheduledExecutorService> scheduledExecutorFactory) { @@ -40,6 +43,23 @@ mIntervalMs = intervalMs; } + private void runTask(@NonNull Runnable command, @NonNull ScheduledExecutorService executor) { + synchronized (this) { + // In rare cases, at this point, another task may have been scheduled on the same + // executor, and `mExecutor` will be null or a new executor when that task is run, but + // that's okay. Either that task won't pass the check below or it will be cancelled. + // For simplicity, every task only shuts down its own executor. + // We only need to guarantee the following: + // - No new task is scheduled on an executor after the executor is shut down. + // - Every executor is eventually shut down. + if (mExecutor == executor) { + mExecutor.shutdown(); + mExecutor = null; + } + } + command.run(); + } + /** * Runs the given command after the interval has passed. If another command comes in during * this interval, the previous one will never run. @@ -48,8 +68,11 @@ if (mCurrentTask != null) { mCurrentTask.cancel(false /* mayInterruptIfRunning */); } - ScheduledExecutorService executor = mScheduledExecutorFactory.get(); - mCurrentTask = executor.schedule(command, mIntervalMs, TimeUnit.MILLISECONDS); - executor.shutdown(); + if (mExecutor == null) { + mExecutor = mScheduledExecutorFactory.get(); + } + ScheduledExecutorService executor = mExecutor; + mCurrentTask = mExecutor.schedule( + () -> runTask(command, executor), mIntervalMs, TimeUnit.MILLISECONDS); } }
diff --git a/libartservice/service/java/com/android/server/art/DexUseManagerLocal.java b/libartservice/service/java/com/android/server/art/DexUseManagerLocal.java index c73f71b..b9d0afe 100644 --- a/libartservice/service/java/com/android/server/art/DexUseManagerLocal.java +++ b/libartservice/service/java/com/android/server/art/DexUseManagerLocal.java
@@ -1173,7 +1173,7 @@ @NonNull public ScheduledExecutorService createScheduledExecutor() { - return Executors.newSingleThreadScheduledExecutor(); + return Executors.newScheduledThreadPool(1 /* corePoolSize */); } @NonNull
diff --git a/libartservice/service/java/com/android/server/art/ReasonMapping.java b/libartservice/service/java/com/android/server/art/ReasonMapping.java index 7c64abf..2a1c81b 100644 --- a/libartservice/service/java/com/android/server/art/ReasonMapping.java +++ b/libartservice/service/java/com/android/server/art/ReasonMapping.java
@@ -188,13 +188,14 @@ /** * Loads the concurrency from the system property, for batch dexopt ({@link - * ArtManagerLocal#dexoptPackages}), or 1 if the system property is not found or cannot be - * parsed. + * ArtManagerLocal#dexoptPackages}). The default is tuned to strike a good balance between + * device load and dexopt coverage, depending on the situation. * * @hide */ public static int getConcurrencyForReason(@NonNull @BatchDexoptReason String reason) { return SystemProperties.getInt("persist.device_config.runtime." + reason + "_concurrency", - SystemProperties.getInt("pm.dexopt." + reason + ".concurrency", 1 /* def */)); + SystemProperties.getInt("pm.dexopt." + reason + ".concurrency", + reason.equals(REASON_BG_DEXOPT) ? 4 : 1 /* def */)); } }
diff --git a/libartservice/service/javatests/com/android/server/art/DebouncerTest.java b/libartservice/service/javatests/com/android/server/art/DebouncerTest.java index bf0bc70..cf6eee4 100644 --- a/libartservice/service/javatests/com/android/server/art/DebouncerTest.java +++ b/libartservice/service/javatests/com/android/server/art/DebouncerTest.java
@@ -61,5 +61,13 @@ mMockClock.advanceTime(1000); assertThat(list).containsExactly(2, 5).inOrder(); + + // Verify that we don't create too many executors, and all the executors we create are + // eventually shut down. + List<MockClock.ScheduledExecutor> executors = mMockClock.getCreatedExecutors(); + assertThat(executors).hasSize(2); + for (MockClock.ScheduledExecutor executor : executors) { + assertThat(executor.isShutdown()).isTrue(); + } } }
diff --git a/libartservice/service/javatests/com/android/server/art/testing/MockClock.java b/libartservice/service/javatests/com/android/server/art/testing/MockClock.java index 7b4b23b..fb77f09 100644 --- a/libartservice/service/javatests/com/android/server/art/testing/MockClock.java +++ b/libartservice/service/javatests/com/android/server/art/testing/MockClock.java
@@ -50,6 +50,11 @@ } } + @NonNull + public List<ScheduledExecutor> getCreatedExecutors() { + return mExecutors; + } + public class ScheduledExecutor extends ScheduledThreadPoolExecutor { // The second element of the pair is the scheduled time. @NonNull
diff --git a/libnativebridge/tests/Android.bp b/libnativebridge/tests/Android.bp index b2d29f1..dc6965f 100644 --- a/libnativebridge/tests/Android.bp +++ b/libnativebridge/tests/Android.bp
@@ -82,14 +82,13 @@ defaults: ["libnativebridge-test-case-defaults"], } -cc_defaults { - name: "libnativebridge-tests-defaults", +cc_test { + name: "libnativebridge-tests", defaults: [ "art_defaults", "art_test_defaults", ], - // TODO(mast): Split up art_gtest_defaults so that it can be used for the - // following without pulling in lots of libs. + target: { linux: { cflags: [ @@ -100,11 +99,6 @@ ], }, }, -} - -cc_test { - name: "libnativebridge-tests", - defaults: ["libnativebridge-tests-defaults"], // native_bridge.cc doesn't support reloading the native bridge after // unloading, so each test needs to be its own process. @@ -154,35 +148,14 @@ header_libs: ["libbase_headers"], } -// Variant of libnativebridge-tests that is part of CTS to verify backed-by API -// coverage. +// Very basic tests in CTS to verify backed-by API coverage of the exported API +// in libnativebridge.map.txt. cc_test { name: "art_libnativebridge_cts_tests", - defaults: [ - "art_standalone_test_defaults", - "libnativebridge-tests-defaults", - ], - - // TODO(b/189484095): Pick only a subset of the tests in - // libnativebridge-tests that don't require the native bridge lib to be - // loaded, to avoid the problems with test_per_src and pushing the extra - // libnativebridge*-test-case.so files to device through tradefed. - srcs: [ - // ValidNameNativeBridge_test.cpp needs to be first due to global state - // had_error that isn't reset between tests. - "ValidNameNativeBridge_test.cpp", - "NeedsNativeBridge_test.cpp", - "UnavailableNativeBridge_test.cpp", - ], - static_libs: [ - "libdl_android", - "libnativebridge", - ], - shared_libs: [ - "liblog", - ], - header_libs: ["libbase_headers"], - + defaults: ["art_standalone_test_defaults"], + shared_libs: ["libnativebridge"], + static_libs: ["libbase"], + srcs: ["libnativebridge_api_test.cpp"], test_config_template: ":art-gtests-target-standalone-cts-template", test_suites: [ "cts", @@ -194,12 +167,10 @@ cc_test { name: "libnativebridge-lazy-tests", - defaults: ["libnativebridge-tests-defaults"], - host_supported: false, - test_suites: ["device-tests"], + defaults: ["art_standalone_test_defaults"], static_libs: [ "libbase", "libnativebridge_lazy", ], - srcs: ["libnativebridge_lazy_test.cpp"], + srcs: ["libnativebridge_api_test.cpp"], }
diff --git a/libnativebridge/tests/libnativebridge_lazy_test.cpp b/libnativebridge/tests/libnativebridge_api_test.cpp similarity index 74% rename from libnativebridge/tests/libnativebridge_lazy_test.cpp rename to libnativebridge/tests/libnativebridge_api_test.cpp index e1d66f5..037587c 100644 --- a/libnativebridge/tests/libnativebridge_lazy_test.cpp +++ b/libnativebridge/tests/libnativebridge_api_test.cpp
@@ -21,33 +21,34 @@ namespace android { -class NativeBridgeLazyTest : public ::testing::Test {}; +class NativeBridgeApiTest : public ::testing::Test {}; +// Test the exported API in libnativebridge and libnativebridge_lazy. // The testing we can do here is limited since there's no exported API to // actually load the native bridge, but we only need to test the trivial // wrappers. -TEST_F(NativeBridgeLazyTest, NeedsNativeBridge) { +TEST_F(NativeBridgeApiTest, NeedsNativeBridge) { EXPECT_FALSE(NeedsNativeBridge(ABI_STRING)); } -TEST_F(NativeBridgeLazyTest, PreInitializeNativeBridge) { +TEST_F(NativeBridgeApiTest, PreInitializeNativeBridge) { EXPECT_FALSE(PreInitializeNativeBridge(nullptr, "")); } -TEST_F(NativeBridgeLazyTest, NativeBridgeAvailable) { +TEST_F(NativeBridgeApiTest, NativeBridgeAvailable) { EXPECT_FALSE(NativeBridgeAvailable()); } -TEST_F(NativeBridgeLazyTest, NativeBridgeInitialized) { +TEST_F(NativeBridgeApiTest, NativeBridgeInitialized) { EXPECT_FALSE(NativeBridgeInitialized()); } -TEST_F(NativeBridgeLazyTest, NativeBridgeGetTrampoline) { +TEST_F(NativeBridgeApiTest, NativeBridgeGetTrampoline) { EXPECT_EQ(nullptr, NativeBridgeGetTrampoline(nullptr, nullptr, nullptr, 0)); } -TEST_F(NativeBridgeLazyTest, NativeBridgeGetError) { +TEST_F(NativeBridgeApiTest, NativeBridgeGetError) { EXPECT_STREQ("native bridge is not initialized", NativeBridgeGetError()); }
diff --git a/odrefresh/Android.bp b/odrefresh/Android.bp index 809e18d..071d8ba 100644 --- a/odrefresh/Android.bp +++ b/odrefresh/Android.bp
@@ -168,7 +168,10 @@ "odr_metrics_record.cc", "odr_statslog_android.cc", ], - shared_libs: ["libstatssocket"], + shared_libs: [ + "libstatspull", + "libstatssocket", + ], }, host: { srcs: ["odr_statslog_host.cc"],
diff --git a/runtime/Android.bp b/runtime/Android.bp index 1c4b871..2f655b1 100644 --- a/runtime/Android.bp +++ b/runtime/Android.bp
@@ -444,7 +444,8 @@ ], shared_libs: [ "libdl_android", - "libstatssocket", + "libstatspull", // for pulled atoms + "libstatssocket", // for pulled atoms "libz", // For adler32. "heapprofd_client_api", ], @@ -1061,6 +1062,7 @@ export_generated_headers: ["statslog_art.h"], shared_libs: [ "liblog", + "libstatspull", "libstatssocket", "libutils", ],
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 4e18987..a5a9e9c 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc
@@ -2234,7 +2234,10 @@ // boot image method optimization. We need to disable it before doing // ResetCounter below, as counters of shared memory method always hold the // "hot" value. - if (runtime->GetJITOptions()->GetProfileSaverOptions().GetProfileBootClassPath()) { + // For debuggable runtimes we don't use AOT code, so don't use shared memory + // optimization so the methods can be JITed better. + if (runtime->GetJITOptions()->GetProfileSaverOptions().GetProfileBootClassPath() || + runtime->IsJavaDebuggable()) { header.VisitPackedArtMethods([&](ArtMethod& method) REQUIRES_SHARED(Locks::mutator_lock_) { method.ClearMemorySharedMethod(); }, space->Begin(), image_pointer_size_);
diff --git a/runtime/fault_handler.cc b/runtime/fault_handler.cc index 652368c..6f1452e 100644 --- a/runtime/fault_handler.cc +++ b/runtime/fault_handler.cc
@@ -43,12 +43,16 @@ // Static fault manger object accessed by signal handler. FaultManager fault_manager; -// This needs to be NO_INLINE since some debuggers do not read the inline-info to set a breakpoint -// if it isn't. +// These need to be NO_INLINE since some debuggers do not read the inline-info to set a breakpoint +// if they aren't. extern "C" NO_INLINE __attribute__((visibility("default"))) void art_sigsegv_fault() { // Set a breakpoint here to be informed when a SIGSEGV is unhandled by ART. VLOG(signals)<< "Caught unknown SIGSEGV in ART fault handler - chaining to next handler."; } +extern "C" NO_INLINE __attribute__((visibility("default"))) void art_sigbus_fault() { + // Set a breakpoint here to be informed when a SIGBUS is unhandled by ART. + VLOG(signals) << "Caught unknown SIGBUS in ART fault handler - chaining to next handler."; +} // Signal handler called on SIGSEGV. static bool art_sigsegv_handler(int sig, siginfo_t* info, void* context) { @@ -233,7 +237,13 @@ // Simulate a crash in a handler. raise(SIGBUS); #endif - return Runtime::Current()->GetHeap()->MarkCompactCollector()->SigbusHandler(info); + if (Runtime::Current()->GetHeap()->MarkCompactCollector()->SigbusHandler(info)) { + return true; + } + + // Set a breakpoint in this function to catch unhandled signals. + art_sigbus_fault(); + return false; } inline void FaultManager::CheckForUnrecognizedImplicitSuspendCheckInBootImage(
diff --git a/runtime/gc/verification.h b/runtime/gc/verification.h index 7a5d01a..a732556 100644 --- a/runtime/gc/verification.h +++ b/runtime/gc/verification.h
@@ -40,7 +40,7 @@ public: explicit Verification(gc::Heap* heap) : heap_(heap) {} - // Dump some reveant to debugging info about an object. + // Dump some debugging-relevant info about an object. std::string DumpObjectInfo(const void* obj, const char* tag) const REQUIRES_SHARED(Locks::mutator_lock_);
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc index 3472c78..b231cce 100644 --- a/runtime/jit/jit.cc +++ b/runtime/jit/jit.cc
@@ -71,7 +71,7 @@ static constexpr uint32_t kJitSlowStressDefaultOptimizeThreshold = kJitStressDefaultOptimizeThreshold / 2; -static constexpr uint32_t kJitDefaultWarmupThreshold = 0x3fff; +static constexpr uint32_t kJitDefaultWarmupThreshold = 0xffff; // Different warm-up threshold constants. These default to the equivalent warmup thresholds divided // by 2, but can be overridden at the command-line. static constexpr uint32_t kJitStressDefaultWarmupThreshold = kJitDefaultWarmupThreshold / 2;
diff --git a/runtime/metrics/statsd.cc b/runtime/metrics/statsd.cc index 2105bdb..6d96c6f 100644 --- a/runtime/metrics/statsd.cc +++ b/runtime/metrics/statsd.cc
@@ -414,18 +414,30 @@ std::unique_ptr<MetricsBackend> CreateStatsdBackend() { return std::make_unique<StatsdBackend>(); } -void ReportDeviceMetrics() { - Runtime* runtime = Runtime::Current(); - int32_t boot_image_status; - if (runtime->GetHeap()->HasBootImageSpace() && !runtime->HasImageWithProfile()) { - boot_image_status = statsd::ART_DEVICE_DATUM_REPORTED__BOOT_IMAGE_STATUS__STATUS_FULL; - } else if (runtime->GetHeap()->HasBootImageSpace() && - runtime->GetHeap()->GetBootImageSpaces()[0]->GetProfileFiles().empty()) { - boot_image_status = statsd::ART_DEVICE_DATUM_REPORTED__BOOT_IMAGE_STATUS__STATUS_MINIMAL; - } else { - boot_image_status = statsd::ART_DEVICE_DATUM_REPORTED__BOOT_IMAGE_STATUS__STATUS_NONE; +AStatsManager_PullAtomCallbackReturn DeviceStatusCallback(int32_t atom_tag, + AStatsEventList* data, + [[maybe_unused]] void* cookie) { + if (atom_tag == statsd::ART_DEVICE_STATUS) { + Runtime* runtime = Runtime::Current(); + int32_t boot_image_status; + if (runtime->GetHeap()->HasBootImageSpace() && !runtime->HasImageWithProfile()) { + boot_image_status = statsd::ART_DEVICE_DATUM_REPORTED__BOOT_IMAGE_STATUS__STATUS_FULL; + } else if (runtime->GetHeap()->HasBootImageSpace() && + runtime->GetHeap()->GetBootImageSpaces()[0]->GetProfileFiles().empty()) { + boot_image_status = statsd::ART_DEVICE_DATUM_REPORTED__BOOT_IMAGE_STATUS__STATUS_MINIMAL; + } else { + boot_image_status = statsd::ART_DEVICE_DATUM_REPORTED__BOOT_IMAGE_STATUS__STATUS_NONE; + } + statsd::addAStatsEvent(data, atom_tag, boot_image_status); + return AStatsManager_PULL_SUCCESS; } - statsd::stats_write(statsd::ART_DEVICE_DATUM_REPORTED, boot_image_status); + + return AStatsManager_PULL_SKIP; +} + +void SetupCallbackForDeviceStatus() { + AStatsManager_setPullAtomCallback( + statsd::ART_DEVICE_STATUS, /*metadata=*/nullptr, DeviceStatusCallback, /*cookie=*/nullptr); } } // namespace metrics
diff --git a/runtime/metrics/statsd.h b/runtime/metrics/statsd.h index cb84825..77c0f1d 100644 --- a/runtime/metrics/statsd.h +++ b/runtime/metrics/statsd.h
@@ -27,10 +27,10 @@ // Statsd is only supported on Android #ifdef __ANDROID__ std::unique_ptr<MetricsBackend> CreateStatsdBackend(); -void ReportDeviceMetrics(); +void SetupCallbackForDeviceStatus(); #else inline std::unique_ptr<MetricsBackend> CreateStatsdBackend() { return nullptr; } -inline void ReportDeviceMetrics() {} +inline void SetupCallbackForDeviceStatus() {} #endif } // namespace metrics
diff --git a/runtime/monitor.cc b/runtime/monitor.cc index 3fed8d4..ef2a137 100644 --- a/runtime/monitor.cc +++ b/runtime/monitor.cc
@@ -14,12 +14,11 @@ * limitations under the License. */ -#include "monitor-inl.h" +#include <android-base/properties.h> #include <vector> #include "android-base/stringprintf.h" - #include "art_method-inl.h" #include "base/logging.h" // For VLOG. #include "base/mutex.h" @@ -32,9 +31,11 @@ #include "dex/dex_file_types.h" #include "dex/dex_instruction-inl.h" #include "entrypoints/entrypoint_utils-inl.h" +#include "gc/verification-inl.h" #include "lock_word-inl.h" #include "mirror/class-inl.h" #include "mirror/object-inl.h" +#include "monitor-inl.h" #include "object_callbacks.h" #include "scoped_thread_state_change-inl.h" #include "stack.h" @@ -42,7 +43,6 @@ #include "thread_list.h" #include "verifier/method_verifier.h" #include "well_known_classes.h" -#include <android-base/properties.h> static_assert(ART_USE_FUTEXES); @@ -1522,18 +1522,29 @@ // not be optimized out. success = stack_visitor->GetVReg(m, dex_reg, kReferenceVReg, &value); if (success) { - ObjPtr<mirror::Object> o = reinterpret_cast<mirror::Object*>(value); - callback(o, callback_context); - break; + mirror::Object* mp = reinterpret_cast<mirror::Object*>(value); + // TODO(b/299577730) Remove the extra checks here once the underlying bug is fixed. + const gc::Verification* v = Runtime::Current()->GetHeap()->GetVerification(); + if (v->IsValidObject(mp)) { + ObjPtr<mirror::Object> o = mp; + callback(o, callback_context); + break; + } else { + LOG(ERROR) << "Encountered bad lock object: " << std::hex << value << std::dec; + success = false; + } } } - DCHECK(success) << "Failed to find/read reference for monitor-enter at dex pc " - << dex_lock_info.dex_pc - << " in method " - << m->PrettyMethod(); if (!success) { - LOG(WARNING) << "Had a lock reported for dex pc " << dex_lock_info.dex_pc - << " but was not able to fetch a corresponding object!"; + LOG(ERROR) << "Failed to find/read reference for monitor-enter at dex pc " + << dex_lock_info.dex_pc << " in method " << m->PrettyMethod(); + if (kIsDebugBuild) { + // Crash only in debug ART builds. + LOG(FATAL) << "Had a lock reported for a dex pc " + "but was not able to fetch a corresponding object!"; + } else { + LOG(ERROR) << "Held monitor information in stack trace will be incomplete!"; + } } } }
diff --git a/runtime/runtime.cc b/runtime/runtime.cc index 7eff246..e225d9e 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc
@@ -1299,7 +1299,7 @@ if (!odrefresh::UploadStatsIfAvailable(&err)) { LOG(WARNING) << "Failed to upload odrefresh metrics: " << err; } - metrics::ReportDeviceMetrics(); + metrics::SetupCallbackForDeviceStatus(); } if (LIKELY(automatically_set_jni_ids_indirection_) && CanSetJniIdType()) { @@ -3333,10 +3333,12 @@ return callbacks_.get(); } -// Used to patch boot image method entry point to interpreter bridge. -class UpdateEntryPointsClassVisitor : public ClassVisitor { +// Used to update boot image to not use AOT code. This is used when transitioning the runtime to +// java debuggable. This visitor re-initializes the entry points without using AOT code. This also +// disables shared hotness counters so the necessary methods can be JITed more efficiently. +class DeoptimizeBootImageClassVisitor : public ClassVisitor { public: - explicit UpdateEntryPointsClassVisitor(instrumentation::Instrumentation* instrumentation) + explicit DeoptimizeBootImageClassVisitor(instrumentation::Instrumentation* instrumentation) : instrumentation_(instrumentation) {} bool operator()(ObjPtr<mirror::Class> klass) override REQUIRES(Locks::mutator_lock_) { @@ -3370,6 +3372,9 @@ m.ClearPreCompiled(); instrumentation_->InitializeMethodsCode(&m, /*aot_code=*/ nullptr); } + + // Clear MemorySharedAccessFlags so the boot class methods can be JITed better. + m.ClearMemorySharedMethod(); } return true; } @@ -3390,7 +3395,7 @@ // If we've already started and we are setting this runtime to debuggable, // we patch entry points of methods in boot image to interpreter bridge, as // boot image code may be AOT compiled as not debuggable. - UpdateEntryPointsClassVisitor visitor(GetInstrumentation()); + DeoptimizeBootImageClassVisitor visitor(GetInstrumentation()); GetClassLinker()->VisitClasses(&visitor); jit::Jit* jit = GetJit(); if (jit != nullptr) {
diff --git a/runtime/trace.cc b/runtime/trace.cc index 81c86f1..20436d6 100644 --- a/runtime/trace.cc +++ b/runtime/trace.cc
@@ -774,6 +774,15 @@ CHECK_IMPLIES(trace_file == nullptr, output_mode == TraceOutputMode::kDDMS); uint16_t trace_version = GetTraceVersion(clock_source_); + + // We initialize the start_time_ from the timestamp counter. This may not match + // with the monotonic timer but we only use this time to calculate the elapsed + // time from this point which should be the same for both cases. + // We record monotonic time at the start of the trace, because Android Studio + // fetches the monotonic timer from other places and matches these times to + // construct a cpu profile. See b/318052824 for more context. + uint64_t start_time_monotonic = start_time_ + (MicroTime() - GetMicroTime(GetTimestamp())); + if (output_mode == TraceOutputMode::kStreaming) { trace_version |= 0xF0U; } @@ -782,7 +791,7 @@ Append4LE(buf_.get(), kTraceMagicValue); Append2LE(buf_.get() + 4, trace_version); Append2LE(buf_.get() + 6, kTraceHeaderLength); - Append8LE(buf_.get() + 8, start_time_); + Append8LE(buf_.get() + 8, start_time_monotonic); if (trace_version >= kTraceVersionDualClock) { uint16_t record_size = GetRecordSize(clock_source_); Append2LE(buf_.get() + 16, record_size);