1 // Copyright 2019 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/profiler/stack_sampling_profiler_java_test_util.h"
7 #include "base/base_profiler_test_support_jni/TestSupport_jni.h"
8 #include "base/location.h"
14 struct UnwinderJavaTestSupportParams {
16 FunctionAddressRange range;
21 void JNI_TestSupport_InvokeCallbackFunction(JNIEnv* env, jlong context) {
22 const void* start_program_counter = GetProgramCounter();
24 UnwinderJavaTestSupportParams* params =
25 reinterpret_cast<UnwinderJavaTestSupportParams*>(context);
26 if (!params->closure.is_null()) {
27 std::move(params->closure).Run();
30 // Volatile to prevent a tail call to GetProgramCounter().
31 const void* volatile end_program_counter = GetProgramCounter();
33 params->range = {start_program_counter, end_program_counter};
36 FunctionAddressRange callWithJavaFunction(OnceClosure closure) {
37 JNIEnv* env = base::android::AttachCurrentThread();
38 UnwinderJavaTestSupportParams params{std::move(closure), {}};
39 base::Java_TestSupport_callWithJavaFunction(
40 env, reinterpret_cast<uintptr_t>(¶ms));