Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Issue 2361353002: Link stack frames of JNI stubs to JNI callbacks. (Closed)

Created:
4 years, 3 months ago by Dmitry Skiba
Modified:
4 years, 1 month ago
CC:
chromium-reviews
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Link stack frames of JNI stubs to JNI callbacks. Chrome's native heap profiler relies on stack frame pointers to unwind. That is fast, but requires that all code in a call chain is built with frame pointer support. Which is not the case for Java / JNI code on Android, so unwinding stops prematurely once it crosses JNI boundary. This CL exploits the fact that both JNI stubs (which call into Java) and JNI callbacks (which are called by Java) are generated. It changes JNI generator to save stack frame pointer in a JNI stub, and later link saved frame pointer to a frame pointer of a JNI callback. That repairs broken stack frame chain and allows unwinder to yield complete trace. Changes in this CL are active only for profiling builds (ones that build with enable_profiling=true). Otherwise JNI generator produces exactly the same code as before (modulo removed empty lines). Example of a complete trace made possible by this CL: <.../base.odex> Java_org_chromium_base_SystemMessageHandler_nativeDoRunLoopOnce base::MessageLoop::DoWork base::MessageLoop::DeferOrRunPendingTask base::MessageLoop::RunTask base::debug::TaskAnnotator::RunTask cc::SingleThreadProxy::BeginMainFrame cc::SingleThreadProxy::DoBeginMainFrame content::CompositorImpl::UpdateLayerTreeHost..............................#4 <.../base.odex> Java_org_chromium_chrome_..._ToolbarSceneLayer_nativeUpdateToolbarLayer...#3 android::ToolbarSceneLayer::UpdateToolbarLayer android::ToolbarLayer::PushResource ui::ResourceManagerImpl::GetResource......................................#2 <.../base.odex> Java_org_chromium_ui_resources_ResourceManager_nativeOnResourceReady......#1 ui::ResourceManagerImpl::OnResourceReady gfx::CreateSkBitmapFromJavaBitmap ...more frames from Chrome... Previously unwinding would've stopped at #1. Code added by JNI generator links frames #1->#2 and #3->#4. BUG=624362 Committed: https://crrev.com/a8c951effbf899ae4951c67d606a634905f88ab4 Cr-Commit-Position: refs/heads/master@{#427534}

Patch Set 1 #

Patch Set 2 : LinkStackFrames -> ScopedStackFrameLinker #

Patch Set 3 : Rebase #

Patch Set 4 : Simplify - remove FakeStackFrame, etc. #

Total comments: 18

Patch Set 5 : Rebase #

Patch Set 6 : Address comments; fix tests #

Patch Set 7 : Remove useless include #

Total comments: 1

Patch Set 8 : Rebase #

Patch Set 9 : git cl format #

Unified diffs Side-by-side diffs Delta from patch set Stats (+180 lines, -68 lines) Patch
M base/android/jni_android.h View 1 2 3 4 5 6 7 8 2 chunks +51 lines, -0 lines 0 comments Download
M base/android/jni_android.cc View 1 2 3 3 chunks +23 lines, -0 lines 0 comments Download
M base/android/jni_generator/golden_sample_for_tests_jni.h View 1 2 3 4 5 15 chunks +0 lines, -15 lines 0 comments Download
M base/android/jni_generator/jni_generator.py View 1 2 3 4 5 6 10 chunks +21 lines, -3 lines 0 comments Download
M base/android/jni_generator/jni_generator_tests.py View 1 2 3 4 5 1 chunk +1 line, -0 lines 0 comments Download
M base/android/jni_generator/testCalledByNatives.golden View 1 2 3 4 5 22 chunks +0 lines, -22 lines 0 comments Download
M base/android/jni_generator/testConstantsFromJavaP.golden View 1 2 3 4 5 14 chunks +0 lines, -14 lines 0 comments Download
M base/android/jni_generator/testFromJavaP.golden View 1 2 3 4 5 3 chunks +0 lines, -3 lines 0 comments Download
M base/android/jni_generator/testFromJavaPGenerics.golden View 1 2 3 4 5 1 chunk +0 lines, -1 line 0 comments Download
M base/android/jni_generator/testMultipleJNIAdditionalImport.golden View 1 2 3 4 5 2 chunks +0 lines, -2 lines 0 comments Download
M base/android/jni_generator/testNativeExportsOnlyOption.golden View 1 2 3 4 5 6 chunks +0 lines, -6 lines 0 comments Download
M base/android/jni_generator/testSingleJNIAdditionalImport.golden View 1 2 3 4 5 2 chunks +0 lines, -2 lines 0 comments Download
M base/debug/stack_trace.h View 1 2 3 4 5 2 chunks +52 lines, -0 lines 0 comments Download
M base/debug/stack_trace.cc View 1 2 3 4 5 6 7 8 3 chunks +23 lines, -0 lines 0 comments Download
M build/config/android/rules.gni View 1 2 3 4 3 chunks +9 lines, -0 lines 0 comments Download

Messages

Total messages: 24 (12 generated)
Dmitry Skiba
4 years, 3 months ago (2016-09-23 06:04:53 UTC) #3
Dmitry Skiba
Sad, but LinkStackFrames overwriting stack is too clever, because per ARM ABI r11 (fp) should ...
4 years, 2 months ago (2016-09-26 19:14:06 UTC) #4
Primiano Tucci (use gerrit)
yeah that's precisely what I meant in our offline chat when I asked how weren't ...
4 years, 2 months ago (2016-09-26 19:33:08 UTC) #5
Dmitry Skiba
Fixed the issue with corrupting fp register by restoring its value before returning. I.e. instead ...
4 years, 2 months ago (2016-10-03 21:34:37 UTC) #6
Dmitry Skiba
Ping. BTW, one advantage of doing it this way is that other tools that unwind ...
4 years, 2 months ago (2016-10-06 15:49:16 UTC) #7
Dmitry Skiba
Primiano raised concern that this change has too many layers and is hard to understand. ...
4 years, 2 months ago (2016-10-12 05:22:33 UTC) #8
Primiano Tucci (use gerrit)
Ok, this is extremely clever yet extremely frightening. The thing that makes me feel good ...
4 years, 2 months ago (2016-10-13 20:03:22 UTC) #10
Dmitry Skiba
> P.S. I assume you only tested on arm (which is fine). Should we just ...
4 years, 2 months ago (2016-10-17 22:09:12 UTC) #11
Nico
lgtm, thanks for the good CL description. https://codereview.chromium.org/2361353002/diff/120001/base/debug/stack_trace.cc File base/debug/stack_trace.cc (right): https://codereview.chromium.org/2361353002/diff/120001/base/debug/stack_trace.cc#newcode262 base/debug/stack_trace.cc:262: , original_parent_fp_(LinkStackFrames(fp, ...
4 years, 1 month ago (2016-10-25 19:36:33 UTC) #17
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2361353002/160001
4 years, 1 month ago (2016-10-25 21:30:10 UTC) #20
commit-bot: I haz the power
Committed patchset #9 (id:160001)
4 years, 1 month ago (2016-10-25 23:39:40 UTC) #22
commit-bot: I haz the power
4 years, 1 month ago (2016-10-25 23:41:17 UTC) #24
Message was sent while issue was closed.
Patchset 9 (id:??) landed as
https://crrev.com/a8c951effbf899ae4951c67d606a634905f88ab4
Cr-Commit-Position: refs/heads/master@{#427534}

Powered by Google App Engine
This is Rietveld 408576698