• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "base/profiler/stack_sampling_profiler_java_test_util.h"
6 
7 #include "base/location.h"
8 
9 // Must come after all headers that specialize FromJniType() / ToJniType().
10 #include "base/base_profiler_test_support_jni/TestSupport_jni.h"
11 
12 namespace base {
13 
14 namespace {
15 
16 struct UnwinderJavaTestSupportParams {
17   OnceClosure closure;
18   FunctionAddressRange range;
19 };
20 
21 }  // namespace
22 
JNI_TestSupport_InvokeCallbackFunction(JNIEnv * env,jlong context)23 void JNI_TestSupport_InvokeCallbackFunction(JNIEnv* env, jlong context) {
24   const void* start_program_counter = GetProgramCounter();
25 
26   UnwinderJavaTestSupportParams* params =
27       reinterpret_cast<UnwinderJavaTestSupportParams*>(context);
28   if (!params->closure.is_null()) {
29     std::move(params->closure).Run();
30   }
31 
32   // Volatile to prevent a tail call to GetProgramCounter().
33   const void* volatile end_program_counter = GetProgramCounter();
34 
35   params->range = {start_program_counter, end_program_counter};
36 }
37 
callWithJavaFunction(OnceClosure closure)38 FunctionAddressRange callWithJavaFunction(OnceClosure closure) {
39   JNIEnv* env = jni_zero::AttachCurrentThread();
40   UnwinderJavaTestSupportParams params{std::move(closure), {}};
41   base::Java_TestSupport_callWithJavaFunction(
42       env, reinterpret_cast<uintptr_t>(&params));
43   return params.range;
44 }
45 
46 }  // namespace base
47