Commit 5a1b43cd authored by Mike Wittman's avatar Mike Wittman Committed by Commit Bot

[Sampling profiler] Eliminate unneeded Java interfaces for stack_unwinder

Strips the stack_unwinder module interfaces and contents down to the
minimal Java required to get the dynamic feature module to work from
native code. The module will be providing native code interfaces[1],
which will be consumed by native code, so it doesn't make sense to
interpose more Java than necessary in between. It's also the case that
the parts of the DFM Java API that deal with the Play Store can't be
used within the sandboxed renderer process.

This change exposes via JNI the StackUnwinderModuleProvider's functions
to query and request installation. This is the only Java-provided
functionality that will be required for manipulating the module from
native code.

1. Design doc: https://docs.google.com/document/d/1QB5IzWuVKfoPdPuiyRok2MUEta1FmRLIQkq1wDATA4k

Bug: 1027654
Change-Id: Ie69e687335a753c17206fc6c81ae981118c698b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2003298Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarEtienne Pierre-Doray <etiennep@chromium.org>
Reviewed-by: default avatarFred Mello <fredmello@chromium.org>
Reviewed-by: default avatarSamuel Huang <huangs@chromium.org>
Commit-Queue: Mike Wittman <wittman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734653}
parent bf0c5673
# 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",
]
sources = [ "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") {
sources = [
"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();
}
...@@ -6,11 +6,9 @@ import("//build/config/android/rules.gni") ...@@ -6,11 +6,9 @@ import("//build/config/android/rules.gni")
import("//chrome/android/modules/buildflags.gni") import("//chrome/android/modules/buildflags.gni")
android_library("java") { android_library("java") {
sources = [ "java/src/org/chromium/chrome/modules/stack_unwinder/StackUnwinderProviderImpl.java" ] sources = [ "java/src/org/chromium/chrome/modules/stack_unwinder/StackUnwinderDummyImpl.java" ]
deps = [ deps = [
"//base:base_java", "//base:base_java",
"//chrome/android/features/stack_unwinder/internal:java",
"//chrome/android/features/stack_unwinder/public:java",
"//chrome/android/modules/stack_unwinder/public:java", "//chrome/android/modules/stack_unwinder/public:java",
] ]
} }
...@@ -25,21 +23,10 @@ group("native") { ...@@ -25,21 +23,10 @@ group("native") {
component("stack_unwinder") { component("stack_unwinder") {
sources = [ "entrypoints.cc" ] sources = [ "entrypoints.cc" ]
deps = [ deps = [ "//base" ]
":jni_registration",
"//base",
"//chrome/android/features/stack_unwinder/internal:native",
]
# stack unwinder native entrypoints belong in the partition. # stack unwinder native entrypoints belong in the partition.
if (use_native_partitions) { if (use_native_partitions) {
cflags = [ "-fsymbol-partition=stack_unwinder_partition" ] cflags = [ "-fsymbol-partition=stack_unwinder_partition" ]
} }
} }
generate_jni_registration("jni_registration") {
targets = [ "//chrome/android/features/stack_unwinder/internal:java" ]
header_output = "$target_gen_dir/jni_registration.h"
namespace = "stack_unwinder"
no_transitive_deps = true
}
...@@ -4,18 +4,12 @@ ...@@ -4,18 +4,12 @@
#include "base/android/jni_generator/jni_generator_helper.h" #include "base/android/jni_generator/jni_generator_helper.h"
#include "base/android/jni_utils.h" #include "base/android/jni_utils.h"
#include "chrome/android/modules/stack_unwinder/internal/jni_registration.h" #include "base/profiler/unwinder.h"
extern "C" { extern "C" {
// This JNI registration method is found and called by module framework code. // This JNI registration method is found and called by module framework
// code. Empty because we have no JNI items to register within the module code.
JNI_GENERATOR_EXPORT bool JNI_OnLoad_stack_unwinder(JNIEnv* env) { JNI_GENERATOR_EXPORT 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; return true;
} }
......
...@@ -5,16 +5,11 @@ ...@@ -5,16 +5,11 @@
package org.chromium.chrome.modules.stack_unwinder; package org.chromium.chrome.modules.stack_unwinder;
import org.chromium.base.annotations.UsedByReflection; 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. */ /**
* Provides the required Java implementation for the dynamic feature module, which is intended to
* implement the module functionality. This class is empty since we access the module contents
* strictly via native code.
*/
@UsedByReflection("StackUnwinderModule") @UsedByReflection("StackUnwinderModule")
public class StackUnwinderProviderImpl implements StackUnwinderProvider { public class StackUnwinderDummyImpl implements StackUnwinderDummyInterface {}
private final StackUnwinderImpl mStackUnwinder = new StackUnwinderImpl();
@Override
public StackUnwinder getStackUnwinder() {
return mStackUnwinder;
}
}
...@@ -8,8 +8,12 @@ android_library("java") { ...@@ -8,8 +8,12 @@ android_library("java") {
deps = [ deps = [
"//base:base_java", "//base:base_java",
"//base:jni_java", "//base:jni_java",
"//chrome/android/features/stack_unwinder/public:java",
"//chrome/android/modules/stack_unwinder/public:java", "//chrome/android/modules/stack_unwinder/public:java",
] ]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
sources = [ "java/src/org/chromium/chrome/modules/stack_unwinder/StackUnwinderModuleProvider.java" ]
}
generate_jni("jni_headers") {
sources = [ "java/src/org/chromium/chrome/modules/stack_unwinder/StackUnwinderModuleProvider.java" ] sources = [ "java/src/org/chromium/chrome/modules/stack_unwinder/StackUnwinderModuleProvider.java" ]
} }
...@@ -4,33 +4,23 @@ ...@@ -4,33 +4,23 @@
package org.chromium.chrome.modules.stack_unwinder; package org.chromium.chrome.modules.stack_unwinder;
import org.chromium.components.module_installer.engine.InstallListener; import org.chromium.base.annotations.CalledByNative;
/** Installs and loads the stack unwinder module. */ /** Installs and loads the stack unwinder module. */
public class StackUnwinderModuleProvider { public class StackUnwinderModuleProvider {
/** Returns true if the module is installed. */ /** Returns true if the module is installed. */
@CalledByNative
public static boolean isModuleInstalled() { public static boolean isModuleInstalled() {
return StackUnwinderModule.isInstalled(); return StackUnwinderModule.isInstalled();
} }
/** /**
* Installs the module. * Installs the module asynchronously.
* *
* Can only be called if the module is not installed. * 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() { @CalledByNative
return StackUnwinderModule.getImpl(); public static void installModule() {
StackUnwinderModule.install((boolean success) -> {});
} }
} }
...@@ -5,10 +5,9 @@ ...@@ -5,10 +5,9 @@
import("//build/config/android/rules.gni") import("//build/config/android/rules.gni")
android_library("java") { android_library("java") {
sources = [ "java/src/org/chromium/chrome/modules/stack_unwinder/StackUnwinderProvider.java" ] sources = [ "java/src/org/chromium/chrome/modules/stack_unwinder/StackUnwinderDummyInterface.java" ]
deps = [ deps = [
"//base:base_java", "//base:base_java",
"//chrome/android/features/stack_unwinder/public:java",
"//components/module_installer/android:module_installer_java", "//components/module_installer/android:module_installer_java",
"//components/module_installer/android:module_interface_java", "//components/module_installer/android:module_interface_java",
] ]
......
...@@ -4,12 +4,13 @@ ...@@ -4,12 +4,13 @@
package org.chromium.chrome.modules.stack_unwinder; package org.chromium.chrome.modules.stack_unwinder;
import org.chromium.chrome.features.stack_unwinder.StackUnwinder;
import org.chromium.components.module_installer.builder.ModuleInterface; import org.chromium.components.module_installer.builder.ModuleInterface;
/** Provides the stack unwinder implementation. */ /**
* Provides the required Java interface for the dynamic feature module, which is intended to
* provide access the module functionality. We access the module contents strictly via native code
* so don't use this interface.
*/
@ModuleInterface(module = "stack_unwinder", @ModuleInterface(module = "stack_unwinder",
impl = "org.chromium.chrome.modules.stack_unwinder.StackUnwinderProviderImpl") impl = "org.chromium.chrome.modules.stack_unwinder.StackUnwinderDummyImpl")
public interface StackUnwinderProvider { public interface StackUnwinderDummyInterface {}
StackUnwinder getStackUnwinder();
}
...@@ -7,12 +7,6 @@ import("//chrome/android/modules/buildflags.gni") ...@@ -7,12 +7,6 @@ import("//chrome/android/modules/buildflags.gni")
stack_unwinder_module_desc = { stack_unwinder_module_desc = {
name = "stack_unwinder" name = "stack_unwinder"
android_manifest = "//chrome/android/modules/stack_unwinder/internal/java/AndroidManifest.xml" android_manifest = "//chrome/android/modules/stack_unwinder/internal/java/AndroidManifest.xml"
java_deps = [ java_deps = [ "//chrome/android/modules/stack_unwinder/internal:java" ]
"//chrome/android/features/stack_unwinder/internal:java", native_deps = [ "//chrome/android/modules/stack_unwinder/internal:native" ]
"//chrome/android/modules/stack_unwinder/internal:java",
]
native_deps = [
"//chrome/android/features/stack_unwinder/internal:native",
"//chrome/android/modules/stack_unwinder/internal:native",
]
} }
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