Commit b5fb1575 authored by Mike Wittman's avatar Mike Wittman Committed by Commit Bot

[Sampling profiler] Add Android unwinder DFM infrastructure

Adds the infrastructure to support a dynamic feature module for Android
stack unwinding. This module will provide the native code implementation
of a stack unwinder supporting unwinding of stack frames corresponding
to native system libraries and Java code.

This CL contains just the infrastructure to set up the DFM, which
is derived from the existing 'test dummy' DFM. The stack unwinder
implementation and the use of the module from Chrome code are deferred
to later CLs.

Bug: 1027654
Change-Id: I4b5dca1294fa1aa8197eab4544a03dd7d5bc48a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1934774
Commit-Queue: Mike Wittman <wittman@chromium.org>
Reviewed-by: default avatarChristopher Grant <cjgrant@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Auto-Submit: Mike Wittman <wittman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719373}
parent b6702238
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/buildflag_header.gni")
import("//build/config/android/rules.gni")
import("//chrome/android/modules/buildflags.gni")
android_library("java") {
deps = [
"//base:base_java",
"//chrome/android/features/stack_unwinder/public:java",
]
java_files = [ "java/src/org/chromium/chrome/features/stack_unwinder/StackUnwinderImpl.java" ]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
deps += [ "//base:jni_java" ]
}
source_set("native") {
sources = [
"stack_unwinder_impl.cc",
]
deps = [
":jni_headers",
"//base",
"//ui/base",
]
}
generate_jni("jni_headers") {
sources = [
"java/src/org/chromium/chrome/features/stack_unwinder/StackUnwinderImpl.java",
]
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.features.stack_unwinder;
import org.chromium.base.annotations.NativeMethods;
/** Stack unwinder implementation. */
public class StackUnwinderImpl implements StackUnwinder {
private static final String TAG = "StackUnwinderImpl";
@Override
public void registerUnwinder() {
StackUnwinderImplJni.get().registerUnwinder();
}
@NativeMethods
interface Natives {
void registerUnwinder();
}
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/logging.h"
#include "chrome/android/features/stack_unwinder/internal/jni_headers/StackUnwinderImpl_jni.h"
static void JNI_StackUnwinderImpl_RegisterUnwinder(JNIEnv* env) {
// TODO(wittman): Create the native Android unwinder and register with
// base::StackSamplingProfiler.
}
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/android/rules.gni")
android_library("java") {
java_files = [
"java/src/org/chromium/chrome/features/stack_unwinder/StackUnwinder.java",
]
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.features.stack_unwinder;
/** Provides a mechanism to register the native unwinder. */
public interface StackUnwinder {
/**
* Registers the native unwinder with the StackSamplingProfiler.
*/
void registerUnwinder();
}
......@@ -11,6 +11,7 @@ import("//chrome/android/modules/buildflags.gni")
import("//chrome/android/modules/chime/chime_module.gni")
import("//chrome/android/modules/extra_icu/extra_icu_module.gni")
import("//chrome/android/modules/image_editor/image_editor_module.gni")
import("//chrome/android/modules/stack_unwinder/stack_unwinder_module.gni")
import("//chrome/android/modules/test_dummy/test_dummy_module.gni")
import("//device/vr/buildflags/buildflags.gni")
......@@ -42,6 +43,7 @@ if (enable_arcore) {
chrome_modern_module_descs = [
test_dummy_module_desc,
extra_icu_module_desc,
stack_unwinder_module_desc,
]
if (enable_vr) {
chrome_modern_module_descs += [ vr_module_desc ]
......
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/android/rules.gni")
import("//chrome/android/modules/buildflags.gni")
android_library("java") {
java_files = [ "java/src/org/chromium/chrome/modules/stack_unwinder/StackUnwinderProviderImpl.java" ]
deps = [
"//base:base_java",
"//chrome/android/features/stack_unwinder/internal:java",
"//chrome/android/features/stack_unwinder/public:java",
"//chrome/android/modules/stack_unwinder/public:java",
]
}
# This group is effectively an alias representing the module's native code,
# allowing it to be named "native" for clarity in module descriptors. The
# component target must be named according to the feature, so that the component
# build's .cr.co library is named properly (ie. libstack_unwinder.cr.so).
group("native") {
deps = [
":stack_unwinder",
]
}
component("stack_unwinder") {
sources = [
"entrypoints.cc",
]
deps = [
":jni_registration",
"//base",
"//chrome/android/features/stack_unwinder/internal:native",
]
# stack unwinder native entrypoints belong in the partition.
if (use_native_partitions) {
cflags = [ "-fsymbol-partition=stack_unwinder_partition" ]
}
}
# TODO(https://crbug.com/1008109): Adapt JNI registration to point at a Java
# target, instead of an APK/module target. This JNI registration target
# points at ChromeModern's module, but it's used by Monochrome as well, since
# both variants do explicit JNI registration in DFMs (for consistency).
#
# Alternatively, move to lazy JNI init for DFMs in Monochrome, by conditionally
# including a registration stub, as Chrome's base library does. That requires
# two sets of registration targets, so that the feature module template can
# selectively pull in the real version or a stub.
generate_jni_registration("jni_registration") {
target = "//chrome/android:chrome_modern_public_bundle__stack_unwinder_bundle_module"
header_output = "$target_gen_dir/jni_registration.h"
namespace = "stack_unwinder"
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/android/jni_utils.h"
#include "chrome/android/modules/stack_unwinder/internal/jni_registration.h"
extern "C" {
// This JNI registration method is found and called by module framework code.
__attribute__((visibility("default"))) bool JNI_OnLoad_stack_unwinder(
JNIEnv* env) {
if (!base::android::IsSelectiveJniRegistrationEnabled(env) &&
!stack_unwinder::RegisterNonMainDexNatives(env)) {
return false;
}
if (!stack_unwinder::RegisterMainDexNatives(env)) {
return false;
}
return true;
}
} // extern "C"
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2019 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
featureSplit="stack_unwinder">
<dist:module
dist:onDemand="true"
dist:title="@string/stack_unwinder_module_title">
<dist:fusing dist:include="true" />
</dist:module>
<application />
</manifest>
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.modules.stack_unwinder;
import org.chromium.base.annotations.UsedByReflection;
import org.chromium.chrome.features.stack_unwinder.StackUnwinder;
import org.chromium.chrome.features.stack_unwinder.StackUnwinderImpl;
/** Provides the stack unwinder implementation inside the stack unwinder module. */
@UsedByReflection("StackUnwinderModule")
public class StackUnwinderProviderImpl implements StackUnwinderProvider {
private final StackUnwinderImpl mStackUnwinder = new StackUnwinderImpl();
@Override
public StackUnwinder getStackUnwinder() {
return mStackUnwinder;
}
}
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/android/rules.gni")
android_library("java") {
deps = [
"//base:base_java",
"//base:jni_java",
"//chrome/android/features/stack_unwinder/public:java",
"//chrome/android/modules/stack_unwinder/public:java",
]
java_files = [ "java/src/org/chromium/chrome/modules/stack_unwinder/StackUnwinderModuleProvider.java" ]
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.modules.stack_unwinder;
import org.chromium.components.module_installer.engine.InstallListener;
/** Installs and loads the stack unwinder module. */
public class StackUnwinderModuleProvider {
/** Returns true if the module is installed. */
public static boolean isModuleInstalled() {
return StackUnwinderModule.isInstalled();
}
/**
* Installs the module.
*
* Can only be called if the module is not installed.
*
* @param listener Called when the install has finished.
*/
public static void installModule(InstallListener listener) {
StackUnwinderModule.install(listener);
}
/**
* Returns the stack unwinder provider from inside the module.
*
* Can only be called if the module is installed. Maps native resources into memory on first
* call.
*/
public static StackUnwinderProvider getStackUnwinderProvider() {
return StackUnwinderModule.getImpl();
}
}
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/android/rules.gni")
android_library("java") {
java_files = [ "java/src/org/chromium/chrome/modules/stack_unwinder/StackUnwinderProvider.java" ]
deps = [
"//base:base_java",
"//chrome/android/features/stack_unwinder/public:java",
"//components/module_installer/android:module_installer_java",
"//components/module_installer/android:module_interface_java",
]
annotation_processor_deps =
[ "//components/module_installer/android:module_interface_processor" ]
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.modules.stack_unwinder;
import org.chromium.chrome.features.stack_unwinder.StackUnwinder;
import org.chromium.components.module_installer.builder.ModuleInterface;
/** Provides the stack unwinder implementation. */
@ModuleInterface(module = "stack_unwinder",
impl = "org.chromium.chrome.modules.stack_unwinder.StackUnwinderProviderImpl")
public interface StackUnwinderProvider {
StackUnwinder getStackUnwinder();
}
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//chrome/android/modules/buildflags.gni")
stack_unwinder_module_desc = {
name = "stack_unwinder"
android_manifest = "//chrome/android/modules/stack_unwinder/internal/java/AndroidManifest.xml"
java_deps = [
"//chrome/android/features/stack_unwinder/internal:java",
"//chrome/android/modules/stack_unwinder/internal:java",
]
native_deps = [
"//chrome/android/features/stack_unwinder/internal:native",
"//chrome/android/modules/stack_unwinder/internal:native",
]
}
......@@ -4031,6 +4031,13 @@ The site does NOT gain access to the camera. The camera images are only visible
Test Dummy
</message>
<message name="IDS_STACK_UNWINDER_MODULE_TITLE"
desc="Text shown when the stack unwinder module is referenced in install start, success,
failure UI (e.g. in IDS_MODULE_INSTALL_START_TEXT, which will expand to
'Installing Stack Unwinder for Chrome…').">
Stack Unwinder
</message>
<message name="IDS_EXTRA_ICU_MODULE_TITLE"
desc="Text shown when the extra ICU module is referenced in install start, success,
failure UI (e.g. in IDS_MODULE_INSTALL_START_TEXT, which will expand to
......
......@@ -237,6 +237,9 @@
"META": {"align": 100},
"includes": [12200],
},
"chrome/android/features/stack_unwinder/internal/resources/resources.grd": {
"includes": [12205],
},
"chrome/common/common_resources.grd": {
"includes": [12210],
},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment