History log of /art/runtime/debugger.cc
Revision Date Author Comments
d698ef52ab913384473c39687c32d68592422132 02-Apr-2018 Alex Light <allight@google.com> Revert^6 "Ensure that OSR still is possible with jvmti"

The instrumentation uninstall could set methods to non-debuggable
boot.oat code. This could cause events to be missed due to methods
being inlined. We needed to change the path so that we would only have
the JIT/interpreter replace methods. We do this by adding a new
callback that can be used to determine if a method needs to be
debuggable and being more careful about replacing code when this is
true.

This reverts commit 5f3005c8844d851d7d218b88b5f90d6c9083ce24.
This unreverts commit b9ad26d1ed9146b89555d4333021f44eeb831f05.

Reason for revert: Fixed issue causing CTS version of test 993 failure.

Test: cts-tradefed run cts-dev CtsJvmtiRunTest993HostTestCases
Test: ./test.py --host -j50 --all -t 993
Test: ./test.py --host
Test: while ./test/run-test --host --jit 1935; do; done
Test: while ./test/run-test --host --jit --jvmti-redefine-stress 1935; do; done
Test: am start --attach-agent -n com.example.android.displayingbitmaps/.ui.ImageGridActivity
Run blur filter.
Bug: 76226464
Bug: 77306669

Merged-In: I5068201a03f7613787c66981405499b6499c24e1
Change-Id: I5068201a03f7613787c66981405499b6499c24e1
(cherry picked from commit f28586390b055a5681e50617d729a3fa09792d9c)
67bf42e89592c3a1c648f927f2ce3ccb189a1161 27-Feb-2018 David Sehr <sehr@google.com> Header library to remove dependence on runtime/

Add a new header library to remove libdexfile and others' dependence on
runtime (typically runtime/base) includes in libdexfile. Also a small step
to tease dexlayout and profman away from relying on these as well.

Bug: 22322814
Test: make -j 50 checkbuild
make -j 50 test-art-host-gtest

Change-Id: I38e2fe399a75f4bc6318c77a71954c00ea73ec2b
af290318c31180148bab64038d66a6059a1a89d5 27-Feb-2018 Roland Levillain <rpl@google.com> Small documentation and stylistic changes.

Test: art/test.py
Change-Id: Ibc74ee4783314266bf1d027811715058626c57c8
b2ec9f5c128673c43f776cbe12c8eeb0a6884ebb 21-Feb-2018 David Sehr <sehr@google.com> Remove duplication, split tests

The code move to libdexfile/dex/descriptors_names.cc apparently did not
remove the original code from runtime/utils.cc. Fix that duplication
and all the header mentions needed. Also, split the test files to go
along with the new locations for the code to be tested.

Bug: 22322814
Test: make -j 50 checkbuild
make -j 50 test-art-host-gtest
flash & boot marlin

Change-Id: Ie734672c4bca2c647d8016291f910b5608674545
0225f8e2939a9340cb7dcebfcfe7996a2bd9bce9 31-Jan-2018 David Sehr <sehr@google.com> Revert "Revert "Make libdexfile build independent of runtime dir""

This reverts commit 787784f9effb126b5d0d3dc97d544c4a477b5daf.

Reason for revert: Bot configuration issue.

Change-Id: I6a10bb4a9571f89c7e4dd095f9157e830a44e2de
Bug: 22322814
Test: make -j 50 checkbuild
787784f9effb126b5d0d3dc97d544c4a477b5daf 30-Jan-2018 David Sehr <sehr@google.com> Revert "Make libdexfile build independent of runtime dir"

This reverts commit b40b7e73469339a6b667b4a2e2b8690112a74dc9.

Reason for revert: on device libdexfile.so missing

Change-Id: I9bd61a98bef870400580e8c991cb061d3f57fa72
b40b7e73469339a6b667b4a2e2b8690112a74dc9 26-Jan-2018 David Sehr <sehr@google.com> Make libdexfile build independent of runtime dir

Remove libdexfile's dependency on utils.cc and move utf.cc into
/dex. Remove libdexfile's constituent sources from libart and
use libdexfile wherever libart is. Also remove some ART-specific
interfaces. Libdexfile's tests remain to be converted, plus
moving the files to a new directory peer to runtime/.

Bug: 22322814
Test: make -j 50 test-art-host
Change-Id: Ifaf695216e4a0e43d3aa377984d933f7a2a243c2
9e734c7ab4599d7747a05db0dc73c7b668cb6683 05-Jan-2018 David Sehr <sehr@google.com> Create dex subdirectory

Move all the DexFile related source to a common subdirectory dex/ of
runtime.

Bug: 71361973
Test: make -j 50 test-art-host
Change-Id: I59e984ed660b93e0776556308be3d653722f5223
94c589db78da2b66bc681c6480819ca4bd4d3326 27-Dec-2017 Andreas Gampe <agampe@google.com> ART: Mark Dbg GCs as debugger

Change Heap::CollectGarbage to accept explicit GcCause, but implicitly
default to kGcCauseExplicit.

Change Dbg functions that run an explicit GC to set the cause to
kGcCauseDebugger.

Test: m test-art-host
Change-Id: I53d4073fca01c1de78d14a58dff33004c7971981
808c7a57bb913b13c22884f57cdacd59bf1fdb3f 15-Dec-2017 Mathieu Chartier <mathieuc@google.com> Make CodeItem fields private

Make code item fields private and use accessors. Added a hand full of
friend classes to reduce the size of the change.

Changed default to be nullable and removed CreateNullable.
CreateNullable was a bad API since it defaulted to the unsafe, may
add a CreateNonNullable if it's important for performance.

Motivation:
Have a different layout for code items in cdex.

Bug: 63756964
Test: test-art-host-gtest
Test: test/testrunner/testrunner.py --host
Test: art/tools/run-jdwp-tests.sh '--mode=host' '--variant=X32' --debug

Change-Id: I42bc7435e20358682075cb6de52713b595f95bf9
403207107da7f11525c4d305184c56b35ec1c17a 14-Dec-2017 Alex Light <allight@google.com> Add support for selecting alternate JDWP implementations

Change JDWP options parsing to take place later and add a
-XjdwpProvider:_ option that can be used by the runtime to select an
appropriate JDWP provider. The argument is a string.

If 'none' is given JDWP will be totally disabled.

If 'internal' is given the current internal JDWP implementation is
used.

If 'default' is given the 'internal' JDWP implementation will
currently be used.

Other values will be added in the future.

Also adds a runtime callback that will be invoked when the runtime
wants to start or stop the debugger (namely at the post-zygote fork
and just before exit) and check if a debugger is availible.

Also add '-XjdwpOptions:_' in preparation for the eventual removal of
the existing -Xrunjdwp=_ and -Xagentlib:jdwp=_ as top-level options.
All of these options now store their arguments as a std::string to be
interpreted by the JDWP implementation as it sees fit. Also change the
jdwpOptions to default to transport=dt_android_adb if there is not one
specified and it is available. This will make changing the default
transport based on the JDWP provider easier.

These new options are needed to allow us to support both the old,
internal, JDWP implementation as its replacement is tested and
verified. This lets us switch between them with little difficulty.

We will probably remove one or both of these options once we have
confidence that the new jdwp implementation has stuck.

Test: ./test.py --host -j50
Test: ./test/run-test --host --debug 001-HelloWorld
Test: Manual, flash walleye, debug app

Bug: 62821960

Change-Id: Ie31db6b6f7d76a03d4ab8e178fcf298ed0eec203
e5463a88039a14c1d1d501d2932d069e6d4224e2 12-Dec-2017 Alex Light <allight@google.com> Ensure that DDM processing doesn't leave unhandled exceptions

Previously if a DDM chunk handler returns an invalid chunk the thread
that processed the chunk could end up with an unhandled exception.
This could be troublesome if it happened on a debugger thread, which
might never actually handle it.

Test: ./test.py --host -j50
Bug: 70570850
Change-Id: Ic67db951d721cf7532b08c0cc3f35bed9396d52d
6f2a6341b6dd8910aebacefea653f11006b46abe 12-Dec-2017 Alex Light <allight@google.com> Clean up JVMTI DDMS extension function.

We change it to not return failure (and print a warning) if the chunk
handler returns an empty chunk. This is a surprisingly common result
in real-world code and was causing significant log-spam.

Bug: 70559172
Test: ./test.py --host -j50
Change-Id: I1ba0f43cb2e834b09f51db75ec9100d97e916b62
31f4c9f86522061d682fd0e2c6003043cec496dc 09-Dec-2017 Mathieu Chartier <mathieuc@google.com> Add CodeItemDebugInfoAccessor

Use it in places where DecodeDebugPositionInfo is called.

Motivation: Abstract away calls to GetDebugInfoOffset.

Bug: 63756964
Test: test-art-host
Test: art/tools/run-jdwp-tests.sh '--mode=host' --debug

Change-Id: I3ab2eff56c472cc717f49d17fd17eb0b8fde4062
660be6ff67870d2512230b13effefdbc5abe43e4 22-Nov-2017 Richard Uhler <ruhler@google.com> Add VMDebug.getInstancesOfClasses API.

The API can be used to iterate over instances of a given type on the
heap.

The GetInstancesOfClassesBenchmark run on bullhead shows the run time
of the API grows linearly in the number of classes, C, to get instances
of and the number of total instances, N, allocated on the heap.

C N=~2^18 N=~2^19
1 13ms 21ms
2 26ms 43ms
4 53ms 87ms

Bug: 69729799
Test: ./test/testrunner/testrunner.py -t 099-vmdebug -b --host

Change-Id: Ied053d19760e656012e2577776f75a1cc0a14ac3
58cc1cb66c1a96ffba4a314edb2c5b4e8b235d5b 20-Nov-2017 Nicolas Geoffray <ngeoffray@google.com> Pass the debug_info_offset explicitly.

In order to use debug_info_offset for encoding implementation details,
rewrite all indirect users of it to fetch it before calling DexFile
methods.

This allows keeping the DexFile interface clean of runtime
considerations.

Test: test.py
Change-Id: I4591e0039b5f822f4409aae411071ecbe97082b1
772099a8976cb8341475c42bfc595373778217dd 21-Nov-2017 Alex Light <allight@google.com> Add remaining DDMS messages into DdmPublishChunk

This ensures that one can get notified of every DDMS chunk that would
be published.

Add a test to ensure that appropriate ddms events are sent.

We also refactor the underlying code so that the only way these events
are sent is through the DdmPublishChunk callback.

Test: ./test.py --host -j50
Bug: 62821960
Change-Id: I0c4a60b75615c206a27aff17df853b53cf5e8c96
8c2b929696cac235e8fd8bf4cae0ca751603b570 09-Nov-2017 Alex Light <allight@google.com> Add JVMTI DDMS extension method and event.

Add a new jvmti extension method
'com.android.art.internal.ddm.process_chunk' that can be used to
request that the system process a DDMS chunk with a given type and
data payload. It returns the processed chunk type and data. Agents can
use this to interact with DDMS.

Also add a new jvmti extension event
'com.android.art.internal.ddm.publish_chunk' that will be called
whenever the system wishes to send an unrequested chunk of data to be
processed. This is triggered by code executing 'DdmServer#sendChunk'
or by other internal mechanisms.

Both of these extensions are provided mainly to aid in the maintenence
of backwards compatibility with existing DDMS applications. Generally
agents should prefer to use the normal JVMTI events and controls over
interpreting DDMS data or calling DDMS functions.

Bug: 62821960
Test: ./test.py --host -j50
Test: ./art/tools/run-jdwp-tests.sh --mode=host \
--test org.apache.harmony.jpda.tests.jdwp.DDM.DDMTest
Change-Id: I39f22d3d096d12b59713ec7b8b0c08d0d68ff422
4098a7ad22535212c193f5c66eaf8a7387e1b7fc 06-Nov-2017 Vladimir Marko <vmarko@google.com> Refactor ArtField::GetType<>() as {Lookup,Resolve}Type().

And add no thread suspension assertion to LookupType()
as well as ArtMethod::LookupResolvedClassFromTypeIndex().

Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Change-Id: If1541ccb0aafeabb6d1dd5566f10afcac98a2ef1
0fa1786bdcc333873ed65a1f77a4669d5701ac5e 24-Oct-2017 Alex Light <allight@google.com> Avoid JVMTI global deoptimization when possible

This changes the openjdkjvmti plugin to be more controlled about the
situations that it will deoptimize everything. Most notably this makes
the plugin deoptimize only individual methods for breakpoints instead
of doing a full deoptimization. It also doesn't deoptimize for the
JVMTI_EVENT_EXCEPTION method, since our throwing code will always send
the appropriate event.

Impact:
Exoplayer benchmark with breakpointlogger setting a breakpoint on
a method that is never called.

The agent is the tools/breakpoint-logger agent.

'art' options are for all runs were:
--64
-Xusejit:true
-Xcompiler-option --debuggable
'art' options for 'Pre change' and 'Post change' runs included:
-Xplugin:libopenjdkjvmti.so
'-agentpath:libbreakpointlogger.so=Lbenchmarks/common/java/BenchmarkBase;->run()V@0'

Clean run (no agent loaded):
Running FMP4 x 1 : 53
Running TS x 1 : 144
Running FMP4 x 2500 : 3309
Running TS x 100 : 3584
ExoPlayerBench(RunTime): 6977000.0 us.
Pre change:
Running FMP4 x 1 : 159
Running TS x 1 : 9395
Running FMP4 x 2500 : 298591
Running TS x 100 : 944447
ExoPlayerBench(RunTime): 1.243226E9 us.
Post change:
Running FMP4 x 1 : 87
Running TS x 1 : 495
Running FMP4 x 2500 : 2939
Running TS x 100 : 3947
ExoPlayerBench(RunTime): 6979000.0 us.

Post change vs clean run is well within margin of error for this
benchmark.

Test: ./test.py --host -j50
Test: ./art/tools/run-prebuild-libjdwp-tests.sh

Bug: 62821960
Bug: 67958496

Change-Id: I63ef04f71c36c34d8534651d0c075921a836ec08
373a9b5c718a45ac484afcf4fe6ce84f4bb562b3 18-Oct-2017 Andreas Gampe <agampe@google.com> ART: Depend on libnativehelper headers only

Depend on header-only versions where possible. Move projects
excluding libart to libnativehelper_header_only.

Bug: 65522645
Test: mmma art
Change-Id: I53dd3b2a97e94ee685f72de007ed3858f7f5c6b6
2161193652e925a2b450514f4e445ccd2fb660b3 26-Sep-2017 Alex Light <allight@google.com> Ensure that OSR doesn't break local-variable get/set

We had a bug where we would on-stack replace a method with a modified
local variable. Thanks to inlining & load-store elimination of local
variable values this could cause the change to the variable to be lost.
We fixed this by giving plugins a way to notify the runtime they are
interested in a particular method.

Bug: 66959663
Bug: 66933582

Test: while ./test/run-test --host --prebuild -O --jit 1935; do; done
Test: ./test.py --host -j50
Change-Id: Ic001b8a9d8d0bd9ce292e807752c86a505f85d36
e2abbc604ce003c776c00ecf1293796bb4c4ac5a 15-Sep-2017 Andreas Gampe <agampe@google.com> ART: Move kDexNoIndex to dex_file_types.h

Define the constant with the types to allow lowering the dependency
on DexFile.

Test: m
Change-Id: I3c61421db45be96d2057e01b1a7825883d8bd178
77fee87b262e969b29a9ac121a8bcbf87b68d9ce 05-Sep-2017 Alex Light <allight@google.com> Add support for JVMTI monitor events.

Adds support for the JVMTI can_generate_monitor_events capability and
all associated events. This adds support for the
JVMTI_EVENT_MONITOR_WAIT, JVMTI_EVENT_MONITOR_WAITED,
JVMTI_EVENT_MONITOR_CONTENDED_ENTER, and
JVMTI_EVENT_MONITOR_CONTENDED_ENTERED events.

Bug: 65558434
Bug: 62821960
Bug: 34415266

Test: ./test.py --host -j50

Change-Id: I0fe8038e6c4249e77d37a67e5056b5d2a94b6f48
05f47743e604e9b3b1de9ec930c6af6d9780c440 14-Sep-2017 Alex Light <allight@google.com> Revert "Revert "Make WatchedFramePop instrumentation event pure-virtual""

Forgot to revert this.

This reverts commit b2c8fc62f4e7889300da2d26294537194e37b926.

Reason for revert: Fixed issue with tests

Change-Id: I1fd5a2759c67a906d55137e2b6548726af2c8e4f
Test: treehugger
9fb1ab1f6bb58bdaccef78bc81b3202d0121e2ed 05-Sep-2017 Alex Light <allight@google.com> Revert "Revert "JVMTI Exception and ExceptionCatch events""

Fixed error where we were incorrectly not updating a ShadowFrame
dex_pc causing deoptimization errors.

Bug: 62821960
Bug: 65049545

Test: ./test.py --host -j50
Test: ./art/tools/run-libcore-tests.sh \
--mode=host --variant-X32 --debug

This reverts commit 959742483885779f106e000df6dd422fc8657931.

Change-Id: I91ab2bc3e645ddf0359c189b19a59a3ecf0d8921
959742483885779f106e000df6dd422fc8657931 04-Sep-2017 Nicolas Geoffray <ngeoffray@google.com> Revert "JVMTI Exception and ExceptionCatch events"

Breaks tests.

Bug: 62821960
Bug: 65049545

This reverts commit 798eab03120f6189e8f6aa804d67af1b1d9f00b0.

Change-Id: Ie96903df06bbbe41f288f5b75a5114b142998fac
b2c8fc62f4e7889300da2d26294537194e37b926 04-Sep-2017 Nicolas Geoffray <ngeoffray@google.com> Revert "Make WatchedFramePop instrumentation event pure-virtual"

Builds on top of a change that breaks tests.

This reverts commit a0e0f103956fab23d1bfb08a69dadb0bc81d1a35.

Change-Id: I6a35fc2f4a099e807b5ed81b93a3f9a8d8beeea2
a0e0f103956fab23d1bfb08a69dadb0bc81d1a35 01-Sep-2017 Alex Light <allight@google.com> Make WatchedFramePop instrumentation event pure-virtual

All the other events are pure virtual but this one had an (empty)
default implementation. Change the event to make it consistent with
all the others.

Test: Builds
Test: Treehugger
Change-Id: I3d81914d067b305f09d4072c443e5ac9027af443
798eab03120f6189e8f6aa804d67af1b1d9f00b0 23-Aug-2017 Alex Light <allight@google.com> JVMTI Exception and ExceptionCatch events

Add support for the JVMTI can_generate_exception_events capability.
This includes the Exception and ExceptionCatch events and all their
associated behaviors.

Test: ./test.py --host -j50
Bug: 62821960
Bug: 65049545

Change-Id: I21cc8522c01033cdeb47bf34fa433bf04bf7ca5c
6e1607e247d979a1671a1fd5a98de3f1031fe719 23-Aug-2017 Alex Light <allight@google.com> Rename instrumentation ExceptionCaught to ExceptionThrown

The instrumentation ExceptionCaught event was badly named since it is
actually sent at the time the exception is thrown and is sent even if
the exception is never actually caught. Rename it and associated
methods/fields to ExceptionThrown to more accurately reflect the
event's semantics.

Test: ./test.py --host -j50
Change-Id: I1e9c401ab619259b25928dbf19f62d3fa9573d47
b45528c1f1b83ca8c970f439b54fbfcfda6908ea 27-Jul-2017 Vladimir Marko <vmarko@google.com> ART: Refactor retrieval of types through ArtMethod.

Split Get*() functions that take a "bool resolve"
argument into Lookup*() and Resolve*() functions.

Test: m test-art-host-gtest
Test: testrunner.py --host
Change-Id: I0b7eaa1fadc2ffa8c0168203790467f91a126963
e431e2758d62cf56f7f347f5a8c9d79e41b6dcd7 19-Jul-2017 Steven Moreland <smoreland@google.com> art: use proper nativehelper headers

libnativeheader exports headers under nativeheader. These were
available before incorrectly as global headers in order to give
access to jni.h.

Test: modules using art find headers
Bug: 63762847
Change-Id: I5c820d677e94e07b2859e78610bc997fe51b41dc
0c18338ebae6b3597c882887f8354b64abb5e90f 14-Jul-2017 Andreas Gampe <agampe@google.com> ART: Replace or remove some ObjectCallback Walk functions

Replace with visitor functions in RegionSpace and SpaceBitmap. Remove
old ObjectCallback version in HeapBitmap. Fix up users. Move some
thread-safety annotations.

Move ObjectCallback definition to the only remaining user (ModUnionTable).

Test: m
Change-Id: I10307aeacad0c60d21fbade2081ec040d6a6ac4c
88fd720b6799184c8ad61e766a6d37af33ed30ef 30-Jun-2017 Alex Light <allight@google.com> Add Jvmti Suspend/ResumeThread functions

Enable the can_suspend jvmti capability and implement all required
functionality associated with it.

Test: ./test.py --host -j40
Bug: 34415266
Bug: 62821960
Bug: 63579748

Change-Id: I83b92de7f81622e1658114b034918e8295805b6e
098ae7f0ce90765068e3607f12671925ca4f2be2 08-Jul-2017 Andreas Gampe <agampe@google.com> ART: Change StringTable to unordered_set

Cache the string hash in the table element. Trade space for time.

Effect on b/37620770 repro case: Dump time = 3.7s -> 1.6s

(cherry picked from commit 84eadb2daafa75c54a4daca151ca90f8b606c596)

Bug: 37620770
Test: m test-art-host
Merged-In: Ifaed1c65e30097851188450a5db2bc8ee30efbb4
Change-Id: Ifaed1c65e30097851188450a5db2bc8ee30efbb4
5b92a70d9cc263cef961bc6c81fe159352f0f4cb 07-Jul-2017 Andreas Gampe <agampe@google.com> ART: Change StringTable for RecentAllocations

Avoid the expensive std::distance call by caching the index inside
the set element. This requires a mutable field and a Finish call.

Effect on b/37620770 repro case: Dump time = ~ 12s -> 3.7s

(cherry picked from commit 2eeb01a9327b091124521a84c76edb2c6dcfa8f0)

Bug: 37620770
Test: m test-art-host
Merged-In: I6ab89e0e99994466183042bd59358439f98dde42
Change-Id: I6ab89e0e99994466183042bd59358439f98dde42
d412d7b98649ce9bd84b4ef733030316c976f5c1 07-Jul-2017 Andreas Gampe <agampe@google.com> ART: Presize output vector in RecentAllocations

Reserve the needed storage for each allocation record before dumping the
data to avoid incremental increases.

Effect on b/37620770 repro case: Dump time ~ 12s

(cherry picked from commit d0fc768defcc417393d4ef5a25214b566bfc36c2)

Bug: 37620770
Test: m test-art-host
Merged-In: I24f46786c9cf15e6523389c630952eff0981f4dc
Change-Id: I24f46786c9cf15e6523389c630952eff0981f4dc
d236626aad8a11a0ced55b3e0c2a7411bcd9b810 07-Jul-2017 Andreas Gampe <agampe@google.com> ART: Add VLOGs to GetRecentAllocations

Add some logging of the different stages.

(cherry picked from commit ff29cee3258b7c0984b447a8b5cff2ef9d332699)

Test: m test-art-host
Merged-In: Idcddb109695c4ed7ff83d2b96e27984c5077159b
Change-Id: Idcddb109695c4ed7ff83d2b96e27984c5077159b
f9f9593b011eb40e697bd75c730c993f2531a75f 07-Jul-2017 Andreas Gampe <agampe@google.com> ART: Improve Dbg::GetRecentAllocations

Move ClassTable to const char* instead of std::string, and let it
know when it needs to keep a copy of the string itself. This avoids
lots of temporary allocations.

Increase the stack depth in test 098 to better cover this behavior.
Add allocations of proxies and arrays to cover the backing storage.

Improvements on test 098:

Before:

heaptrack stats:
allocations: 598174
leaked allocations: 186
temporary allocations: 132302

65797 calls to allocation functions with 3.34KB peak consumption from
art::StringTable::Add(char const*)
65666 calls to allocation functions with 144B peak consumption from
art::StringTable::IndexOf(char const*) const

After:

heaptrack stats:
allocations: 466828
leaked allocations: 186
temporary allocations: 1002

(cherry picked from commit f774a4e5243b9b06f3c71ea9b67fc40b96a78342)

Bug: 37620770
Test: m test-art-host
Test: art/test/testrunner/testrunner.py -b --host -t 098
Test: SANITIZE_HOST=address art/test/testrunner/testrunner.py -b --host -t 098
Merged-In: Iee496c96471dbb825c22b2656598c95f7c029a2f
Change-Id: Iee496c96471dbb825c22b2656598c95f7c029a2f
84eadb2daafa75c54a4daca151ca90f8b606c596 08-Jul-2017 Andreas Gampe <agampe@google.com> ART: Change StringTable to unordered_set

Cache the string hash in the table element. Trade space for time.

Effect on b/37620770 repro case: Dump time = 3.7s -> 1.6s

Bug: 37620770
Test: m test-art-host
Change-Id: Ifaed1c65e30097851188450a5db2bc8ee30efbb4
2eeb01a9327b091124521a84c76edb2c6dcfa8f0 07-Jul-2017 Andreas Gampe <agampe@google.com> ART: Change StringTable for RecentAllocations

Avoid the expensive std::distance call by caching the index inside
the set element. This requires a mutable field and a Finish call.

Effect on b/37620770 repro case: Dump time = ~ 12s -> 3.7s

Bug: 37620770
Test: m test-art-host
Change-Id: I6ab89e0e99994466183042bd59358439f98dde42
d0fc768defcc417393d4ef5a25214b566bfc36c2 07-Jul-2017 Andreas Gampe <agampe@google.com> ART: Presize output vector in RecentAllocations

Reserve the needed storage for each allocation record before dumping the
data to avoid incremental increases.

Effect on b/37620770 repro case: Dump time ~ 12s

Bug: 37620770
Test: m test-art-host
Change-Id: I24f46786c9cf15e6523389c630952eff0981f4dc
ff29cee3258b7c0984b447a8b5cff2ef9d332699 07-Jul-2017 Andreas Gampe <agampe@google.com> ART: Add VLOGs to GetRecentAllocations

Add some logging of the different stages.

Test: m test-art-host
Change-Id: Idcddb109695c4ed7ff83d2b96e27984c5077159b
f774a4e5243b9b06f3c71ea9b67fc40b96a78342 07-Jul-2017 Andreas Gampe <agampe@google.com> ART: Improve Dbg::GetRecentAllocations

Move ClassTable to const char* instead of std::string, and let it
know when it needs to keep a copy of the string itself. This avoids
lots of temporary allocations.

Increase the stack depth in test 098 to better cover this behavior.
Add allocations of proxies and arrays to cover the backing storage.

Improvements on test 098:

Before:

heaptrack stats:
allocations: 598174
leaked allocations: 186
temporary allocations: 132302

65797 calls to allocation functions with 3.34KB peak consumption from
art::StringTable::Add(char const*)
65666 calls to allocation functions with 144B peak consumption from
art::StringTable::IndexOf(char const*) const

After:

heaptrack stats:
allocations: 466828
leaked allocations: 186
temporary allocations: 1002

Bug: 37620770
Test: m test-art-host
Test: art/test/testrunner/testrunner.py -b --host -t 098
Test: SANITIZE_HOST=address art/test/testrunner/testrunner.py -b --host -t 098
Change-Id: Iee496c96471dbb825c22b2656598c95f7c029a2f
46f9340f2a055a8fdfebbfbb739c697c20d83e7c 29-Jun-2017 Alex Light <allight@google.com> Add SuspendReason enum and change Suspension functions.

More self-documenting and more type safe.

Bug: 62821960
Test: ./test.py
Change-Id: Ic7a1ae6a25e687d65f5aa10c1aad54a7b80dd086
97e78033e6cf81d72c9d4d016e349282b911303c 28-Jun-2017 Alex Light <allight@google.com> Move debugger.cc GetCanonicalMethod to ArtMethod

This functionality will be useful to other parts of the runtime so put
it in a more central place.

Test: ./test.py --host -j40
Change-Id: I4d19cc1016884f5921245ac284c7323cbf3ea8cd
e00ec30588a36eed90aa24eaca9dbc7520f17bf7 16-Jun-2017 Alex Light <allight@google.com> Make native field operations call instrumentation listeners.

Previously native reads and writes of fields would not be reported to
instrumentation listeners.

We filter these events out from the debugger since currently the
debugger will deadlock if it tries to propagate them through JDWP.

Bug: 62712031

Test: ./test.py --host --trace -j40
Test: ./art/tools/run-jdwp-tests.sh --mode=host
Test: Manual
Change-Id: Ibc75248bdca06537d8b4ff7bb890546136ffa161
d76615851af31791c7b1549e8c4609152237b9ce 01-May-2017 Alex Light <allight@google.com> Handler-ize InstrumentationListener and related code

We are going to be making instrumentation listeners that can cause
suspensions during their running. We explicitly handler-ize all the
instrumentation listener functions in order to ensure this is safe.

Bug: 34414073
Test: ./test.py --host --ntrace --trace -j40
Change-Id: Ic719080d0991b104d41b7757df8d1f332c72cd04
513061a792b22c417c938d31c19581390709561c 01-Jun-2017 Andreas Gampe <agampe@google.com> ART: Clean up thread.h and thread_list.h

Remove dependency on stack.h and gc_root.h. Remove unused object
callbacks include. Factor out ManagedStack into its own set of files.
Fix up users of transitive includes.

Test: m test-art-host
Change-Id: I01286c43d8c7710948c161b1348faabb05922e59
24d3e46ea954cf3a35a2b57be2bf61864ee4f967 24-Apr-2017 Orion Hodson <oth@google.com> ART: Support for SourceDebugExtension

Adds support for reading SourceDebugExtension class annotation from DEX files.

Bug: 30109642
Test: art/tools/run-jdwp-tests.sh --mode=device --test org.apache.harmony.jpda.tests.jdwp.ReferenceType.SourceDebugExtensionTest

(cherry picked from commit 77d8a1c3572afb38542cb5a2b3516674a182ce48)

Change-Id: I94952a769a6cd0dd85a58cfb1bb65ec0d1bf4e60
77d8a1c3572afb38542cb5a2b3516674a182ce48 24-Apr-2017 Orion Hodson <oth@google.com> Revert^2 "ART: Support for SourceDebugExtension"

This reverts commit 6530cab77a36d6d284c9d61084e39cd2c7fb91f8.

Bug: 30109642
Bug: 37560145
Test: art/tools/run-jdwp-tests.sh --mode=device --test org.apache.harmony.jpda.tests.jdwp.ReferenceType.SourceDebugExtensionTest
Change-Id: I74cacb351fb7b181c5a17e004914d6d8bdcaaa48
6530cab77a36d6d284c9d61084e39cd2c7fb91f8 24-Apr-2017 Orion Hodson <oth@google.com> Revert "ART: Support for SourceDebugExtension"

This reverts commit 70a45017d6371521c251d67a9aac7d1c86fb6a06.

Pending fix for run-jdwp-tests.sh --mode=device.

Bug: 30109642
Test: art/tools/run-jdwp-tests.sh

Change-Id: I62f84e0fb09b6fe280ca6b518fbd2bc431318a56
cdd798de1b2e7807f1cab8ebbfbb165069beae6b 18-Apr-2017 Sebastien Hertz <shertz@google.com> Follow-up to 70d60275cc2860bde50e5f9c5b151e94f745ae14

Test: make -j build-art-host
Change-Id: Id6e81518041bd64dec537ff3da2fa049d39b27d0
70a45017d6371521c251d67a9aac7d1c86fb6a06 30-Mar-2017 Orion Hodson <oth@google.com> ART: Support for SourceDebugExtension

Adds support for reading SourceDebugExtension class annotation from
DEX files.

Bug: 30109642
Test: art/tools/run-jdwp-tests.sh --mode=host --test org.apache.harmony.jpda.tests.jdwp.ReferenceType.SourceDebugExtensionTest
Change-Id: I2187a2776953a21d36f8b2d165bef6733c02811e
70d60275cc2860bde50e5f9c5b151e94f745ae14 14-Apr-2017 Sebastien Hertz <shertz@google.com> JDWP: fix Dbg::ResumeThread

A thread should be resumed if and only if it has been suspended by
the debugger. Therefore, we must check the debug suspend count, not
the suspend count (which includes debug suspend count). Otherwise we
could end up resuming a thread that has been suspended for another
reason (like a GC) but not by the debugger itself.

Bug: 27385848
Test: art/tools/run-jdwp-tests.sh --mode=host --variant=X64
Change-Id: I70ed6dfc233501e92332634650babf21ba911048
e3f991ff5751960a6b190720fac58a744cf4902d 06-Apr-2017 Alex Light <allight@google.com> Fixup JDWP for obsolete methods

We needed to implement some additional methods and behaviors in JDWP
in order to support JVMTI obsolete methods.

Test: Manual (using art/test/915-obsolete-2 & jdb debugger)
Test: Manual (using art/test/915-obsolete-2 & Android Studio/IntelliJ debugger)

Bug: 31455788

Change-Id: I20c2fa27a2dd002e37526b126f23ce552f19e623
(cherry picked from commit 7337631929812fb8a60b5182eba076a32d1cb851)
7337631929812fb8a60b5182eba076a32d1cb851 06-Apr-2017 Alex Light <allight@google.com> Fixup JDWP for obsolete methods

We needed to implement some additional methods and behaviors in JDWP
in order to support JVMTI obsolete methods.

Test: Manual (using art/test/915-obsolete-2 & jdb debugger)
Test: Manual (using art/test/915-obsolete-2 & Android Studio/IntelliJ debugger)

Bug: 31455788

Change-Id: I20c2fa27a2dd002e37526b126f23ce552f19e623
cafa08146648442ee53348c4918a4fab29e591c1 15-Feb-2017 Nicolas Geoffray <ngeoffray@google.com> Use GetPeerFromOtherThread in debugger.

Test: run-jdwp-tests.sh --mode=host --variant=X64 --debug
Change-Id: I6b92153752becbad04563d96b824a06c002f8392
fa4333dcb481e564f54726b4e6f8153612df835e 14-Feb-2017 Andreas Gampe <agampe@google.com> ART: Add operator == and != with nullptr to Handle

Get it in line with ObjPtr and prettify our code.

Test: m
Change-Id: I1322e2a9bc7a85d7f2441034a19bf4d807b81a0e
433b79a9130df5f2375b9d3d7518c1f3fb84a467 30-Jan-2017 Nicolas Geoffray <ngeoffray@google.com> Revert "Revert "Make --debuggable rely on JIT code.""

Fixed by https://android-review.googlesource.com/#/c/330165/

This reverts commit 81356645157af44152c7b7db383596b5cf3479b5.

Change-Id: Ifb74e1cc90ab6dea621f7f54a00b540d6ccd0cf6
81356645157af44152c7b7db383596b5cf3479b5 30-Jan-2017 Vladimir Marko <vmarko@google.com> Revert "Make --debuggable rely on JIT code."

Breaks 137-cfi with ART_TEST_RUN_TEST_DEBUGGABLE=true

This reverts commit a0619e25aacf8b8074132f4951f75fdbcfd42925.

bug: 28769520
Change-Id: Ifd7b8fc7c9b72c0a523fd57c4b1b80edd3547caa
a0619e25aacf8b8074132f4951f75fdbcfd42925 20-Dec-2016 Nicolas Geoffray <ngeoffray@google.com> Make --debuggable rely on JIT code.

Removes -Xfully-deoptable in the process, which was added as a
temporary workaround until this CL.
Partial revert of https://android-review.googlesource.com/#/c/302232/

Makes things consistent with existing infrastructure:

- Parse the --debuggable from the compiler options, just like
--compiler-filter.

- Add DEBUG_JAVA_DEBUGGABLE, passed by the zygote, for debuggable apps.

- Java debuggable now solely relies on JIT for simplicity.

- Debugging under userdebug for non-java-debuggable apps is still
best effort.

Test: test-art-host, jdwp

bug: 28769520
Change-Id: Id0593aacd85b9780da97f20914a50943957c858f
0f01b583c3952d0219696480654a0db8fac4b661 19-Jan-2017 Andreas Gampe <agampe@google.com> ART: Add ClassLoadCallback

Add callback for class-load and class-prepare events. Move Dbg
over. Add tests.

Bug: 31684920
Test: m test-art-host-gtest-runtime_callbacks_test
Test: art/tools/run-jdwp-tests.sh --mode=host
Change-Id: I871f6b3c54448fd6ece8d9a7571b2042be50d525
04bbb5be5b9c0f0b3a72116353d23ea63c8bc5e9 19-Jan-2017 Andreas Gampe <agampe@google.com> Revert "Revert "ART: Start RuntimeCallbacks""

This reverts commit bf6331a45f730e1f1044af2ce43bceda660ae6fc.

Switch to using the mutator lock.

Bug: 31684920
Test: m test-art-host-gtest-runtime_callbacks_test
Test: art/tools/run-jdwp-tests.sh --mode=host --debug
Change-Id: I6ce0f71de2aa9f90cd23cfca7723a793b560b16b
bf6331a45f730e1f1044af2ce43bceda660ae6fc 19-Jan-2017 Nicolas Geoffray <ngeoffray@google.com> Revert "ART: Start RuntimeCallbacks"

jdwp tests failing with:
STDERR> dalvikvm32 E 01-18 23:14:50 12180 12198 thread-inl.h:137] holding "runtime callbacks lock" at point where thread suspension is expected

Bug: 31684920

This reverts commit 13093d455b8266338fd713b04261c58e9dc2b164.

Change-Id: I94e4154e273d006eecdd485607dcfd96392d6a00
13093d455b8266338fd713b04261c58e9dc2b164 18-Jan-2017 Andreas Gampe <agampe@google.com> ART: Start RuntimeCallbacks

Add a central RuntimeCallbacks structure to handle certain interesting
runtime events.

In a first iteration, add ThreadLifecycleCallback with ThreadStart and
ThreadStop. Move Dbg over to ThreadLifecycleCallback.

Add a test.

Bug: 31684920
Test: m test-art-host-gtest-runtime_callbacks_test
Test: art/tools/run-jdwp-tests.sh --mode=host
Change-Id: Ie0f77739a563207bfb4f04374e72dc6935c40b4f
942fd3130254d8276cbfe8e6201825e9c49e9b2c 16-Jan-2017 Vladimir Marko <vmarko@google.com> Reduce using ArtMethod's dex_cache_resolved_types_.

Avoid using the ArtMethod's dex cache type array shortcut
in runtime, preparing for its removal. We do not completely
remove the shortcut yet because it is still used by array
allocation entrypoints.

Fix ArgArray::BuildArgArrayFromObjectArray in reflection.cc
to not ask for the parameter type to be resolved. It should
have been previously resolved when retrieving the Method.

Also partially revert
https://android-review.googlesource.com/310717
because it relied on the removed AIOOBE check in the removed
ArtMethod::GetDexCacheResolvedType(). The removed check was
simply defensive but it could not be triggered without some
memory corruption.

Test: m test-art-host
Bug: 30627598
Change-Id: Ic45a5ff8c66b79429e440cbc08d67bf22a083682
46ee31b67d7ee1bd085fbc240502053caa3cf8fa 14-Dec-2016 Andreas Gampe <agampe@google.com> ART: Move to libbase StringPrintf

Remove ART's StringPrintf implementation. Fix up clients. Add
missing includes where necessary.

Test: m test-art-host
Change-Id: I564038d5868595ac3bb88d641af1000cea940e5a
19a4d374738da4dc668a078f92dbe887ff9f00d9 08-Dec-2016 Vladimir Marko <vmarko@google.com> Clean up Class::GetDirectInterface().

Once the `klass` has been resolved, this function should not
need to resolve interface types anymore. Drop the type
resolution from this function and pass the Class as ObjPtr<>
instead of Handle<>. Make callers that expect non-null
result DCHECK() that assumption. For the callers that may
actually need to resolve these interface classes, introduce
a new function ResolveDirectInterface().

Also improve ObjPtr<> constructors and assignment operator
to improve overload resolution. For example, if we have
foo(ObjPtr<T1>) and foo(ObjPtr<T2>), calling foo(.) with
a T1* would have previously been ambiguous even if T1 is
not a base of T2.

Test: m test-art-host
Change-Id: Iff44a7285f68f0af4507fc9ba37343865422fe84
08883debd927d18c9ecf66683a2a11aa98165656 08-Nov-2016 Andreas Gampe <agampe@google.com> ART: Refactor jfieldID handling

ArtField objects have been native since Marshmallow.
Remove the dependency on being runnable. Refactor the
code into the jni_internal header.

Test: m test-art-host
Change-Id: I46708c70f9b4b566d7e26e4c5ffc3f0cbadc43fa
13b27842e88ccf1a42807c92daeb108e867dc4cd 08-Nov-2016 Andreas Gampe <agampe@google.com> ART: Refactor jmethodID handling

ArtMethod objects have been native since Marshmallow.
Remove the dependency on being runnable. Refactor the
code into the jni_internal header.

Test: m test-art-host
Change-Id: I1385fcd4c08981491701da55a87036b447aa2fc2
eb84221ffc00357be6d69e2e461c7a45ee96334a 07-Oct-2016 Leonard Mosescu <mosescu@google.com> Enable agent attaching during live phase

This is the ART part, the plumbing from VMDebug_attachAgent() to
actually loading the agent into the runtime.

Test: m test-art-host

Bug: 31682382

Change-Id: I3ccc67aa050c1f78278882128983686ed44ddec2
28357fab628bd9b91749988b554977398caf9963 19-Oct-2016 Mathieu Chartier <mathieuc@google.com> Move most of class linker to ObjPtr

Return values are still mirror pointer. Fix some failing asserts in
compiler driver and tests.

Bug: 31113334

Test: test-art-host

Change-Id: I4450bf9dfb2541749496b8388616e8aae8488919
709b070044354d9f47641f273edacaeeb0240ab7 13-Oct-2016 David Sehr <sehr@google.com> Remove mirror:: and ArtMethod deps in utils.{h,cc}

The latest chapter in the ongoing saga of attempting to dump a DEX
file without having to start a whole runtime instance. This episode
finds us removing references to ArtMethod/ArtField/mirror.

One aspect of this change that I would like to call out specfically
is that the utils versions of the "Pretty*" functions all were written
to accept nullptr as an argument. I have split these functions up as
follows:
1) an instance method, such as PrettyClass that obviously requires
this != nullptr.
2) a static method, that behaves the same way as the util method, but
calls the instance method if p != nullptr.
This requires using a full class qualifier for the static methods,
which isn't exactly beautiful. I have tried to remove as many cases
as possible where it was clear p != nullptr.

Bug: 22322814
Test: test-art-host
Change-Id: I21adee3614aa697aa580cd1b86b72d9206e1cb24
28bd2e4f151267b34b8e1eb19c489d8d547bbf5c 04-Oct-2016 Mathieu Chartier <mathieuc@google.com> Move mirror::Class to use ObjPtr

Leave the return types as non ObjPtr for now. Fixed moving GC bugs
in tests.

Test: test-art-host

Bug: 31113334

Change-Id: I5da1b5ac55dfbc5cc97a64be2c870ba9f512d9b0
2d8559517759dcfac749a28d6713d36809ec556f 13-Oct-2016 Mathieu Chartier <mathieuc@google.com> Move Heap::GetInstances to use Handles

Prevent moving GC bugs from VisitObjects. Fix JDWP tests.

Test: art/tools/run-jdwp-tests.sh '--mode=host' '--variant=X32' --debug

Bug: 31113334
Change-Id: Ie7f51f1980ec0c1eddc3b59c3e49564eacb3be85
aea9bfb051bb197fdfb63d56ff0f3d63b36eb499 13-Oct-2016 Mathieu Chartier <mathieuc@google.com> Use handles for GetReferringObjects

Required since VisitObjects may cause thread suspension. Fixes
failing jdwp tests.

Test: test-art-host
Test: art/tools/run-jdwp-tests.sh '--mode=host' '--variant=X32' --debug

Bug: 31113334
Change-Id: Ic11780b3778c83e7812bc90c0723a293537f376c
e8a3c576301fd531d5f73a65fc8b84a63619d580 12-Oct-2016 Mathieu Chartier <mathieuc@google.com> Replace StackHandleScopeCollection with VariableSizedHandleScope

VariableSizedHandleScope's internal handle scopes are not pushed
directly on the thread. This means that it is safe to intermix with
other types of handle scopes.

Added test.

Test: clean-oat-host && test-art-host

Change-Id: Id2fd1155788428f394d49615d337d9134824c8f0
9d156d500801accee919b6d51e22d6ddcdcd4a05 07-Oct-2016 Mathieu Chartier <mathieuc@google.com> Move Heap parameters to ObjPtr

Deleted some unused object dumping code.

Test: test-art-host

Bug: 31113334

Change-Id: I747220caafe6679591fd4b361d7f50383a046164
f8ac97f94aad9ce2d324c2c7c21dde3abf13315b 06-Oct-2016 Mathieu Chartier <mathieuc@google.com> ObjPtr misc cleanup

Check for subtypes in constructor.

Remove various calls to MakeObjPtr and ObjPtr::Ptr.

Bug: 31113334

Test: test-art-host
Change-Id: I8d680d514ea52cd64fc4f7c2e988926bc726174e
1cc62e4ea24828fdb3f3da0b8603f0b107d09a04 04-Oct-2016 Mathieu Chartier <mathieuc@google.com> Rename ObjPtr::Decode to ObjPtr::Ptr

Done to prevent ambiguity with ScopedObjectAccess::Decode.

Bug: 31113334

Test: test-art-host
Change-Id: I07a2497cc9cf66386311798933547471987fc316
3398c7874e002beaa6c2b2fadf183e7d1ddad23a 30-Sep-2016 Mathieu Chartier <mathieuc@google.com> Move ArtField to ObjPtr

Added EXPECT_OBJ_PTR_EQ and variants to gtests.

Fixed moving GC bugs in:
ClassLinker::CreatePathClassLoader
ClassLinkerTest: StaticFields

ObjPtr Decode call sites: 186 -> 181.

Some tests fail due to ResolvedFieldAccessTest, will fix in follow
up CL.

Bug: 31113334

Test: test-art-host CC baker

Change-Id: I8b266ad00f3c20c8cbe7cfdf280d175083df0b88
0795f23920ee9aabf28e45c63cd592dcccf00216 28-Sep-2016 Mathieu Chartier <mathieuc@google.com> Clean up ScopedThreadStateChange to use ObjPtr

Also fixed inclusion of -inl.h files in .h files by adding
scoped_object_access-inl.h and scoped_fast_natvie_object_access-inl.h

Changed AddLocalReference / Decode to use ObjPtr.

Changed libartbenchmark to be debug to avoid linkage errors.

Bug: 31113334

Test: test-art-host

Change-Id: I4d2e160483a29d21e1e0e440585ed328b9811483
894f3fd2bbb314f7040315c3f5db6958291d2fe9 15-Sep-2016 Jeff Hao <jeffhao@google.com> Ensure class is initialized when reading its fields from debugger.

Bug: 31016523
Test: mm run-jdwp-tests-ri & mm run-jdwp-tests-host

(cherry-picked from commit de19a25625823496bcf8f92352f709c7a3924bfa)

Change-Id: I02f6c66116f4507c89f7ca1cb480d7029d97c485
de19a25625823496bcf8f92352f709c7a3924bfa 15-Sep-2016 Jeff Hao <jeffhao@google.com> Ensure class is initialized when reading its fields from debugger.

Bug: 31016523
Test: mm run-jdwp-tests-ri & mm run-jdwp-tests-host
Change-Id: I6bccf8464de7ec1e0c1fdac862cbacf890abede6
9323e6e44060545d6c4f925139572868f65b7fe3 13-Sep-2016 David Sehr <sehr@google.com> Separate annotations from dexfile reading.

Bug: 22322814
Change-Id: I867d66da407dd80394a10d19903ebbc1ec3986ff
Test: test-art
268764da8022cafa5661c5b514eaa343c5257e57 13-Sep-2016 Mathieu Chartier <mathieuc@google.com> Make ScopedAssertNoThreadSuspension no overhead for non-debug

Previously it required Thread::Current() which may not be free.
The plan is to add a lot more ScopedAssertNoThreadSuspension in
the codebase.

Also cleaned up callers.

Bug: 31458474
Change-Id: I5a1621a5435476504d22266cc01a9bf26aab7568
bdf7f1c3ab65ccb70f62db5ab31dba060632d458 31-Aug-2016 Andreas Gampe <agampe@google.com> ART: SHARED_REQUIRES to REQUIRES_SHARED

This coincides with the actual attribute name and upstream usage.
Preparation for deferring to libbase.

Test: m
Test: m test-art-host
Change-Id: Ia8986b5dfd926ba772bf00b0a35eaf83596d8518
064d24e921978a1d44f23aced69d2657d81e9af4 25-Aug-2016 Jeff Hao <jeffhao@google.com> Revert "Revert "Fix debugger calling new String().""

Bug: 30951794
Test: mm -j24 run-jdwp-tests-host

This reverts commit 6f48d4c72e7b4011a6d9652734bd1cb0c389790b.
This also includes the reversion of commit
528954f55e3173b02df2822c1fc680873d6a91c8.

Change-Id: If0b2ae39cb2a9db80b567bb8d5761d504433632d
528954f55e3173b02df2822c1fc680873d6a91c8 24-Aug-2016 Nicolas Geoffray <ngeoffray@google.com> Revert "Fix debugger missing handle between adding and tagging object."

Bug: 30951794

This reverts commit 9e0878494cdacd0877a1614041efc38ebb053017.

Change-Id: I3fe1c7e466ae25a81cd37ee5a4aacb40b55686a1
6f48d4c72e7b4011a6d9652734bd1cb0c389790b 24-Aug-2016 Nicolas Geoffray <ngeoffray@google.com> Revert "Fix debugger calling new String()."

Bug: 30951794

This reverts commit f15ec05896ddc5fec1f224ef97bdfebb72b5a855.

Change-Id: Ie7fc565159a19a19a269099f21db833d470aef7c
3aaa37bba53d6df0265793de48b4b0b57327e57a 29-Jul-2016 jessicahandojo <jessicahandojo@google.com> creating workflow for mirror::String compression

All-ASCII String characters are stored in 8-bit blocks
instead of 16-bit. The compression has not taken place, but all
workflow are in the code already (changing kUseStringCompression in
string.h file to TRUE will enable the feature)

Notes: Feature works on interpreter only without optimizing

Test art: m ART_TEST_INTERPRETER=true ART_TEST_OPTIMIZING=false
test-art-host

Also tested with String tests from libcore/:
1. libcore.java.lang.StringTest
2. libcore.java.lang.StringBufferTest
3. libcore.java.lang.StringBuilderTest
4. libcore.java.lang.OldStringTest
5. libcore.java.lang.OldStringBufferTest

Memory improvement is 33% (from 6.03% to 4.03%, total String memory
from all apps per total memory of all apps) measured on Angler
with Hprof tools

Bug: 31040547
Change-Id: I9cc92c265ebf1305fc06b5fc33efd83797660cce
95ca9d2099ef36a575f93e41b1b77fe2b70ba67c 20-Aug-2016 Jeff Hao <jeffhao@google.com> Fix debugger calling new String().

Used to return an empty string instead of the newly created String.
Requires accompanying jdwp test fix to test String contents.

Bug: 30951794
Test: mm -j24 run-jdwp-tests-host

Merges two cherry-picks:
f15ec05896ddc5fec1f224ef97bdfebb72b5a855
9e0878494cdacd0877a1614041efc38ebb053017

Change-Id: Idc4725b82798a9b6d636c72e76715bc97ad30d23
9e0878494cdacd0877a1614041efc38ebb053017 22-Aug-2016 Jeff Hao <jeffhao@google.com> Fix debugger missing handle between adding and tagging object.

Bug: 30951794
Change-Id: Ic9c5f296efe839a8961ab00d08afc54c5443bc17
f15ec05896ddc5fec1f224ef97bdfebb72b5a855 20-Aug-2016 Jeff Hao <jeffhao@google.com> Fix debugger calling new String().

Used to return an empty string instead of the newly created String.
Requires accompanying jdwp test fix to test String contents.

Bug: 30951794
Change-Id: I27a8e0afcbe7e32a14dd3c394e44b6cd4d3c58f6
Test: mm -j24 run-jdwp-tests-host
aef0c91e0b03f26c3947ccf2608d92ae6eae632d 08-Aug-2016 Sebastien Hertz <shertz@google.com> JDWP: fix method argument count

The arguments count must include 'this' for instance method.

Bug: 30673627
Test: make test-art-host
Test: art/tools/run-jdwp-tests.sh --mode=host --variant=X64
Change-Id: Ie582e3bb3e27a2572ce5d3c66990f02650eee61b
542451cc546779f5c67840e105c51205a1b0a8fd 26-Jul-2016 Andreas Gampe <agampe@google.com> ART: Convert pointer size to enum

Move away from size_t to dedicated enum (class).

Bug: 30373134
Bug: 30419309
Test: m test-art-host
Change-Id: Id453c330f1065012e7d4f9fc24ac477cc9bb9269
98810e34804e224e5ab302cd353393f72a45202b 24-May-2016 Hiroshi Yamauchi <yamauchi@google.com> Remove SetStateUnsafe in Debugger::Disconnected.

The debugger thread has the exclusive mutator lock and doen't need to
switch to runnable while updating instrumentation.

This avoids a spurious failure of the DCHECK in the jdwp test.

Bug: 25262836

Change-Id: Ibfd0bc3936a877fd264396fcc4cc1af8d19a1645
4ba674b914f24f2baf42769401cff43f8261abd6 10-May-2016 Mingyao Yang <mingyao@google.com> Fix an assert during jdwp debugging.

When debugger attaches, we patch entry points of methods in framework code.
During that process, it's possible that some method's declaring class isn't
resolved yet. We need to relax one assert for that case.

Bug: 28630805

(cherry picked from commit 3fd448a8b7903b00fceaed5853306e2d7eb31c72)

Change-Id: I59fd488ad75417a64b52321677ffcac6ccdc5ce1
3fd448a8b7903b00fceaed5853306e2d7eb31c72 10-May-2016 Mingyao Yang <mingyao@google.com> Fix an assert during jdwp debugging.

When debugger attaches, we patch entry points of methods in framework code.
During that process, it's possible that some method's declaring class isn't
resolved yet. We need to relax one assert for that case.

Bug: 28630805
Change-Id: I59fd488ad75417a64b52321677ffcac6ccdc5ce1
8f95cf3cb5f715b1277de9cd7fade07ce4b230be 19-Apr-2016 Hiroshi Yamauchi <yamauchi@google.com> Fix a deadlock between debugger and GC.

Avoid a deadlock between GC and debugger's SuspendAllForDebugger where
GC gets suspended during GC.

Fix the jdwp tests with the CC collector, but the deadlock is NOT
specific to the CC collector.

Bug: 25800335
Bug: 12687968
Change-Id: I8f2869872bce4692d943020072e35ebf5a4e68a5
458b105a9cbab6156d72acf3b9372291dba9097a 29-Mar-2016 Mathieu Chartier <mathieuc@google.com> Obtain stack trace outside of critical section

Fixes deadlock if the stack walk does allocations, changed stack
trace format to prevent slowdown.

Added missing GetInterfaceMethodIfProxy to fix a crash in maps.

Bug: 27857910

(cherry picked from commit 23428587d32361736d4c5e0ba7270c7602695a43)

Change-Id: I64373bcd87a68fdd1b58fb855db2b16c9f6ed36b
23428587d32361736d4c5e0ba7270c7602695a43 29-Mar-2016 Mathieu Chartier <mathieuc@google.com> Obtain stack trace outside of critical section

Fixes deadlock if the stack walk does allocations, changed stack
trace format to prevent slowdown.

Added missing GetInterfaceMethodIfProxy to fix a crash in maps.

Bug: 27857910

Change-Id: Iba86b7390a87349c38785297ac76751417b0fc87
6300fd77033817664aee3056c4ff5fab85698d2b 18-Mar-2016 Nicolas Geoffray <ngeoffray@google.com> Code cleanup between debugger and jit.

This is to allow secondary dex files to be fully compiled.

- No need to do full deopt anymore for breakpoints: code in boot.oat
is deoptimized as soon as the debugger attaches (and we decided that
existing frames could not be debugged), and application being
debugged is compiled debuggable.

- jit should only call UpdateMethodsCode if exit stubs are not
installed due to lock violation otherwise (the lock level of the
jit code cache is lower than the deoptimization lock).
This part needs an overall cleanup beyond the scope of this change.

Change-Id: I38d85dcb270db746c1d6b0ceb7893a1aad8c9655
f448016e70fa91269d3750384aab1ac98d7896fd 16-Mar-2016 David Srbecky <dsrbecky@google.com> Do not JIT boot image during native-debugging (keep AOT code instead).

The performance impact is currently significant and being able
to debug framework is not our primary goal for native debugging.

Change-Id: I3366c2a6317004f9dd16700b271a6c9b974f1c6e
6ea1a0e2168c8d9b6d97c075c73a72d84080f45b 29-Jan-2016 Mingyao Yang <mingyao@google.com> AOT compile framework code as non-debuggable

When a debugger attaches, we patch method entry points in framework
code to interpreter bridge. The code will later be jitted as debuggable.

Change-Id: Id148069ccad95e2339ba214742ae3ef4f084f495
1aa8ec2ccdd7bedb6d30d91c89f1e94ab23c4439 01-Feb-2016 Mathieu Chartier <mathieuc@google.com> Fix up dex cache strings stored in classes

Previously we left the image pointer instead of fixing up the pointer
to the one in the BSS. This only showed up because JIT does the same
as boot image, bypassing null check.

Fixed a bug where oat files without embedded dex cache arrays would
get their dex cache arrays corrupted.

Added a non virtual class visitor for performance.

Bug: 26846419
Bug: 22858531

Change-Id: I8cd0d61e440f753b4628ddb8c932eb23a0a81027
81f0f953c4bb159997046c962d44cb1898b1778d 20-Jan-2016 Nicolas Geoffray <ngeoffray@google.com> Move backward branch instrumentation to all branch.

This is in preparation for osr, and later dead branch profiling.

Change-Id: I4597c0784c894c310f295dd534967d67dcefa419
7929a489a9b256020d3add793198ba1e97e426e6 31-Dec-2015 Andreas Gampe <agampe@google.com> ART: Fix JDWP GetClassLoader command

The command is spec-ed to take a type, and return the type's
classloader. Decode the input as a class, just like all the
other ReferenceType commands already do.

Bug: 26349019
Change-Id: I129fbc844f529fa9234742ffe128d7ac41ce6d7e
7a62feae77ebec5119f5e9bea2a6c1cb36ed3084 31-Dec-2015 Andreas Gampe <agampe@google.com> Revert "ART: Fix JDWP GetClassLoader command"

This reverts commit 40144cc022d321e2ec28d7fac2f5a24ba6714aff.

The implementation should not DCHECK.

Bug: 26349019
Change-Id: I9238ee0b05f8a150f55773e78301ded9e8b38334
40144cc022d321e2ec28d7fac2f5a24ba6714aff 30-Dec-2015 Andreas Gampe <agampe@google.com> ART: Fix JDWP GetClassLoader command

The command is spec-ed to take a type, and return the type's
classloader. The input is thus already a Class, not a generic Object.
Fix the implementation to not always return null.

Bug: 26349019
Change-Id: I4aa075902f4a112624edc644d3540a59eea057c8
51a64d5d4fe91842cc2a5f2a412441147c145683 17-Dec-2015 Alex Light <allight@google.com> Make use of new method iterators.

Change-Id: I1f82f17951339b2054a1dac87bde79f9e803fc4a
b06e28e5b9fbabe3e69b18f31bf353eaff5d0c1f 10-Dec-2015 David Srbecky <dsrbecky@google.com> Refactor DexFile::DecodeDebugInfo.

Split the method into two - one for locals and one for positions.
All uses of the method request only one of the two and it makes the
code slightly cleaner. The position variant requires fewer parameters.

Expose additional line table information which was previously ignored
by the decode method (prologue, epilogue, source file).

Change-Id: Idf8ba98fa58ea0d2103932b5cc0af81365885107
e6465bc8a52cfa3995b4072810cdb7ab397a7793 15-Dec-2015 Dimitry Ivanov <dimitry@google.com> Remove references to dlmalloc specific functions

Remove references to internal libc dlmalloc_* functions
so that we can hide them for lp64

Change-Id: I13977bea63d900e1819052140e3bd6bc1f2fc759
6c8467ffc427a513dc2fdea7ed9eeb0bb54d30ef 21-Nov-2015 Alex Light <allight@google.com> Make debugger support default methods.

Supports breaking on, stepping into and through default methods.

Bug: 25549445
Bug: 24618811

Change-Id: I1a47e3263a0624adbd9e83b99d0acd7bef7757a4
464595f53abe4370ee6f589eb472e2036e39bce7 24-Nov-2015 Przemyslaw Szczepaniak <pszczepaniak@google.com> Enso ThreadGroup.groups is an array not ArrayList

ThreadGroup.groups in the enso branch uses plain
array in place of ArrayList. debugger.cc code
needed minor adjustments to access it.

Bug: 25857261
Change-Id: I77ffb92b64a3642933c3240dbadedab5def5dc1b
636b9252af8d8848dbf8f30b7e9638867b62c791 01-Aug-2015 Mingyao Yang <mingyao@google.com> Support deoptimization only to set vreg

This CL removes the old API that was used to update vreg. We now rely
exclusively on deoptimization to change the value of a vreg (mainly
from the debugger). This allows to have only one mechanism working
with both Quick and Optimizing compilers. It also remove run-test
455-set-vreg which was the only user of the old API.

This CL also renames StackVisitor::SetVReg[Pair]FromDebugger to
StackVisitor::SetVReg[Pair] to reflect that change.

Bug: 25428216
Change-Id: Ib09510185280dbd0f6d02c52549ae9671c187e32
a5891e81a2fb833307cf7c7e7267070dc0223dc8 06-Nov-2015 Nicolas Geoffray <ngeoffray@google.com> Fix interaction between JIT and instrumentation.

- The JIT needs to go through the instrumentation to update
entry points.
- The instrumention needs to know if a method got JITted
to know if needs to deoptimize.

bug:25438583

Change-Id: I4b186a1da9f4a3fb329efd052a774d5502a902a1
a3e1377f3f389a33f6a283796ea5cea1583911f3 05-Nov-2015 Sebastien Hertz <shertz@google.com> JDWP: fix returned tag for ClassType.NewInstance

Bug: 25490662
Change-Id: I0c369f04342a60caef4f7462005804307a410d18
56d5e50a7519495777f3223e21b9d73d8ceaa6ad 03-Nov-2015 Sebastien Hertz <shertz@google.com> JDWP: fix java.lang.String creation

Bug: 25439464
Change-Id: I56f11ed942585e8110dbbba1178cf11ec76e032f
41af5e50d0b5e9d13084a61cfe9dfa6b6e201a40 28-Oct-2015 Mathieu Chartier <mathieuc@google.com> Store method as ArtMethod* instead of jmethodId in Breakpoint

Previously we needed a ScopedObjectAccess for Dbg::VisitRoots,
this could cause deadlocks in the following scenario:

GC:
Goes to runnable state while holding mutator lock as shared held.
This occurred in Dbg::VisitRoots when calling Breakpoint::Method.

Other thread:
Calls SuspendAll and suspends the GC thread before it can go back
to suspended thread state. This thread then attempts to exclusive
lock mutator lock, but the GC is suspended while holding it in a
shared state.

Bug: 25336094
Change-Id: Idcb8d34c314b1d6951abe533a0cfa586cc07d7d6
4b8f1ecd3aa5a29ec1463ff88fee9db365f257dc 26-Aug-2015 Roland Levillain <rpl@google.com> Use ATTRIBUTE_UNUSED more.

Use it in lieu of UNUSED(), which had some incorrect uses.

Change-Id: If247dce58b72056f6eea84968e7196f0b5bef4da
a6b1ead81603513fd40b77fd72f06d8cb1f35276 06-Oct-2015 Mathieu Chartier <mathieuc@google.com> Mark breakpoint roots

Used to prevent class unloading on methods that have breakpoints.

Bug: 22720414
Change-Id: I9aee8bcbfdf253607e89dfc55a50ba3f11d99206
aa5168291c46f9b418d989bccf2d8e09338a83e6 03-Oct-2015 Mathieu Chartier <mathieuc@google.com> Add exclusion between instrumentation and GC

Instrumentation calls VisitClasses while exclusive holding the
mutator lock. This can cause deadlocks since VisitClasses needs to
decode JNI weak globals. If the system weak slow path flag is set,
then we wait holding locks while exclusive holding the mutator lock.
This causes a deadlock since the GC cannot acquire the mutator lock
to sweep system weaks.

This fixes a deadlock seen in one of the tracing tests.

Change-Id: I580152118e068a70f309dcc19df4144afec835dd
8ac9c91cfa2408cf8d27bcf12785a60923aab775 02-Oct-2015 Mathieu Chartier <mathieuc@google.com> Make SetStateUnsafe run checkpoints before going to suspended

This prevents cases where we can get a checkpoint request in runnable
and then unsafe set to suspended. This was bad behavior since the
checkpoint may not be run in a timely manner.

Bug: 24191051
Change-Id: I73605c1a1154f67699f3902141f3232ab064793f
99170c636dfae4908b102347cfe9f92bad1881cc 06-Jul-2015 Mingyao Yang <mingyao@google.com> Deoptimization support in optimizing compiler for setting local values

Due to compiler optimizations, we may not always be able to update
the value of a local variable in a compiled frame (like a variable
seen as constant by the compiler). To avoid that situation, we simply
deoptimize compiled frames updated by the debugger so they are
executed by the interpreter with the updated value.

When the debugger attempts to set a local variable (actually a DEX
register or a pair of registers) in a compiled frame, we allocate a
ShadowFrame associated to that frame (using its frame id) and set the
new value in that ShadowFrame. When we know we are about to continue
the execution of the compiled frame, we deoptimize the stack using
the preallocated ShadowFrame (instead of creating a new one). We
initialize it with the current value of all DEX registers except
the ones that have been set by the debugger. Therefore, the
ShadowFrame represent the runtime context modified by the debugger.

Bumps oat version to force recompilation.

Bug: 19944235
Change-Id: I0ebe6241264f7a3be0f14ee4516c1f7436e04da6
26f728661a08062a373a3203b72dc2555c2aed2d 15-Sep-2015 Sebastien Hertz <shertz@google.com> Cleanup thread access in StackVisitor

Adds method StackVisitor::GetThread to give access to the visited
Thread* so we no longer need to copy that pointer in subclasses.

Also adds a few missing const and DISALLOW_COPY_AND_ASSIGN.

Change-Id: I57649ee7742ef4ef1e01447ac2fbb66f977b22eb
4f55e22630d99ca0edd9e951e5ee96b57bb9b980 04-Sep-2015 Mathieu Chartier <mathieuc@google.com> Add and use ScopedSuspendAll

Usage replaces most SuspendAll and ResumeAll calls.

Change-Id: I355683a5365876242cea85a656dcb58455f7a294
5550ca8bcc742b109d77e62f3a0877c667d894d3 21-Aug-2015 Nicolas Geoffray <ngeoffray@google.com> Record profiling information before Jitting.

- Add a new instrumentation kind to record dynamic invokes.
- Use the JNI entry point field to store the profiling data.
- Record seen receivers for every dynamic invoke.

Change-Id: I2c1738ab2a72052d45964d055dc16b44b906e54c
520633bebd2bf4d70884d30f179dbde9f275aac6 08-Sep-2015 Sebastien Hertz <shertz@google.com> Support deoptimization on exception

Allows to deoptimize when an exception is being thrown. We only
deoptimize if an executable frame (starting from the catch handler)
needs to be executed with the interpreter.

Before executing deoptimized frames, the exception is restored. The
interpreter starts by handling this exception at the point of the
throwing instruction.

Bug: 23714835
Change-Id: I0c5f7d4b257644acf12210aae8e5b6bb0f4af1f7
f1d666e1b48f8070ef1177fce156c08827f08eb8 04-Sep-2015 Mathieu Chartier <mathieuc@google.com> Add ScopedThreadSuspension

Fixes the TransitionFromRunnableToSuspended and
TransitionFromSuspendedToRunnable pattern that was prone to errors.

Change-Id: Ie6ae9c0357c83b4fc4899d05dfa0975553170267
05792b98980741111b4d0a24d68cff2a8e070a3a 03-Aug-2015 Vladimir Marko <vmarko@google.com> ART: Move DexCache arrays to native.

This CL has a companion CL in libcore/
https://android-review.googlesource.com/162985

Change-Id: Icbc9e20ad1b565e603195b12714762bb446515fa
2e1c16d9a4695e4b5cab3ed3ec95f7a88e69c79f 28-Aug-2015 Sebastien Hertz <shertz@google.com> JDWP: check object is assignable in ArrayReference.SetValues

If the object's type is not compatible with the array's type, we
return a TYPE_MISMATCH error.

Bug: 23602995
Change-Id: Ibd838dd301e40db4f08c74c9783707d1c87c67fd
76f55b030d2517d434f227bee2363c3fb760e5c6 22-Aug-2015 Hiroshi Yamauchi <yamauchi@google.com> Synchronize JNI critical calls with the CC collector thread flip.

JNI critical calls (like GetArrayElementsCritical) would need to block
for the whole GC run to finish if the CC collector GC is ongoing. This
CL changes it so that they don't need to block for the GC run, but
only for the duration of the thread flip operation, which is much
shorter. This is valid due to the to-space invariant.

Bug: 12687968
Bug: 19235243

Change-Id: I1b6b4ae4fa539ddc0ec50b10ae8c8709f2a12fe8
3887c468d731420e929e6ad3acf190d5431e94fc 12-Aug-2015 Roland Levillain <rpl@google.com> Remove unnecessary `explicit` qualifiers on constructors.

Change-Id: Id12e392ad50f66a6e2251a68662b7959315dc567
90ef3db4bd1d4865f5f9cb95c8e7d9afb46994f9 05-Aug-2015 Mathieu Chartier <mathieuc@google.com> Address some comments and clean up

Change-Id: I538cf204f1c89d5fc81f8fc5e5800fcf1cf87359
b1d8c314b55bb2df2b2bb72a3daaf5db65b7ebc7 04-Aug-2015 Igor Murashkin <iam@google.com> Revert "cleanup: Replace pointers with out-parameters and fix-up formatting"

This reverts commit a315f5c546b796f55f4872bb6efc15eb858d9639.

--

Revert "runtime: cleanup class_linker out-parameters and formatting"

This reverts commit bc1d78daa463572c5a770cdca858a3b51d8e1b7b.

--

Revert "base: replace raw pointers for out-parameters with safer out<T>"

This reverts commit fb326cffc679cab8eb873b9e44795706f023cb3c.
bc1d78daa463572c5a770cdca858a3b51d8e1b7b 31-Jul-2015 Igor Murashkin <iam@google.com> runtime: cleanup class_linker out-parameters and formatting

* Use out<T> instead of parameters
* Fixes up some other signatures to be more correct
* Reformat parameters to be one per line if they can't fit on one line
* Reformat locks to be one per line if they can't fit on the decl line

Change-Id: Ib71b08707d3ed0bb85299406c0b23a1de4e92a1c
40c8141b48275afd1680b99878782848ab3a6761 01-Aug-2015 Igor Murashkin <iam@google.com> Revert "runtime: cleanup class_linker out-parameters and formatting"

This reverts commit 0de694ed3efe8412b83622a24074831edcc7e384.

Change-Id: I4b185584d6e47918179b16d76709cc3366872f3c
0de694ed3efe8412b83622a24074831edcc7e384 31-Jul-2015 Igor Murashkin <iam@google.com> runtime: cleanup class_linker out-parameters and formatting

* Use out<T> instead of parameters
* Fixes up some other signatures to be more correct
* Reformat parameters to be one per line if they can't fit on one line
* Reformat locks to be one per line if they can't fit on the decl line

Change-Id: I1031cf4edc41f95b89edb343d43ef93e15384206
c60e1b755c5632dfeb04c333489ede52ee5c945f 30-Jul-2015 Andreas Gampe <agampe@google.com> ART: Use __ANDROID__ instead of HAVE_ANDROID_OS

Use the proper define.

Change-Id: I71e291ac25f5d5f0187ac9b6ef2d6872f19e6085
e0671ce5a6cb34e44e3afefa8e29c0c3e30d2855 29-Jul-2015 Mathieu Chartier <mathieuc@google.com> Clean up class visitors

Move from function pointers to virtual function visitors.

Change-Id: I68cb83c1d2ed9b5a89f8e534fe7ca4bbc1c91f45
90443477f9a0061581c420775ce3b7eeae7468bc 17-Jul-2015 Mathieu Chartier <mathieuc@google.com> Move to newer clang annotations

Also enable -Wthread-safety-negative.

Changes:
Switch to capabilities and negative capabilities.

Future work:
Use capabilities to implement uninterruptible annotations to work
with AssertNoThreadSuspension.

Bug: 20072211

Change-Id: I42fcbe0300d98a831c89d1eff3ecd5a7e99ebf33
14c3bf91b2ec434295ec84d6446f495fb7de6d5c 13-Jul-2015 Mathieu Chartier <mathieuc@google.com> Change intern table to not use WaitHoldingLocks

Bug: 22423014
Change-Id: I9e16b8cb4def72fff73f1783a182877105feb7aa
41656de4b6440bcd1bea5fb785f0710153b2bc68 07-Jul-2015 Man Cao <manc@google.com> Fix potential bugs in allocation tracker

Add a missing visit allocation records call in concurrent copying collecter.
Handle null class objects if we support class unloading, and issues
with disallow and allow new allocation records.

Bug: 20037135
Change-Id: I59b7321c281e0d79a620501b2f43e36d2a576203
d4032e4e2d454b11dba74acc4824abb8a846f707 12-Jun-2015 Sebastien Hertz <shertz@google.com> JDWP: remove suspend count check on invoke

We used to return an error when the debugger asks to execute a method
in a thread that is suspended more than once. The reason was to avoid
blocking the JDWP thread on a thread that is still suspended.

Now invoke commands are handled asynchronously, we no longer need to
that check.

Bug: 19397712
Change-Id: I14f259923753e411dcce514183ed6fccd4cd0450
42c3c33df8b6eefc4ba532f1981282510f109928 24-Jun-2015 Man Cao <manc@google.com> Make allocation tracker use less memory

The allocation tracker no longer keeps recently allocated objects live.
Instead it just keeps their class objects live as strong roots. This fixed
the gc-stress test failure for 098-ddmc.

Also fixed the issue in DisableNewSystemWeak() for allocation tracker,
by making new allocation to wait until GC's sweeping to complete. I didn't
feel any significant slowdown with this wait.

Bug: 20037135
Change-Id: I6a98188832cf7ee478007e3788e742dc6e18f7b8
1ed11b9ad5512cf464cb1686640df53201fa5297 12-Jun-2015 Man Cao <manc@google.com> Restore DDMS recent allocation tracking's behavior

Make the allocation tracker mark recently allocated objects as roots,
so the allocation records are not swept. Because DDMS needs recent
allocation tracking records even for dead objects. This should fix
the flaky failures for 098-ddmc test, but it cannot pass GC stress
test (OOM). Re-enabled 098-ddmc for other tests.

There should be an option to not mark them as roots, when user only
needs HPROF dump with traces but not DDMS's recent allocation tracking.
Probably need to add a new JNI API function for this option.

There could be another way to keep a second list of recent allocation
records and maintain a type cache for them, so not to make the objects
roots. But it's more complex, and not sure which is better.

Also reduce memory usage for AllocRecordStackTrace objects, and change
default stack depth to 16. Rename the property that controls the stack
depth to "debug.allocTracker.maxStackDepth" so developer can change it.

Bug:20037135
Change-Id: Ic6b9ae87bdcda558be6f14ded8057e763439881c
33d6903e570daf8f3cf7c1f6ebd9a6dd22c7c23c 18-Jun-2015 Roland Levillain <rpl@google.com> Replace some run-time assertions with compile-time ones in ART.

Change-Id: I16c3fad45c4b98b94b7c83d071374096e81d407a
4998374789fc62c147027eef022c74a97949ac6e 11-Jun-2015 Sebastien Hertz <shertz@google.com> JDWP: update handling of 8-bit and 16-bit fields

We must use special getter/setter for types smaller than int:
boolean, byte, char and short. However, JDWP still requires to treat:
- int and float as 32-bit values
- long and double as 64-bit values

Bug: 21746739

(cherry picked from commit 05c26b30843dd8283c703356e75d51726e8b8e3a)

Change-Id: I2d667291974e191f2c9b10311ce02435b902dd0c
05c26b30843dd8283c703356e75d51726e8b8e3a 11-Jun-2015 Sebastien Hertz <shertz@google.com> JDWP: update handling of 8-bit and 16-bit fields

We must use special getter/setter for types smaller than int:
boolean, byte, char and short. However, JDWP still requires to treat:
- int and float as 32-bit values
- long and double as 64-bit values

Bug: 21746739
Change-Id: I8d0ce46246084c9e16f287da28d8969d36b83b99
6ba35b50347aa7418c66c7b046cd164987e95df3 01-Jun-2015 Sebastien Hertz <shertz@google.com> JDWP: asynchronous invoke command handling

The JDWP thread used to wait for the result of a method invocation
running in an event thread. But doing that prevents the JDWP thread
from processing incoming commands from the debugger if the event
thread gets suspended by a debug event occurring in another thread.
In Android Studio (or another IDE), this leads to the debugger being
blocked (with the famous message "Waiting until last debugger command
completes" of Android Studio / IntelliJ) because it is actually
waiting for the reply of its latest command while the JDWP thread
cannot process it.

This CL changes the way invoke commands (ClassType.InvokeCommand,
ClassType.NewInstance and ObjectReference.InvokeCommand) are handled
in the ART runtime.
The JDWP thread no longer waits for the event thread to complete the
method invocation. It now simply waits for the next JDWP command to
process. This means it does not send any reply for invoke commands,
except if the information given by the debugger is wrong. In this
case, it still sends a reply with the appropriate error code.
The event thread is now responsible for sending the reply (containing
the result and the exception object of the invoked method) before
going back to the suspended state.

In other words, we add special handling for invoke commands so they
are handled asynchronously while other commands remained handled
synchronously. In the future, we may want to handle all commands
asynchronously (using a queue of reply/event for instance) to remove
the special handling code this CL is adding.

Now the JDWP thread can process commands while a thread is invoking
a method, it is possible for the debugger to detach (by sending a
VirtualMachine.Dispose command) before the invocation completes. In
that situation, we must not suspend threads again (including the
event thread that executed the method) because they would all remain
suspended forever.

Also minor cleanup of the use of JDWP constants and update comments.

Bug: 21515842
Bug: 18899981

(cherry picked from commit cbc5064ff05179b97b416f00ca579c55e38cd7d9)

Change-Id: I8d31006043468913ee8453212e6d16e11fcfe4ea
8c2ff641294715864013737fdec57cdfd410270c 28-May-2015 Man Cao <manc@google.com> Add allocation stack traces for HPROF dump.

This feature is currently only enabled when DDMS's allocation tracking
is enabled. In the future there should be a way to enable this feature
before an application starts.

Also updates DDMS's recent allocation tracking to use a new backend
data structure that is shared with this feature.

The following system properties controls customizable parameters:
dalvik.vm.allocTrackerMax: max number of objects that have allocation
records, default 512K;

dalvik.vm.recentAllocMax: max number of records that are sent to DDMS
when clicking "Get allocation" button,
default 64K-1 (limit of the protocol);

dalvik.vm.allocStackDepth: max number of stack frames in an allocation
record, default 4.

Bug: 20037135
Change-Id: I26ed378a5613678bd3c43e846025f90470a8e059
cbc5064ff05179b97b416f00ca579c55e38cd7d9 01-Jun-2015 Sebastien Hertz <shertz@google.com> JDWP: asynchronous invoke command handling

The JDWP thread used to wait for the result of a method invocation
running in an event thread. But doing that prevents the JDWP thread
from processing incoming commands from the debugger if the event
thread gets suspended by a debug event occurring in another thread.
In Android Studio (or another IDE), this leads to the debugger being
blocked (with the famous message "Waiting until last debugger command
completes" of Android Studio / IntelliJ) because it is actually
waiting for the reply of its latest command while the JDWP thread
cannot process it.

This CL changes the way invoke commands (ClassType.InvokeCommand,
ClassType.NewInstance and ObjectReference.InvokeCommand) are handled
in the ART runtime.
The JDWP thread no longer waits for the event thread to complete the
method invocation. It now simply waits for the next JDWP command to
process. This means it does not send any reply for invoke commands,
except if the information given by the debugger is wrong. In this
case, it still sends a reply with the appropriate error code.
The event thread is now responsible for sending the reply (containing
the result and the exception object of the invoked method) before
going back to the suspended state.

In other words, we add special handling for invoke commands so they
are handled asynchronously while other commands remained handled
synchronously. In the future, we may want to handle all commands
asynchronously (using a queue of reply/event for instance) to remove
the special handling code this CL is adding.

Now the JDWP thread can process commands while a thread is invoking
a method, it is possible for the debugger to detach (by sending a
VirtualMachine.Dispose command) before the invocation completes. In
that situation, we must not suspend threads again (including the
event thread that executed the method) because they would all remain
suspended forever.

Also minor cleanup of the use of JDWP constants and update comments.

Bug: 21515842
Bug: 18899981
Change-Id: I15e00fb068340f3d69dc9225d8d2065246e68c58
3d21bdf8894e780d349c481e5c9e29fe1556051c 22-Apr-2015 Mathieu Chartier <mathieuc@google.com> Move mirror::ArtMethod to native

Optimizing + quick tests are passing, devices boot.

TODO: Test and fix bugs in mips64.

Saves 16 bytes per most ArtMethod, 7.5MB reduction in system PSS.
Some of the savings are from removal of virtual methods and direct
methods object arrays.

Bug: 19264997

(cherry picked from commit e401d146407d61eeb99f8d6176b2ac13c4df1e33)

Change-Id: I622469a0cfa0e7082a2119f3d6a9491eb61e3f3d

Fix some ArtMethod related bugs

Added root visiting for runtime methods, not currently required
since the GcRoots in these methods are null.

Added missing GetInterfaceMethodIfProxy in GetMethodLine, fixes
--trace run-tests 005, 044.

Fixed optimizing compiler bug where we used a normal stack location
instead of double on ARM64, this fixes the debuggable tests.

TODO: Fix JDWP tests.

Bug: 19264997

Change-Id: I7c55f69c61d1b45351fd0dc7185ffe5efad82bd3

ART: Fix casts for 64-bit pointers on 32-bit compiler.

Bug: 19264997
Change-Id: Ief45cdd4bae5a43fc8bfdfa7cf744e2c57529457

Fix JDWP tests after ArtMethod change

Fixes Throwable::GetStackDepth for exception event detection after
internal stack trace representation change.

Adds missing ArtMethod::GetInterfaceMethodIfProxy call in case of
proxy method.

Bug: 19264997
Change-Id: I363e293796848c3ec491c963813f62d868da44d2

Fix accidental IMT and root marking regression

Was always using the conflict trampoline. Also included fix for
regression in GC time caused by extra roots. Most of the regression
was IMT.

Fixed bug in DumpGcPerformanceInfo where we would get SIGABRT due to
detached thread.

EvaluateAndApplyChanges:
From ~2500 -> ~1980
GC time: 8.2s -> 7.2s due to 1s less of MarkConcurrentRoots

Bug: 19264997
Change-Id: I4333e80a8268c2ed1284f87f25b9f113d4f2c7e0

Fix bogus image test assert

Previously we were comparing the size of the non moving space to
size of the image file.

Now we properly compare the size of the image space against the size
of the image file.

Bug: 19264997
Change-Id: I7359f1f73ae3df60c5147245935a24431c04808a

[MIPS64] Fix art_quick_invoke_stub argument offsets.

ArtMethod reference's size got bigger, so we need to move other args
and leave enough space for ArtMethod* and 'this' pointer.

This fixes mips64 boot.

Bug: 19264997
Change-Id: I47198d5f39a4caab30b3b77479d5eedaad5006ab
415fd0833fe44b99ed57353f4bd7572681506daa 01-Jun-2015 Sebastien Hertz <shertz@google.com> Fix JDWP tests after ArtMethod change

Fixes Throwable::GetStackDepth for exception event detection after
internal stack trace representation change.

Adds missing ArtMethod::GetInterfaceMethodIfProxy call in case of
proxy method.

Bug: 19264997
Change-Id: I363e293796848c3ec491c963813f62d868da44d2
e401d146407d61eeb99f8d6176b2ac13c4df1e33 22-Apr-2015 Mathieu Chartier <mathieuc@google.com> Move mirror::ArtMethod to native

Optimizing + quick tests are passing, devices boot.

TODO: Test and fix bugs in mips64.

Saves 16 bytes per most ArtMethod, 7.5MB reduction in system PSS.
Some of the savings are from removal of virtual methods and direct
methods object arrays.

Bug: 19264997
Change-Id: I622469a0cfa0e7082a2119f3d6a9491eb61e3f3d
1309ba27dd02e0e4dea0e45f8b5500080cbbd703 28-May-2015 Sebastien Hertz <shertz@google.com> Fix single-step in native thread

If we attempt to single-step in a thread that is not running Java
code, there is no current method on the stack. So we need to check
for null before trying to decode debug info.

Bug: 21320157

(cherry picked from commit 52f5f93873ec244320e05b033243c5c7a3ae40e2)

Change-Id: I961108071dd58a23f6327370b00c35a4cabe0aa7
52f5f93873ec244320e05b033243c5c7a3ae40e2 28-May-2015 Sebastien Hertz <shertz@google.com> Fix single-step in native thread

If we attempt to single-step in a thread that is not running Java
code, there is no current method on the stack. So we need to check
for null before trying to decode debug info.

Bug: 21320157
Change-Id: Idef9954d14e1eb7185f25d2a6e238135ac52d35f
41b175aba41c9365a1c53b8a1afbd17129c87c14 19-May-2015 Vladimir Marko <vmarko@google.com> ART: Clean up arm64 kNumberOfXRegisters usage.

Avoid undefined behavior for arm64 stemming from 1u << 32 in
loops with upper bound kNumberOfXRegisters.

Create iterators for enumerating bits in an integer either
from high to low or from low to high and use them for
<arch>Context::FillCalleeSaves() on all architectures.

Refactor runtime/utils.{h,cc} by moving all bit-fiddling
functions to runtime/base/bit_utils.{h,cc} (together with
the new bit iterators) and all time-related functions to
runtime/base/time_utils.{h,cc}. Improve test coverage and
fix some corner cases for the bit-fiddling functions.

Bug: 13925192

(cherry picked from commit 80afd02024d20e60b197d3adfbb43cc303cf29e0)

Change-Id: I905257a21de90b5860ebe1e39563758f721eab82
80afd02024d20e60b197d3adfbb43cc303cf29e0 19-May-2015 Vladimir Marko <vmarko@google.com> ART: Clean up arm64 kNumberOfXRegisters usage.

Avoid undefined behavior for arm64 stemming from 1u << 32 in
loops with upper bound kNumberOfXRegisters.

Create iterators for enumerating bits in an integer either
from high to low or from low to high and use them for
<arch>Context::FillCalleeSaves() on all architectures.

Refactor runtime/utils.{h,cc} by moving all bit-fiddling
functions to runtime/base/bit_utils.{h,cc} (together with
the new bit iterators) and all time-related functions to
runtime/base/time_utils.{h,cc}. Improve test coverage and
fix some corner cases for the bit-fiddling functions.

Bug: 13925192
Change-Id: I704884dab15b41ecf7a1c47d397ab1c3fc7ee0f7
54d65738eecc1fa79ed528ff2f6b9b4f7a4743be 26-May-2015 Sebastien Hertz <shertz@google.com> JDWP: fix breakpoint on catch statement

Setting a breakpoint on a catch statement in the source actually
installs the breakpoint on a DEX move-exception instruction. At this
point, an exception is pending in the current thread.

The issue is no exception must be pending in the current thread to
report the breakpoint event. This is required to be able to call JNI
functions to create JDWP ids.

This CL fixes it by clearing the pending exception before reporting
event and restore it after reporting the event.

Bug: 21382373

(cherry picked from commit de48aa6708a3d5dacf7db3d64965e23261fb15d3)

Change-Id: Ie107eb47b6f2559c4fa5297f4033e07baad06f38
de48aa6708a3d5dacf7db3d64965e23261fb15d3 26-May-2015 Sebastien Hertz <shertz@google.com> JDWP: fix breakpoint on catch statement

Setting a breakpoint on a catch statement in the source actually
installs the breakpoint on a DEX move-exception instruction. At this
point, an exception is pending in the current thread.

The issue is no exception must be pending in the current thread to
report the breakpoint event. This is required to be able to call JNI
functions to create JDWP ids.

This CL fixes it by clearing the pending exception before reporting
event and restore it after reporting the event.

Bug: 21382373
Change-Id: Id3c60cca398135a3e0859a1ccb645b9c99d5ca76
39b6c24ce68cf05db0f82f454b4401cfb03d675f 20-May-2015 Jeff Hao <jeffhao@google.com> Intercept JNI invocation of String.<init> methods.

libmono uses JNI AllocObject and CallNonvirtualVoidMethod to create and
initialize a string instead of using the recommended NewObject. This
change adds an intercept to change the String.<init> call to a
StringFactory call instead. Then, it uses the object id of the original
string object referrer and maps it to the result of the StringFactory.

Bug: 21288130

(cherry picked from commit 15e9ad1d028d7f12cb598b075453173532a00d91)

Change-Id: I3421c43722c07397da4a398c2ca9110e1d40bcfa
15e9ad1d028d7f12cb598b075453173532a00d91 20-May-2015 Jeff Hao <jeffhao@google.com> Intercept JNI invocation of String.<init> methods.

libmono uses JNI AllocObject and CallNonvirtualVoidMethod to create and
initialize a string instead of using the recommended NewObject. This
change adds an intercept to change the String.<init> call to a
StringFactory call instead. Then, it uses the object id of the original
string object referrer and maps it to the result of the StringFactory.

Bug: 21288130
Change-Id: Ib4db402c178bc37188d5c5faf30b6e4fdc747b17
6650075fb831379d24cfafc3d56442e742418688 08-Apr-2015 Sebastien Hertz <shertz@google.com> JDWP: more GC safety

Ensures GC safety when keeping references that may be moved by GC:
- SingleStepControl: stores ArtMethod* in a GcRoot
- ModBasket: stores references in a StackHandleScope

Bug: 18166750

(cherry picked from commit 261bc044a3575512869586593e99e97cd8b1c321)

Change-Id: I35971a901537956739d1f089d61cb4ea9dc6c93d
261bc044a3575512869586593e99e97cd8b1c321 08-Apr-2015 Sebastien Hertz <shertz@google.com> JDWP: more GC safety

Ensures GC safety when keeping references that may be moved by GC:
- SingleStepControl: stores ArtMethod* in a GcRoot
- ModBasket: stores references in a StackHandleScope

Bug: 18166750
Change-Id: If2b6f9ecff4cf469b50487fd863319fdfa9b9f37
b43390cb87eace4a017f672d66cfb20fb9e76aa1 12-May-2015 Mathieu Chartier <mathieuc@google.com> Hold heap bitmap lock in Heap::GetObjectsAllocated

Fixes a race condition where add and remove space could cause a crash
when we iterated over the spaces.

TODO: Add a spaces lock or something to guard against this.

(cherry picked from commit a395c0a492079d86b312c9edc796d63001576954)

Bug: 21031927

Change-Id: I7f0d558316f8e9d9f22ffd182e8666355bf50d47
a395c0a492079d86b312c9edc796d63001576954 12-May-2015 Mathieu Chartier <mathieuc@google.com> Hold heap bitmap lock in Heap::GetObjectsAllocated

Fixes a race condition where add and remove space could cause a crash
when we iterated over the spaces.

TODO: Add a spaces lock or something to guard against this.

Bug: 21031927

Change-Id: I7f0d558316f8e9d9f22ffd182e8666355bf50d47
8e5bd18fc665d7ec5461ea068e98740a65da754c 06-May-2015 Nicolas Geoffray <ngeoffray@google.com> Add a flag to StackVisitor for inlining.

The flag tells whether the stack walk needs to include inlined
Java frames.

This does not do anything just yet, as we're not inlining anyways.

Change-Id: I716e25094fe56fa335ca1f9a398c1bcdba478e73
5eae455507399286c845ba54796c47087a72b3e2 01-Apr-2015 Sebastien Hertz <shertz@google.com> Support multiple instrumentation clients

Changes Instrumentation::ConfigureStubs to support multiple clients
that need different levels of instrumenation. A client is identified
by a string key used to save the desired instrumentation level.

Also adds regression gtest instrumentation_test and some cleanup.

Bug: 19829329

(cherry picked from commit 0462c4c87c39db6cfcd338f323844738109ac3c9)

Change-Id: I1fc24a86fcb7cb46d4be806895376c25cc0a0b3c
c3cde2c00bcbe97c9b0c119919500fcbbe824baa 10-Apr-2015 Sebastien Hertz <shertz@google.com> JDWP: properly combine location events

This CL properly groups JDWP events at the same location: Breakpoint,
Single-step, Method Entry and Method Exit. This is necessary if the
debugger is not the only instrumentation listener. This matches the
behavior of Dalvik, especially for methods with a single return
instruction.

The interpreter was tuned so the instrumentation callbacks were
called to satisfy the debugger with the idea the debugger was the
only instrumentation listener. This is not true when method tracing
is enabled at the same time.
When tracing is enabled, there is always a listener for MethodEntry
and MethodExit events (art::Trace class). However, if the debugger
is only listening to DexPcMoved event (to manage JDWP Breakpoint
event), it will not be notified of this event.

We now properly call all the instrumentation callbacks in the
interpreter and move the logic specific to debugging into the class
DebugInstrumentationListener. This allows to properly group JDWP
location events together depending on the sequence of instrumentation
callbacks.

We add Thread::tls_32bit_sized_values::debug_method_entry_ flag to
remember we just entered a method. It replaces the local variable
notified_method_entry_event in the interpreter and simplifies the
code.

Bump oat version to force recompilation because the layout of the
Thread class is modified.

Bug: 19829329
Bug: 20205350

(cherry picked from commit 9d6bf69ad3012a9d843268fdd5325b6719b6d5f2)

Change-Id: I204af9112e37d2eebc86661fb7c961a41c74e598
0462c4c87c39db6cfcd338f323844738109ac3c9 01-Apr-2015 Sebastien Hertz <shertz@google.com> Support multiple instrumentation clients

Changes Instrumentation::ConfigureStubs to support multiple clients
that need different levels of instrumenation. A client is identified
by a string key used to save the desired instrumentation level.

Also adds regression gtest instrumentation_test and some cleanup.

Bug: 19829329
Change-Id: I1fc24a86fcb7cb46d4be806895376c25cc0a0b3c
9d6bf69ad3012a9d843268fdd5325b6719b6d5f2 10-Apr-2015 Sebastien Hertz <shertz@google.com> JDWP: properly combine location events

This CL properly groups JDWP events at the same location: Breakpoint,
Single-step, Method Entry and Method Exit. This is necessary if the
debugger is not the only instrumentation listener. This matches the
behavior of Dalvik, especially for methods with a single return
instruction.

The interpreter was tuned so the instrumentation callbacks were
called to satisfy the debugger with the idea the debugger was the
only instrumentation listener. This is not true when method tracing
is enabled at the same time.
When tracing is enabled, there is always a listener for MethodEntry
and MethodExit events (art::Trace class). However, if the debugger
is only listening to DexPcMoved event (to manage JDWP Breakpoint
event), it will not be notified of this event.

We now properly call all the instrumentation callbacks in the
interpreter and move the logic specific to debugging into the class
DebugInstrumentationListener. This allows to properly group JDWP
location events together depending on the sequence of instrumentation
callbacks.

We add Thread::tls_32bit_sized_values::debug_method_entry_ flag to
remember we just entered a method. It replaces the local variable
notified_method_entry_event in the interpreter and simplifies the
code.

Bump oat version to force recompilation because the layout of the
Thread class is modified.

Bug: 19829329
Change-Id: I204af9112e37d2eebc86661fb7c961a41c74e598
848f70a3d73833fc1bf3032a9ff6812e429661d9 15-Jan-2014 Jeff Hao <jeffhao@google.com> Replace String CharArray with internal uint16_t array.

Summary of high level changes:
- Adds compiler inliner support to identify string init methods
- Adds compiler support (quick & optimizing) with new invoke code path
that calls method off the thread pointer
- Adds thread entrypoints for all string init methods
- Adds map to verifier to log when receiver of string init has been
copied to other registers. used by compiler and interpreter

Change-Id: I797b992a8feb566f9ad73060011ab6f51eb7ce01
8a35405e00ad3a722750e37c8eae1c3e1cc0afb0 25-Apr-2015 Christopher Ferris <cferris@google.com> Fix mismatched malloc/free delete/new.

Modify the monitor code to override the delete operator. The problem
is the new operator is overloaded to return a pointer returned by
posix_memalign, but then it's freed with a delete, not a free call.

Also, fix the debugger code to use the [] for a std::unique_ptr to
match how the value is actually allocated.

Both problems found by ASAN.

Bug: 18202869

Change-Id: I2f3a2c02a7f35399b7ba6717b08a035089fab00d
2cebb24bfc3247d3e9be138a3350106737455918 22-Apr-2015 Mathieu Chartier <mathieuc@google.com> Replace NULL with nullptr

Also fixed some lines that were too long, and a few other minor
details.

Change-Id: I6efba5fb6e03eb5d0a300fddb2a75bf8e2f175cb
c785344b87221f5e4e6473e5b762e4e61fe65dcf 27-Mar-2015 Mathieu Chartier <mathieuc@google.com> Move ArtField to native

Add linear alloc. Moved ArtField to be native object. Changed image
writer to put ArtFields after the mirror section.

Savings:
2MB on low ram devices
4MB on normal devices

Total PSS measurements before (normal N5, 95s after shell start):
Image size: 7729152 bytes
23112 kB: .NonMoving
23212 kB: .NonMoving
22868 kB: .NonMoving
23072 kB: .NonMoving
22836 kB: .NonMoving
19618 kB: .Zygote
19850 kB: .Zygote
19623 kB: .Zygote
19924 kB: .Zygote
19612 kB: .Zygote
Avg: 42745.4 kB

After:
Image size: 7462912 bytes
17440 kB: .NonMoving
16776 kB: .NonMoving
16804 kB: .NonMoving
17812 kB: .NonMoving
16820 kB: .NonMoving
18788 kB: .Zygote
18856 kB: .Zygote
19064 kB: .Zygote
18841 kB: .Zygote
18629 kB: .Zygote
3499 kB: .LinearAlloc
3408 kB: .LinearAlloc
3424 kB: .LinearAlloc
3600 kB: .LinearAlloc
3436 kB: .LinearAlloc
Avg: 39439.4 kB

No reflection performance changes.

Bug: 19264997
Bug: 17643507

Change-Id: I10c73a37913332080aeb978c7c94713bdfe4fe1c
692063955ae845d8bd9fa2d22a50a1e06513bdcf 07-Apr-2015 Sebastien Hertz <shertz@google.com> JDWP: fix thread_list deadlock

Limits the scope of Locks::thread_list_lock_ locking in the debugger
so we do not try to lock it twice when creating a JDWP id (because
calling Object::IdentityHashCode may need to take the lock).

Bug: 20048099
Change-Id: I305dd72ccc4d2d007d1603b0d52bcfa94b6842a7
bb87e0f1a52de656bc77cb01cb887e51a0e5198b 03-Apr-2015 Mathieu Chartier <mathieuc@google.com> Refactor and improve GC root handling

Changed GcRoot to use compressed references. Changed root visiting to
use virtual functions instead of function pointers. Changed root visting
interface to be an array of roots instead of a single root at a time.
Added buffered root marking helper to avoid dispatch overhead.

Root marking seems a bit faster on EvaluateAndApplyChanges due to batch
marking. Pause times unaffected.

Mips64 is untested but might work, maybe.

Before:
MarkConcurrentRoots: Sum: 67.678ms 99% C.I. 2us-664.999us Avg: 161.138us Max: 671us

After:
MarkConcurrentRoots: Sum: 54.806ms 99% C.I. 2us-499.986us Avg: 136.333us Max: 602us

Bug: 19264997

Change-Id: I0a71ebb5928f205b9b3f7945b25db6489d5657ca
2c3e77a0b91b2225fcdd3b34d8a734b85eec0579 02-Apr-2015 Sebastien Hertz <shertz@google.com> JDWP: clear exception when allocation fails

Clears pending exception if an allocation (requested by the debugger)
fails and logs an error message about the failure.

Checks we never leave a pending exception after processing a JDWP
request.

Bug: 20037531
Change-Id: I63239034a3c1ab368b0e19c2f5f756d9e2ec6a29
4e5b20863898006ec6c9d120cda167d38dda6e60 24-Mar-2015 Sebastien Hertz <shertz@google.com> Fix JDWP race at runtime shutdown

When the runtime shuts down, it closes the JDWP connection with the
debugger. However, if a JDWP command is still being processed by the
JDWP handler thread when we close the connection, we won't be able to
send its reply.

Bug: 19628620
Change-Id: I20301325a347d66f3b9ef95ebe8f156abafb1f76
daaf3265806eb2eadb2e03302bd68022fab5ca28 24-Mar-2015 Mathieu Chartier <mathieuc@google.com> Add AccessibleObject and Field to mirror

Main motivation is to remove all the functionality / field access on
java side to ArtField. Also comes with some reflection speedups /
slowdowns.

Summary results:
getDeclaredField/getField are slower mostly due to JNI overhead.
However, there is a large speedup in getInt, setInt,
GetInstanceField, and GetStaticField.

Before timings (N5 --compiler-filter=everything):

benchmark ns linear runtime
Class_getDeclaredField 782.86 ===
Class_getField 832.77 ===
Field_getInt 160.17 =
Field_setInt 195.88 =
GetInstanceField 3214.38 ==============
GetStaticField 6809.49 ==============================

After:
Class_getDeclaredField 1068.15 ============
Class_getField 1180.00 ==============
Field_getInt 121.85 =
Field_setInt 139.98 =
GetInstanceField 1986.15 =======================
GetStaticField 2523.63 ==============================

Bug: 19264997

Change-Id: Ic0d0fc1b56b95cd6d60f8e76f19caeaa23045c77
abbabc8acca2231edc5d6e95d523e3fde9a0ba9f 26-Mar-2015 Sebastien Hertz <shertz@google.com> JDWP: more checking for StackFrame commands

Checks thread is suspended and the slot is valid for GetValues and
SetValues command. Also improves error messages when we could not
get or set a local value in the stack or we try to read an invalid
reference from the stack.

Bug: 15680615
Change-Id: I629099fc908e733edb712bd43e141695ed858f4f
d8565456d29f4ad05f11cf84d2d2dac488508e06 26-Mar-2015 Mathieu Chartier <mathieuc@google.com> Fix ClassLinker::MayBeCalledWithDirectCodePointer for JIT

Currently, we don't know if another method has a direct code
pointer or not. This should fix the case where breakpoints
occasionally don't work with JIT.

The JIT now also checks that a method doesn't have any breakpoints
before starting to compile it.

Bug: 17950037

Change-Id: I17cfe874fe4825beba23903a5053d5cb27e106cb
eb07669e9784ccb41d75df180727e57fc4520e28 22-Aug-2014 Daniel Mihalyi <daniel.mihalyi@mattakis.com> JDWP: Optimized single step during debugging

For single stepping full deoptimization and undeoptimizations were
performed with significant overhead, because every code will be
executed in interpreted mode during a single step, even if it is not
strictly required.

For example, if we have a computation heavy method call and we would
like to step over it, that method (and all the methods called from it)
will run in interpreter mode. This can take so long in some cases
(e.g. multiple minutes) that it makes debugging process unusable.

The solution for this limitation is not using full deoptimizations for
single steps and force interpreter only for those methods that we are
about to step into, and require stack deoptimization before step outs.

Bug: 17750566
Bug: 18094282
Bug: https://code.google.com/p/android/issues/detail?id=77984

Change-Id: I683c52465883146c4c84ec47bf96f8efd920527f
Signed-off-by: Daniel Mihalyi <daniel.mihalyi@mattakis.com>
bf9fc581e8870faddbd320a935f9a627da724c48 14-Mar-2015 Mathieu Chartier <mathieuc@google.com> Add more info to who called SuspendAll

Helps diagnose related jank.

Change-Id: I38191cdda723c6f0355d0197c494a3dff2b6653c
0aa50ce2fb75bfc2e815a0c33adf9b049561923b 10-Mar-2015 Nicolas Geoffray <ngeoffray@google.com> Remove ThrowLocation.

Note that this is a cleanup change, and has no functionality change.
The ThrowLocation had no use anymore.

Change-Id: I3d2126af1dc673cec3a0453ff3d56a172663a5f6
1558b577907b613864e98f05862543557263e864 25-Feb-2015 Sebastien Hertz <shertz@google.com> JDWP: allocate DebugInvokeReq only when requested

Only allocates thread-local DebugInvokeReq when the debugger requests
a thread to invoke a method. The JDWP thread allocates that structure
then attaches it to the target thread. When the thread is resumed, it
executes the method. Once the invocation completes, the thread
detaches the DebugInvokeReq, signals the JDWP thread then suspends.
Finally, the JDWP thread wakes up, prepares the reply with the invoke
result (or exception) and deallocates the DebugInvokeReq.

Also ensures GC safety for object returned by the invoke. We add the
object to the JDWP object registry right after the invoke. We now
reference that object with a JDWP ObjectID instead of an Object* in
the DebugInvokeReq struct. This prevent from accessing a stale
reference if the GC runs and moves the Object*.

This CL includes the following changes:
- Move former DebugInvokeReq::ready flag to
Thread::tls_32bit_sized_values::ready_for_debug_invoke. It's needed
to know whether a thread has been suspended by an event, thus ready
to invoke a method from the debugger.
- Remove DebugInvokeReq::invoke_needed: we now test if we attached a
DebugInvokeReq* to the thread.
- Rename misleading FinishMethod function to RequestMethod.

Bug: 19142632
Bug: 18166750
Change-Id: I351fb4eb94bfe69fcafb544d21d55ff35a033000
14691c5e786e8c2c5734f687e4c96217340771be 05-Mar-2015 Nicolas Geoffray <ngeoffray@google.com> Compute the right catch location for the debugger.

Also remove tls ThrowLocation, it is not needed anymore.

Change-Id: I78fddf09ce968ca475e39c17fa76d699c589c8d9
7642cfc90fc9c3ebfd8e3b5041915705c93b5cf0 26-Feb-2015 Nicolas Geoffray <ngeoffray@google.com> Change how we report exceptions to the debugger.

This is only a refactoring/cleanup. Bug fixes with respect
to catch location, and more cleanups will follow.

Change-Id: I30d3c6260b0c8f8115a811621397225b88f2063a
e5f13e57ff8fa36342beb33830b3ec5942a61cca 24-Feb-2015 Mathieu Chartier <mathieuc@google.com> Revert "Revert "Add JIT""

Added missing EntryPointToCodePointer.

This reverts commit a5ca888d715cd0c6c421313211caa1928be3e399.

Change-Id: Ia74df0ef3a7babbdcb0466fd24da28e304e3f5af
a5ca888d715cd0c6c421313211caa1928be3e399 24-Feb-2015 Nicolas Geoffray <ngeoffray@google.com> Revert "Add JIT"

Sorry, run-test crashes on target:
0-05 12:15:51.633 I/DEBUG (27995): Abort message: 'art/runtime/mirror/art_method.cc:349] Check failed: PcIsWithinQuickCode(reinterpret_cast<uintptr_t>(code), pc) java.lang.Throwable java.lang.Throwable.fillInStackTrace() pc=71e3366b code=0x71e3362d size=ad000000'
10-05 12:15:51.633 I/DEBUG (27995): r0 00000000 r1 0000542b r2 00000006 r3 00000000
10-05 12:15:51.633 I/DEBUG (27995): r4 00000006 r5 b6f9addc r6 00000002 r7 0000010c
10-05 12:15:51.633 I/DEBUG (27995): r8 b63fe1e8 r9 be8e1418 sl b6427400 fp b63fcce0
10-05 12:15:51.633 I/DEBUG (27995): ip 0000542b sp be8e1358 lr b6e9a27b pc b6e9c280 cpsr 40070010
10-05 12:15:51.633 I/DEBUG (27995):

Bug: 17950037
This reverts commit 2535abe7d1fcdd0e6aca782b1f1932a703ed50a4.

Change-Id: I6f88849bc6f2befed0c0aaa0b7b2a08c967a83c3
2535abe7d1fcdd0e6aca782b1f1932a703ed50a4 17-Feb-2015 Mathieu Chartier <mathieuc@google.com> Add JIT

Currently disabled by default unless -Xjit is passed in.

The proposed JIT is a method JIT which works by utilizing interpreter
instrumentation to request compilation of hot methods async during
runtime.

JIT options:
-Xjit / -Xnojit
-Xjitcodecachesize:N
-Xjitthreshold:integervalue

The JIT has a shared copy of a compiler driver which is accessed
by worker threads to compile individual methods.

Added JIT code cache and data cache, currently sized at 2 MB
capacity by default. Most apps will only fill a small fraction of
this cache however.

Added support to the compiler for compiling interpreter quickened
byte codes.

Added test target ART_TEST_JIT=TRUE and --jit for run-test.

TODO:
Clean up code cache.
Delete compiled methods after they are added to code cache.
Add more optimizations related to runtime checks e.g. direct pointers
for invokes.
Add method recompilation.
Move instrumentation to DexFile to improve performance and reduce
memory usage.

Bug: 17950037

Change-Id: Ifa5b2684a2d5059ec5a5210733900aafa3c51bca
b3b173bbbd1d1cbad555de13c3fa6765f5078bce 06-Feb-2015 Sebastien Hertz <shertz@google.com> Follow up 129144

Passes JDWP options to debugger on runtime init so we no longer need
to keep them on the heap.

Updates ParseJdwpOption to return Result for consistency.

Bug: 19275792
Change-Id: I68b7e58908164d3e4cf9e3fbcc3dfab6ce0579a5
2bf93f48bbb417b358c9e3c77911ea6ec7307c15 09-Jan-2015 Sebastien Hertz <shertz@google.com> JDWP: update thread synchronization

This CL ensures only one thread can do JDWP stuff at a time: either
processing a command coming from the debugger (JDWP thread) or
sending an event (breakpoint, class prepare, etc) to the debugger
before suspending.

The JDWP thread now uses AcquireJdwpTokenForCommand and
ReleaseJdwpTokenForCommand, respectively acquiring and releasing the
token used for synchronization. On the other hand, the event threads
now use AcquireJdwpTokenForEvent and ReleaseJdwpTokenForEvent.

During an invoke, the target thread needs to take the JDWP token to
execute the method while it's already held by the JDWP handler thread
waiting for the invocation to complete. To avoid both threads from
waiting for each other (deadlock), the JDWP thread releases the token
and acquires it again after the invocation is complete, so the target
thread can run safely and prevents other threads from sending events.

Bug: 19120467
Change-Id: Ie3208fb940a60573769d494128cf22f0fa30fa61
3be6e9d904baa13d7cf51dfc6742dea12e766b2e 05-Feb-2015 Sebastien Hertz <shertz@google.com> Read JDWP options from runtime

Allocates JDWP::JdwpOptions on the heap and copies parsed options to
avoid the need to include jdwp/jdwp.h into runtime.h file.

Also does some minor cleanup and removes the old JDWP options parsing
code that became dead code after we move it to the new command-line
parser.

Bug: 19275792
Change-Id: I71901c89fbf2cc3c1901a089e2a98b4326c6ee70
f26e1b355333cbb5b064da3b4bbf2dc450a5eb40 29-Jan-2015 Mathieu Chartier <mathieuc@google.com> Check for null class of class

Experimental fix.

Bug: 19193521

(cherry picked from commit 65370e37b3fd9e53e3c1bce5757912e8309cd305)

Change-Id: If59fe9a7bd16f3578ed036a5dbb2787862b33766
65370e37b3fd9e53e3c1bce5757912e8309cd305 29-Jan-2015 Mathieu Chartier <mathieuc@google.com> Check for null class of class

Experimental fix.

Bug: 19193521
Change-Id: I11571dd5a63852acdbad5d4291510542c2e4b18a
597c4f0aeafed2b6fa69e53ece4be4f53115d707 26-Jan-2015 Sebastien Hertz <shertz@google.com> JDWP: allocate single step control only when active

Only allocates SingleStepControl when a single step is requested in
a thread.

Bug: 19142632
Change-Id: I830b7eaea86b516d3fac80ce14d41c66b4bd5415
2cd334ae2d4287216523882f0d298cf3901b7ab1 09-Jan-2015 Hiroshi Yamauchi <yamauchi@google.com> More of the concurrent copying collector.

Bug: 12687968
Change-Id: I62f70274d47df6d6cab714df95c518b750ce3105
4c4d609a3f1d67c76c855df13c2c1be9c315a6c9 23-Jan-2015 Mathieu Chartier <mathieuc@google.com> Fix compaction bugs related to IdentityHashCode

IdentityHashCode is a suspend point if monitor inflation occurs.

Change-Id: I114021aed8b3f3437109ef622298de05e13b4e34
0c8c303c20cdaaf54d26e45cc17dc5afb820d8ef 17-Jan-2015 Hiroshi Yamauchi <yamauchi@google.com> Clean up the locks around Heap::VisitObjects().

This is so that we could support suspending all threads when visiting
objects in the presence of a concurrent, moving collector.

Bug: 12687968
Change-Id: Icc8e60630465afde948ebc6ea91d4ebaff5d7837
7f418db815f0eaef5b2f43e1f06fb8773a415494 26-Nov-2014 Sebastien Hertz <shertz@google.com> JDWP: fix breakpoint for method in the image

When we set a breakpoint in a compiled method, we deoptimize it by
changing its entrypoint so it is executed with the interpreter.
However, methods in the image can be called with their direct code
pointer, ignoring the updated entrypoint. In that case, the method
is not executed with the interpreter and we miss the breakpoint.

This CL avoids that situation by forcing a full deoptimization so
everything runs with the interpreter. However, if the image has been
compiled in PIC mode, we keep using selective deoptimization because
direct code pointer is not used in this mode.

Bug: 17965285

(cherry picked from commit 6963e44331258b131bcc0599b868ba15902d6d22)

Change-Id: I9bf738f89b9eb6d18733503216b376b8a1d181f5
e34fa1df67fbe0173b4ea9abddcc3ae3d0537037 14-Jan-2015 Mathieu Chartier <mathieuc@google.com> Print more info in MarkSweep::VerifyRoot

Refactored old root callback to use a new class called RootInfo.
RootInfo contains all the relevant info related to the root
associated with the callback. The MarkSweep::VerifyRoot function
now uses this info to print the StackVisitor's described location
if the GC root is of the type kRootJavaFrame.

Some other cleanup.

Example output:
E/art (12167): Tried to mark 0x123 not contained by any spaces
E/art (12167): Attempting see if it's a bad root
E/art (12167): Found invalid root: 0x123 with type RootJavaFrame
E/art (12167): Location=Visiting method
'void java.lang.Runtime.gc()' at dex PC 0xffffffff (native PC 0x0)
vreg=0

(cherry picked from commit 12f7423a2bb4bfab76700d84eb6d4338d211983a)

Bug: 18588862
Change-Id: Ic5a2781f704e931265ffb3621c2eab4b2e25f60f
12f7423a2bb4bfab76700d84eb6d4338d211983a 14-Jan-2015 Mathieu Chartier <mathieuc@google.com> Print more info in MarkSweep::VerifyRoot

Refactored old root callback to use a new class called RootInfo.
RootInfo contains all the relevant info related to the root
associated with the callback. The MarkSweep::VerifyRoot function
now uses this info to print the StackVisitor's described location
if the GC root is of the type kRootJavaFrame.

Some other cleanup.

Example output:
E/art (12167): Tried to mark 0x123 not contained by any spaces
E/art (12167): Attempting see if it's a bad root
E/art (12167): Found invalid root: 0x123 with type RootJavaFrame
E/art (12167): Location=Visiting method
'void java.lang.Runtime.gc()' at dex PC 0xffffffff (native PC 0x0)
vreg=0

Bug: 18588862
Change-Id: Ic5a2781f704e931265ffb3621c2eab4b2e25f60f
55f6534f260ec82ef2d69a0667b1883f13d11399 13-Jan-2015 Sebastien Hertz <shertz@google.com> JDWP: fix deadlock with GC

This CL fixes a deadlock where JDWP thread and running GC thread are
waiting for each other. Here is the sequence of the deadlock:
1. GC thread disables access to weak global references, then releases
mutator lock.
2. JDWP thread takes mutator lock exclusively after suspending all
threads.
3. GC thread waits for shared mutator lock which is held by JDWP
thread.
4. JDWP thread clears weak global references but need to wait for GC
thread to re-enable access to them.

To avoid that situation, we ensure the JDWP thread does not attempt
to delete weak global references while holding the mutator
exclusively so GC thread is not blocked.

Bug: 18995321
Change-Id: Ia7e82f463c27ffdcfd730c3117337a6a33d111e7
ad466adf38db74a9840659626858196091151a64 09-Jan-2015 Mathieu Chartier <mathieuc@google.com> Change hprof to use streaming

Previously, we compute the whole hprof dump in memory resulting in
> 50MB of memory usage for some apps (such as maps). This could
cause the app to get killed by the low memory killer.

The solution works by doing the dump in 2 passes.
The first pass calculates the size of the dump.
The second pass starts by sending the DDMS header with the correct
size, then does the rest of the hprof dump by streaming and sending
data one HprofRecord at a time.

Bug: 18921793
Change-Id: I7dd9f5cfe49799ba268095c994a8c2eb1fe493df
4306ef8a7ec8e3887e51f64e80d940d974cc3ac3 20-Dec-2014 Mathieu Chartier <mathieuc@google.com> Don't allow suspension from FindLocksAtDexPc

Transitioning to suspended from runnable sometimes runs dump
checkpoints in ThreadStress which can cause deadlocks. This happens
since FindLocksAtDexPC runs the verifier which calls
AllowThreadSuspension. This results in a blocked thread which holds
the monitor lock, and if another thread tries to do a monitor enter,
it deadlocks while holding the mutator lock (assuming the GC is
suspending all).

The fix for avoiding this deadlock is not calling
AllowThreadSuspension from FindLocksAtDexPc.

Bug: 18576985
Change-Id: I7e5faaf3bbbd5b5f680de95d53c33b5106705b0c
2f5c202624f733d97fecdd4e31915199e0c77707 17-Dec-2014 Sebastien Hertz <shertz@google.com> JDWP: fix setting multiple breakpoints in the same method

When setting multiple breakpoints in the same method, we were
incorrectly setting the deoptimization kind of all the breakpoints
set after a first breakpoint. This resulted in incorrect
deoptimization/undeoptimization and even an abort. This was caught
by running the debugger with sanity checks enabled with libartd.so.

We now set next breakpoints with the deoptimization kind of the first
existing breakpoint (if any) so we trigger right [un]deoptimization
when adding or removing a breakpoint.

Bug: 18782753
Bug: 18651686

(cherry picked from commit abe93e0098a2648fa286cfea01954737e32c7be9)

Change-Id: I95424e361dc04df0adb54b5afac5b4da2b8b2731
abe93e0098a2648fa286cfea01954737e32c7be9 17-Dec-2014 Sebastien Hertz <shertz@google.com> JDWP: fix setting multiple breakpoints in the same method

When setting multiple breakpoints in the same method, we were
incorrectly setting the deoptimization kind of all the breakpoints
set after a first breakpoint. This resulted in incorrect
deoptimization/undeoptimization and even an abort. This was caught
by running the debugger with sanity checks enabled with libartd.so.

We now set next breakpoints with the deoptimization kind of the first
existing breakpoint (if any) so we trigger right [un]deoptimization
when adding or removing a breakpoint.

Bug: 18782753
Bug: 18651686
Change-Id: Idf36ede73302fba83a154052bef701bedc8bc726
7d95565c84d91ae5dcec4b89728ada208633de0c 22-Oct-2014 Sebastien Hertz <shertz@google.com> Cleanup JDWP event matching

* Use std::vector for the event match list.
* Make event reporting methods void since result is never used.
* Use nullptr keyword instead of NULL.

Change-Id: Icd6f47e46cefc2cc63325df00037cd4b6a475259
bc689b7cefce2dd357abf25b82e5fcd690e27706 15-Dec-2014 Mathieu Chartier <mathieuc@google.com> Clean up debugger

Separated logic for native vs java heap, cleaned up lock annotations.
Added missing end of space marker for bump pointer spaces.

Bug: 18730149

Change-Id: I5bc21f0cee83b9cfa357e8a59658885c12cae09c
7522c741d9660a56da2dd6a8e20b8cdf01a6c333 08-Dec-2014 Pavel Vyssotski <pavel.n.vyssotski@intel.com> ART: Fix DDM client hang transmitting native heap dump with MALLOC_IMPL=dlmalloc

VM acting as a DDM client hangs transmitting native heap segment data when dlmalloc
is used instead of default jemalloc. dlmalloc_inspect_all disallow any memory allocation
inside heap callback. So cannot send any data walking the heap, the same for logging.
Callback function also needs to acquire the heap bitmap lock. Finally, need to indicate
end of a space to flush data.

Change-Id: I9541962268dd58c2a4237fe1550c9e153252ab4a
Signed-off-by: Pavel Vyssotski <pavel.n.vyssotski@intel.com>
6963e44331258b131bcc0599b868ba15902d6d22 26-Nov-2014 Sebastien Hertz <shertz@google.com> JDWP: fix breakpoint for method in the image

When we set a breakpoint in a compiled method, we deoptimize it by
changing its entrypoint so it is executed with the interpreter.
However, methods in the image can be called with their direct code
pointer, ignoring the updated entrypoint. In that case, the method
is not executed with the interpreter and we miss the breakpoint.

This CL avoids that situation by forcing a full deoptimization so
everything runs with the interpreter. However, if the image has been
compiled in PIC mode, we keep using selective deoptimization because
direct code pointer is not used in this mode.

Bug: 17965285
Change-Id: Icaf8cbb7fe9ad01d36f7378c59d50d9ce42ae57f
a0485607a4a4d8c683a9849f6f20902c4e1da7a4 03-Dec-2014 Ian Rogers <irogers@google.com> Move GetClassFromTypeIdx to ArtMethod.

Move GetClassFromTypeIdx out of MethodHelper into ArtMethod in
preparation for the removal of MethodHelper.

Change-Id: I9c03dd8c821944c606ea08cdf92afc80c4275247
08f1f50d6c2e8f247b8f5f19711d75a792851c7a 03-Dec-2014 Ian Rogers <irogers@google.com> Remove FieldHelper.

Change-Id: I2d74e2d5b3c35a691c95339de0db9361847fca11
f2134f684923454e00c8ca7675b431a8538131bc 17-Nov-2014 Sebastien Hertz <shertz@google.com> JDWP: only deoptimize when it is required

We don't need to deoptimize anything when we forced the use of the
interpreter (-Xint). In this case, no compiled code is executed
(except native methods which are not concerned by deoptimization).
Therefore we even don't need to enable/disable deoptimization support
in instrumentation.

We also don't need to deoptimize a method that hasn't been compiled.
Since it will run with interpreter, there is no point deoptimizing
it. However this method may be inlined in a compiled caller method
so we still need to deoptimize everything in this case.

This CL updates breakpoint support by storing the required kind of
deoptimization for a particular method. There are 3 cases:
- kNothing: the method does not require deoptimization.
- kSelectiveDeoptimization: the method needs to be deoptimized.
- kFullDeoptimization: we must deoptimize everythinig.
When uninstalling a breakpoint, we need to do the reverse operation.

Also fixes the SanityCheckExistingBreakpoints function to control
breakpoints related to the given method only and adds extra verbose
ilogs when choosing the appropriate deoptimization kind.

Includes a partial cherry-pick of commit
87553c9fa1298ffb40127b2bb6413859fd3f79df to use method
ClassLinker::GetOatMethodQuickCodeFor.

Bug: 18407046

(cherry picked from commit f3928794a10516e2ac0ffe2686a10891788d4b9c)

Change-Id: I50853cc5fc5c52650485785a1198d35ea0f7fb8e
ae214ee0064525e8e4a2e5f61b6d0b8f4f1900e8 25-Nov-2014 Andreas Gampe <agampe@google.com> ART: Fix inline dependency

GetClassFromTypeIdx is defined in the -inl file.

Change-Id: Ib5dbcea08dccee43ff70cac2e45cdbf210cb490c
f3928794a10516e2ac0ffe2686a10891788d4b9c 17-Nov-2014 Sebastien Hertz <shertz@google.com> JDWP: only deoptimize when it is required

We don't need to deoptimize anything when we forced the use of the
interpreter (-Xint). In this case, no compiled code is executed
(except native methods which are not concerned by deoptimization).
Therefore we even don't need to enable/disable deoptimization support
in instrumentation.

We also don't need to deoptimize a method that hasn't been compiled.
Since it will run with interpreter, there is no point deoptimizing
it. However this method may be inlined in a compiled caller method
so we still need to deoptimize everything in this case.

This CL updates breakpoint support by storing the required kind of
deoptimization for a particular method. There are 3 cases:
- kNothing: the method does not require deoptimization.
- kSelectiveDeoptimization: the method needs to be deoptimized.
- kFullDeoptimization: we must deoptimize everythinig.
When uninstalling a breakpoint, we need to do the reverse operation.

Also fixes the SanityCheckExistingBreakpoints function to control
breakpoints related to the given method only and adds extra verbose
logs when choosing the appropriate deoptimization kind.

Bug: 18407046
Change-Id: I5212c1fd2f72e06c79e7871db15696824d37dc0b
4ad5cd3e7d519484559ef778d96fb3f0be8919fa 12-Nov-2014 Ian Rogers <irogers@google.com> Modify the behavior of thread suspend shootouts.

The thread doing the suspension doesn't attempt to suspend the other thread
unless it knows another thread isn't trying to suspend it. Use the suspend
count, and its lock, for this purpose.
Re-enable ThreadStress test.
Bug: 15446488

Change-Id: Idd34410c7b89d8abd6973e5699a15ca699472c78
277ccbd200ea43590dfc06a93ae184a765327ad0 04-Nov-2014 Andreas Gampe <agampe@google.com> ART: More warnings

Enable -Wno-conversion-null, -Wredundant-decls and -Wshadow in general,
and -Wunused-but-set-parameter for GCC builds.

Change-Id: I81bbdd762213444673c65d85edae594a523836e5
6a3c1fcb4ba42ad4d5d142c17a3712a6ddd3866f 31-Oct-2014 Ian Rogers <irogers@google.com> Remove -Wno-unused-parameter and -Wno-sign-promo from base cflags.

Fix associated errors about unused paramenters and implict sign conversions.
For sign conversion this was largely in the area of enums, so add ostream
operators for the effected enums and fix tools/generate-operator-out.py.
Tidy arena allocation code and arena allocated data types, rather than fixing
new and delete operators.
Remove dead code.

Change-Id: I5b433e722d2f75baacfacae4d32aef4a828bfe1b
872dd8208f00c667af8d9e0fd07fdd0ada56d437 30-Oct-2014 Ian Rogers <irogers@google.com> Tidy and reduce ART library dependencies on the host.

Move to shared rather than static libraries. Avoids capture of all static
libraries library dependencies.

Change-Id: I2be96e92dad4ed1842d76b044745f2a2e15372eb
4eec026ec4d86869baa27ad0afd9564cca8856c9 14-Oct-2014 Sebastien Hertz <shertz@google.com> Fix JDWP Virtualmachine.Resume command

We used to call ThreadList::UndoDebuggerSuspensions but this is not
correct. Indeed Virtualmachine.Resume command should be performed
as many times as all threads have been suspended (either by the
Virtualmachine.Suspend command or the application of suspend policy
ALL for event).

This CL fixes this issue by adding ThreadList::ResumeAllForDebugger.
It decrements suspend count and debug suspend count by 1 (globally
and for each thread).

It also handles the case where Virtualmachine.Resume is called while
threads have not been suspended (global debug suspend count is 0). In
this case we just print a warning and do nothing.

Bug: 17974047

(cherry picked from commit 253fa555d9424a56c52879449eabe73d5c96cf61)

Change-Id: I38b38240f84f141670506e88fa5c2480f856fdd6
e49e195c4bc2f20df0289c0bbb46f56839308dde 13-Oct-2014 Sebastien Hertz <shertz@google.com> More use of WellKnownClasses for debugger

Uses WellKnownClasses cached fields for ThreadGroupReference-related
JDWP commands.
Adds fields of java.lang.ThreadGroup and java.util.ArrayList used by
the debugger.

Change-Id: I54f7ef7e44cb61bec95657a69177bba1fbb7dc75
cf7f19135f0e273f7b0136315633c2abfc715343 23-Oct-2014 Ian Rogers <irogers@google.com> C++11 related clean-up of DISALLOW_..

Move DISALLOW_COPY_AND_ASSIGN to delete functions. By no having declarations
with no definitions this prompts better warning messages so deal with these
by correcting the code.
Add a DISALLOW_ALLOCATION and use for ValueObject and mirror::Object.
Make X86 assembly operand types ValueObjects to fix compilation errors.
Tidy the use of iostream and ostream.
Avoid making cutils a dependency via mutex-inl.h for tests that link against
libart. Push tracing dependencies into appropriate files and mutex.cc.
x86 32-bit host symbols size is increased for libarttest, avoid copying this
in run-test 115 by using symlinks and remove this test's higher than normal
ulimit.
Fix the RunningOnValgrind test in RosAllocSpace to not use GetHeap as it
returns NULL when the heap is under construction by Runtime.

Change-Id: Ia246f7ac0c11f73072b30d70566a196e9b78472b
253fa555d9424a56c52879449eabe73d5c96cf61 14-Oct-2014 Sebastien Hertz <shertz@google.com> Fix JDWP Virtualmachine.Resume command

We used to call ThreadList::UndoDebuggerSuspensions but this is not
correct. Indeed Virtualmachine.Resume command should be performed
as many times as all threads have been suspended (either by the
Virtualmachine.Suspend command or the application of suspend policy
ALL for event).

This CL fixes this issue by adding ThreadList::ResumeAllForDebugger.
It decrements suspend count and debug suspend count by 1 (globally
and for each thread).

It also handles the case where Virtualmachine.Resume is called while
threads have not been suspended (global debug suspend count is 0). In
this case we just print a warning and do nothing.

Bug: 17974047
Change-Id: I25af22b1936760292d2a8c286e0867f2ae864108
677cd61ad05d993c4d3b22656675874f06d6aabc 15-Oct-2014 Ian Rogers <irogers@google.com> Make ART compile with GCC -O0 again.

Tidy up InstructionSetFeatures so that it has a type hierarchy dependent on
architecture.
Add to instruction_set_test to warn when InstructionSetFeatures don't agree
with ones from system properties, AT_HWCAP and /proc/cpuinfo.
Clean-up class linker entry point logic to not return entry points but to
test whether the passed code is the particular entrypoint. This works around
image trampolines that replicate entrypoints.
Bug: 17993736

(cherry picked from commit 6f3dbbadf4ce66982eb3d400e0a74cb73eb034f3)

Change-Id: I3e7595f437db4828072589d475a5453b7f31003e
6f3dbbadf4ce66982eb3d400e0a74cb73eb034f3 15-Oct-2014 Ian Rogers <irogers@google.com> Make ART compile with GCC -O0 again.

Tidy up InstructionSetFeatures so that it has a type hierarchy dependent on
architecture.
Add to instruction_set_test to warn when InstructionSetFeatures don't agree
with ones from system properties, AT_HWCAP and /proc/cpuinfo.
Clean-up class linker entry point logic to not return entry points but to
test whether the passed code is the particular entrypoint. This works around
image trampolines that replicate entrypoints.
Bug: 17993736

Change-Id: I5f4b49e88c3b02a79f9bee04f83395146ed7be23
5d1c1bbd4c8a1727027d0ae69277af6f6f6badf3 15-Sep-2014 Sebastien Hertz <shertz@google.com> Check for errors in ThreadGroupReference JDWP commands

Returns INVALID_OBJECT error for null or invalid object. Also returns
INVALID_THREAD_GROUP error when the object is not a java.lang.ThreadGroup.

Removes unused Dbg::GetMainThreadGroupId method.

Bug: 17503230
(cherry picked from commit a06430c76981d545b5f2b64a7ef53c44c030cf73)

Change-Id: Ic39d3d2c45bf288fc22d908a3c90a3ca24f1c4d4
4c69d7f4df78d20c631abc5f70b811a9944854d3 10-Oct-2014 Mathieu Chartier <mathieuc@google.com> Hold mutator lock in DdmSendHeapSegments for all spaces

Previously we were releasing the mutator lock in DdmSendHeapSegments
and only reacquiring it for RosAlloc spaces. This was causing problems
since the HeapChunkCallback access object fields through mirror.

Bug: 17950534

(cherry picked from commit d6527cf8e824d9057f32755f2ff4bdcf46c7095b)

Change-Id: Idb307fd4c01450a07e3c9621e04d2aabf2c6a0b9
d6527cf8e824d9057f32755f2ff4bdcf46c7095b 10-Oct-2014 Mathieu Chartier <mathieuc@google.com> Hold mutator lock in DdmSendHeapSegments for all spaces

Previously we were releasing the mutator lock in DdmSendHeapSegments
and only reacquiring it for RosAlloc spaces. This was causing problems
since the HeapChunkCallback access object fields through mirror.

Bug: 17950534
Change-Id: I6bd71f43e84eae8585993da656bf1577095607a9
5797aef3bbfa6fc762d384e25b31f6a121664987 01-Sep-2014 Sebastien Hertz <shertz@google.com> Optimize JDWP stack local values access

The StackFrame.GetValues and StackFrame.SetValues JDWP commands can refer to
multiple variables at the same time in a given frame. However we used to walk
the stack until getting to the requested frame for each variable.

Now, we walk the stack only once until getting to the frame so the context is
initialized. Then we read/write value for each variable from this context.

Bug: 17343501
Bug: 15680615
(cherry picked from commit 8009f39c6d63181a6cd0e348ce732997dbdf3d20)

Change-Id: I70f64b25e4b20860f5446b8c540345d5e71ec4a9
fc787ecd91127b2c8458afd94e5148e2ae51a1f5 10-Oct-2014 Ian Rogers <irogers@google.com> Enable -Wimplicit-fallthrough.

Falling through switch cases on a clang build must now annotate the fallthrough
with the FALLTHROUGH_INTENDED macro.
Bug: 17731372

Change-Id: I836451cd5f96b01d1ababdbf9eef677fe8fa8324
9ef78b59da51080882e47505896b420977fd79ae 26-Sep-2014 Mathieu Chartier <mathieuc@google.com> Fix broken runtime SetStatsEnabled logic

Previously, Runtime::SetStatsEnabled wouldn't take stats_enabled_
into account when deciding whether or not to increment / decrement
teh stats enabled counter. This resulted in counter underflows and
other errors which caused some CTS tests to fail.

Also added some locking to prevent race conditions.

Bug: 17360878

(cherry picked from commit a98ffd745bbecb2e84a492194950c0b94966546b)

Change-Id: I21d241a58d35bd6a607aa2305c6da81720bd0886
a98ffd745bbecb2e84a492194950c0b94966546b 26-Sep-2014 Mathieu Chartier <mathieuc@google.com> Fix broken runtime SetStatsEnabled logic

Previously, Runtime::SetStatsEnabled wouldn't take stats_enabled_
into account when deciding whether or not to increment / decrement
teh stats enabled counter. This resulted in counter underflows and
other errors which caused some CTS tests to fail.

Also added some locking to prevent race conditions.

Bug: 17360878

Change-Id: I779237d55dda4f35054a4d27fb2c660a38750fc0
f0edfc355893d53d1104b05501c99ad5ccf305c4 25-Sep-2014 Hiroshi Yamauchi <yamauchi@google.com> Some optimizations for the array alloc path.

- Force Array::Alloc() to be inlined.
- Simplify the array size overflow check.
- Turn fill_usable into a template parameter.
- Remove a branch in Array::DataOffset() and avoid
Primitive::ComponentSize(), which has a switch, in the array alloc
path.
- Strength reductions in the array size computation by using component
size shifts instead of component sizes. Store component size shift
in the upper 16 bits of primitive_type field.
- Speedup: ~4% (3435->3284) in MemAllocTest on N4.

Bug: 9986565

Change-Id: I4b142ffac4ab8b5b915836f1660a949d6442344c
4d6e48392771467b9e37fdeb32479ca29bf9c691 18-Sep-2014 Sebastien Hertz <shertz@google.com> Do not hold breakpoint lock when running the verifier

When setting a breakpoint, we need to know whether the method may be
inlined. We run the method verifier but that may cause thread
suspension. Therefore we must not hold any lock at this time. The
issue is we do hold the breakpoint lock so we fails a check in debug
mode.

This CL ensures we don't hold the breakpoint lock when running the
method verifier to detect inlining.

Bug: 17562442
(cherry picked from commit 4d1e9ab57e4c822e8e678b1d0c1d6ad2abfa9b3e)

Change-Id: I6daae91e3e82f41006f29959a5c6c0ec0a88194e
8009f39c6d63181a6cd0e348ce732997dbdf3d20 01-Sep-2014 Sebastien Hertz <shertz@google.com> Optimize JDWP stack local values access

The StackFrame.GetValues and StackFrame.SetValues JDWP commands can refer to
multiple variables at the same time in a given frame. However we used to walk
the stack until getting to the requested frame for each variable.

Now, we walk the stack only once until getting to the frame so the context is
initialized. Then we read/write value for each variable from this context.

Bug: 17343501
Bug: 15680615

Change-Id: I2a4128f29a3c5856b994e280037c0a09eb48c5c8
a9aa0ffc2cf917be05749d1b27e7994249edb6d2 19-Sep-2014 Sebastien Hertz <shertz@google.com> Fix JDWP crash when reporting exception

The exception's throw location may be null so we need to handle that
case. Also fixes a memset issue.

Bug: 17571297
(cherry picked from commit bbb63897d7f2d99219cb50721fe530521e08ddff)

Change-Id: Iedebb58f9460c5f04913c269200e51161bda1ba9
4d1e9ab57e4c822e8e678b1d0c1d6ad2abfa9b3e 18-Sep-2014 Sebastien Hertz <shertz@google.com> Do not hold breakpoint lock when running the verifier

When setting a breakpoint, we need to know whether the method may be
inlined. We run the method verifier but that may cause thread
suspension. Therefore we must not hold any lock at this time. The
issue is we do hold the breakpoint lock so we fails a check in debug
mode.

This CL ensures we don't hold the breakpoint lock when running the
method verifier to detect inlining.

Bug: 17562442
Change-Id: Ia6b128fc8917ce00025b68ae4ac62fb2a1f154e6
2d5f39ed5aeaeb7ca22b07b4c6e8c56348ef8893 20-Sep-2014 Mathieu Chartier <mathieuc@google.com> Add ScopedAssertNoThreadSuspension

Added a new class, ScopedAssertNoThreadSuspension.
Deleted some unnecessary ScopedAssertNoThreadSuspension since
VisitObjects already has a ScopedAssertNoThreadSuspension.

Change-Id: I29ec0006120c39a27184d30e2d1d0c179e203776
bbb63897d7f2d99219cb50721fe530521e08ddff 19-Sep-2014 Sebastien Hertz <shertz@google.com> Fix JDWP crash when reporting exception

The exception's throw location may be null so we need to handle that
case. Also fixes a memset issue.

Bug: 17571297
Change-Id: I954b67207b1ba99a8f3240ce936579dc5644cc69
6995c60cd6657c10811055c42661a55b10b47cef 09-Sep-2014 Sebastien Hertz <shertz@google.com> Update JDWP event filtering to avoid useless ids

To reduce the number of JDWP ids in the debugger, we update the event filtering
support to work with runtime objects (Thread, Class, Object, ...) instead of
JDWP ids (ThreadId, RefTypeId, ObjectId, ...).

We used to create useless JDWP ids for events even if they were not reported
because of event filtering (thread only, class only, instance only, ...). Now
we only create JDWP ids when we know we're going to report an event.

Bug: 17343664
(cherry picked from commit d539167b7f11136fe570a77aff2ee4935842007a)

Change-Id: I8619e219733fc2fa3569f473b7bd8d9af4181f2b
69dbec6d9d55eeb2867949c2791d01dc9aa916c8 16-Sep-2014 Jeff Hao <jeffhao@google.com> Avoid suspending for alloc trace enabling when already suspended.

Bug: 17499772

(cherry picked from commit 1d6ee090fddd4bfd35c304d6ceb929d5c529dfcc)

Change-Id: Id09809c476c685f0a197ee75bb08638931364efd
b0b0b496125c16620e99ea4e4a05693c281eccf1 15-Sep-2014 Sebastien Hertz <shertz@google.com> Avoid crash in StringReference.Value JDWP command

Checks for null or invalid object id. Also checks whether the corresponding
object is a java.lang.String.

Bug: 17492221
Bug: 15005460

(cherry picked from commit 29259fa6b0514866d2d4bf57d58c1557b26abbb7)

Change-Id: I52673bdef6912a4cccf5a6eeecb6e1e817b9dd6b
1d6ee090fddd4bfd35c304d6ceb929d5c529dfcc 16-Sep-2014 Jeff Hao <jeffhao@google.com> Avoid suspending for alloc trace enabling when already suspended.

Bug: 17499772
Change-Id: Id98c10967b28e8859e5ac46f5878c304fb85c498
a06430c76981d545b5f2b64a7ef53c44c030cf73 15-Sep-2014 Sebastien Hertz <shertz@google.com> Check for errors in ThreadGroupReference JDWP commands

Returns INVALID_OBJECT error for null or invalid object. Also returns
INVALID_THREAD_GROUP error when the object is not a java.lang.ThreadGroup.

Removes unused Dbg::GetMainThreadGroupId method.

Bug: 17503230
Change-Id: Ifae39b0280633836655b22fc212018cb06b65c6c
5a4b8a236030460651a3136397d23ca6744e7eb7 11-Sep-2014 Andreas Gampe <agampe@google.com> ART: Rename Handle hierarchy

Bring the names in line with normal OO principles: ConstHandle
becomes Handle, and Handle becomes MutableHandle.

Change-Id: I0f018eb7ba28bc422e3a23dd73a6cbe6fc2d2044
29259fa6b0514866d2d4bf57d58c1557b26abbb7 15-Sep-2014 Sebastien Hertz <shertz@google.com> Avoid crash in StringReference.Value JDWP command

Checks for null or invalid object id. Also checks whether the corresponding
object is a java.lang.String.

Bug: 17492221
Bug: 15005460

Change-Id: I2e9afe2ade69b130e59a5a0c00d02ded20b05b94
d539167b7f11136fe570a77aff2ee4935842007a 09-Sep-2014 Sebastien Hertz <shertz@google.com> Update JDWP event filtering to avoid useless ids

To reduce the number of JDWP ids in the debugger, we update the event filtering
support to work with runtime objects (Thread, Class, Object, ...) instead of
JDWP ids (ThreadId, RefTypeId, ObjectId, ...).

We used to create useless JDWP ids for events even if they were not reported
because of event filtering (thread only, class only, instance only, ...). Now
we only create JDWP ids when we know we're going to report an event.

Bug: 17343664
Change-Id: Ib83df6d82fbcb40895f5cd9201a1e9ecd0a07e17
844506b3f75b4643de8b326855daf03c2fbcc99c 13-Sep-2014 Ian Rogers <irogers@google.com> Pass current thread as argument to alloc instrumentation.

Avoids recomputation in the hot allocation path when instrumentation is
enabled.

Change-Id: Ic6e7d7d0744f4756787f75d21fddd3c50280b588
7b078e8c04f3e1451dbdd18543c8b9692b5b067e 10-Sep-2014 Ian Rogers <irogers@google.com> Compile time performance improvements focusing on interpret-only.

Reduce virtual method dispatch in the method verifier and make more code
inline-able.
Add a StringPiece with const char* equality operator to avoid redundant
StringPieces and strlens.
Remove back link from register line to verifier and pass as argument to reduce
size of RegisterLine.
Remove instruction length from instruction flags and compute from the
instruction, again to reduce size.
Add suspend checks to resolve and verify to allow for more easy monitor
inflation and reduce contention on Locks::thread_list_suspend_thread_lock_.
Change ThrowEarlierClassFailure to throw pre-allocated exception.
Avoid calls to Thread::Current() by passing self.
Template specialize IsValidClassName.
Make ANR reporting with SIGQUIT run using checkpoints rather than suspending
all threads. This makes the stack/lock analysis less lock error prone.
Extra Barrier assertions and condition variable time out is now returned as a
boolean both from Barrier and ConditionVariable::Wait.

2 threaded host x86-64 interpret-only numbers from 341 samples:
Before change: Avg 176.137ms 99% CI 3.468ms to 1060.770ms
After change: Avg 139.163% 99% CI 3.027ms to 838.257ms
Reduction in average compile time after change is 20.9%.
Slow-down without change is 26.5%.

Bug: 17471626 - Fix bug where RegTypeCache::JavaLangObject/String/Class/Throwable
could return unresolved type when class loading is disabled.
Bug: 17398101

Change-Id: Id59ce3cc520701c6ecf612f7152498107bc40684
070f732bc270f6b9a579838d3418eb13b9cdf8ff 09-Sep-2014 Sebastien Hertz <shertz@google.com> Fix deadlock in VirtualMachine.AllThreads

We cannot add any object in the JDWP object registry while holding the
Locks::thread_list_lock. Indeed we may need to suspend a thread and take it,
causing a deadlock by waiting for ourself on this lock.

Bug: 17343664

(cherry picked from commit d35776413901a6a9d478e06dc354ea4f7d962e04)

Change-Id: I07d150b95a6d2b62c913bf2ca2ac217911b2f19d
4537c41b9a58c2280b3ad8bcf0130ed11c7a54f6 28-Aug-2014 Sebastien Hertz <shertz@google.com> Don't hold any lock when visiting classes from JDWP

Computes reference type ids of all loaded classes without holding the class
linker lock. Because computing the JDWP reference type id can cause thread
suspension, we can't hold any lock. This is detected in debug build (using
libartd.so) and causes an abort.

Also adds missing thread safety annotations related to ObjectRegistry::lock_.

Bug: 17305632
Bug: 16720689

(cherry picked from commit 95795e286145a4aece5c4a095fa2e7e88ee2115a)

Change-Id: If4fb069790a0a3358ad49da8f75c62a54c0f0b56
d35776413901a6a9d478e06dc354ea4f7d962e04 09-Sep-2014 Sebastien Hertz <shertz@google.com> Fix deadlock in VirtualMachine.AllThreads

We cannot add any object in the JDWP object registry while holding the
Locks::thread_list_lock. Indeed we may need to suspend a thread and take it,
causing a deadlock by waiting for ourself on this lock.

Bug: 17343664
Change-Id: I2335c63e418c0d485daf2c35f8debcd52f943140
306db81aba41eb244a4e8299cf58ac18ae9999c7 05-Sep-2014 Brian Carlstrom <bdc@google.com> Fix numerous issues with DdmVmInternal allocation tracking

Issues addressed:
- Using without JDWP attached caused native crash.
- When buffer is full (64k entries), number of entries reported was 0.
- Disabling tracking after disabling tracking caused native crash.
- Asking for allocations after disabled caused native crash.
- Lock ordering issues between mutator lock and alloc tracker lock.

Adding 098-ddmc test to cover these cases.

Bug: 17392248

(cherry picked from commit a5815065ac0877add9c0db3605d27b4d6c426e61)

Change-Id: Ib0bc18dfcdafcc050ab9dceed3d167dd878d1d7a
f4cb036808b88fe60d71a705b2744284155cbc01 05-Sep-2014 Brian Carlstrom <bdc@google.com> Fix numerous issues with DdmVmInternal allocation tracking

Issues addressed:
- Using without JDWP attached caused native crash.
- When buffer is full (64k entries), number of entries reported was 0.
- Disabling tracking after disabling tracking caused native crash.
- Asking for allocations after disabled caused native crash.
- Lock ordering issues between mutator lock and alloc tracker lock.

Adding 098-ddmc test to cover these cases.

Bug: 17392248
Change-Id: I45c0abbfb3dd7a7421aea3bbba2ea8d05225e48b
c0542af3e2170143ba40d89136e284997e16bf64 04-Sep-2014 Ian Rogers <irogers@google.com> Remove abuse of mirror::Object* to reference special values.

Remove kInvalidIndirectRefObject, kClearedJniWeakGlobal and
ObjectRegistry::kInvalidObject. Handle error conditions by passing in or
returning an error value.
GetObjectRefType is simplified to be faster and not return invalid references
that are not expected according to the spec. Adjust check JNI and
jni_internal_test appropriately.
Fix cases in the debugger/JDWP of out arguments being passed by reference.
Bug: 17376993

Change-Id: I3ce8a28c01827e163f4dc288449959464da788b1
95795e286145a4aece5c4a095fa2e7e88ee2115a 28-Aug-2014 Sebastien Hertz <shertz@google.com> Don't hold any lock when visiting classes from JDWP

Computes reference type ids of all loaded classes without holding the class
linker lock. Because computing the JDWP reference type id can cause thread
suspension, we can't hold any lock. This is detected in debug build (using
libartd.so) and causes an abort.

Also adds missing thread safety annotations related to ObjectRegistry::lock_.

Bug: 17305632
Bug: 16720689

Change-Id: Id2cbd56624499c09e4755aaef7a9b15d2bdf4c91
ed2be1725fb79075892b1a9103487c9d9a95b350 19-Aug-2014 Sebastien Hertz <shertz@google.com> Reduce lock contention when debugging

Uses a ReaderWriterMutex for the breakpoint lock to reduce contention during
debugging session.

Also adds missing thread safety annotations on fields and methods related to
instrumentation and debugging.

Bug: 16814665
Bug: 11667502

(cherry picked from commit 59d9d668d4f4286813afe2b4e7c6db839222ce96)

Change-Id: I5f1156da8c6cc8316d6db16e6cfb2470fe289ad3
ba32de47e32f436d7c11cb4a2e78bdd4ad4dc5d2 28-Aug-2014 Brian Carlstrom <bdc@google.com> Fix issue with Thread.setName hanging after Thread.start

When suspending a thread by peer the invariant that only attached threads are
suspended must be maintained. Add a ThreadList::Contains check which requires
making this method non-static.
Add some extra thread logging.

Bug: 17302037

(cherry picked from commit 37c16453a92bbf1a47f042000318a1b60381017d)

Change-Id: I51832785d4b4b431e035318e75635f442e89a1fb
37c16453a92bbf1a47f042000318a1b60381017d 28-Aug-2014 Brian Carlstrom <bdc@google.com> Fix issue with Thread.setName hanging after Thread.start

When suspending a thread by peer the invariant that only attached threads are
suspended must be maintained. Add a ThreadList::Contains check which requires
making this method non-static.
Add some extra thread logging.

Bug: 17302037
Change-Id: I89af9840e398c2ceadeb736c431dfe3be8f3ba06
bf99f77dda749e2b653e8c45259b1fb56e7bb012 24-Aug-2014 Mathieu Chartier <mathieuc@google.com> Clean up Handle usage.

Prefer using ConstHandle instead of Handle as function arguments
since you can't assign new references to ConstHandle which helps
prevent bugs.

Changed NullHandle to be a ConstHandle so that you can never modify
it to be a non null reference.

Change-Id: I81cb979f6f8d5b49e5614966a2caf28c3701dd4f
dc3761719fb5e2d1ced5708e3c73b965f9ef0c73 22-Aug-2014 Hiroshi Yamauchi <yamauchi@google.com> Handlerize MethodVerifier::mirror_method_.

The method (mirror_method_) wasn't handlerized across some
allocation/GC points such as the ResolveType() call in
ScanTryCatchBlocks() and the GetReturnType() calls in
CodeFlowVerifyInstruction().

Bug: 12687968
Change-Id: I95323de14459eb5a7c4abfcf44f882f86d59be64
59d9d668d4f4286813afe2b4e7c6db839222ce96 19-Aug-2014 Sebastien Hertz <shertz@google.com> Reduce lock contention when debugging

Uses a ReaderWriterMutex for the breakpoint lock to reduce contention during
debugging session.

Also adds missing thread safety annotations on fields and methods related to
instrumentation and debugging.

Bug: 16814665
Bug: 11667502
Change-Id: I056cdafa91109e0c83806c8d8df75c37ade0a354
c6345efb56f9096c4b1a1a90e1d8d847fc01d910 18-Aug-2014 Sebastien Hertz <shertz@google.com> Fix JDWP event races

Fix a race where the JDWP connection could be closed before the VM_DEATH event
is sent during runtime shutdown.

Fix potential race where we could wait forever for the JDWP thread to establish
connection.

Bug: 16720689

(cherry picked from commit d8b3537b89fa68599534a65afc3b272639cd4a75)

Change-Id: I4b8996ade6a38fa8f7f23c3000b7184b162907d7
d8b3537b89fa68599534a65afc3b272639cd4a75 18-Aug-2014 Sebastien Hertz <shertz@google.com> Fix JDWP event races

Fix a race where the JDWP connection could be closed before the VM_DEATH event
is sent during runtime shutdown.

Fix potential race where we could wait forever for the JDWP thread to establish
connection.

Bug: 16720689

Change-Id: I227e0a15a2fd17d7bfe2a66a35d719d558fcd32d
cb6b0f31ede2275e79e6199ec391147585a37a2a 12-Aug-2014 Ian Rogers <irogers@google.com> Avoid use of std::string where we have const char*.

Removing the ClassHelper caused std::string creation for all calls to
Class::GetDescriptor and a significant performance regression. Make the
std::string an out argument so the caller can maintain it and its life time
while allowing GetDescriptor to return the common const char* case.

Don't generate GC maps when compilation is disabled.

Remove other uses of std::string that are occuring on critical paths.
Use the cheaper SkipClass in CompileMethod in CompilerDriver.
Specialize the utf8 as utf16 comparison code for the common shorter byte
encoding.
Force a bit of inlining, remove some UNLIKELYs (they are prone to pessimizing
code), add some LIKELYs.

x86-64 host 1-thread interpret-only of 57 apks:
Before: 29.539s
After: 23.467s

Regular compile:
Before: 1m35.347s
After: 1m20.056s

Bug: 16853450
Change-Id: Ic705ea24784bee24ab80084d06174cbf87d557ad

Conflicts:
runtime/utils.cc
1ff3c98775a4577cf053dba9a0c2d5c21c07b298 12-Aug-2014 Ian Rogers <irogers@google.com> Avoid use of std::string where we have const char*.

Removing the ClassHelper caused std::string creation for all calls to
Class::GetDescriptor and a significant performance regression. Make the
std::string an out argument so the caller can maintain it and its life time
while allowing GetDescriptor to return the common const char* case.

Don't generate GC maps when compilation is disabled.

Remove other uses of std::string that are occuring on critical paths.
Use the cheaper SkipClass in CompileMethod in CompilerDriver.
Specialize the utf8 as utf16 comparison code for the common shorter byte
encoding.
Force a bit of inlining, remove some UNLIKELYs (they are prone to pessimizing
code), add some LIKELYs.

x86-64 host 1-thread interpret-only of 57 apks:
Before: 29.539s
After: 23.467s

Regular compile:
Before: 1m35.347s
After: 1m20.056s

Bug: 16853450
Change-Id: Ic705ea24784bee24ab80084d06174cbf87d557ad
9ac5602c1f5829c994360674fea1055a738caa23 12-Aug-2014 Sebastien Hertz <shertz@google.com> Fix crash in VirtualMachine.AllThreads JDWP command

When collecting all the started threads, we may encounter a thread in the
process of being started from Java code (Thread.start) in the threads list. The
crash occurs when we attempt to access the java.lang.Thread peer (calling
Thread::GetPeer) but the JNI global reference to it (Thread::jpeer) has not
been destroyed yet (which is verified with a check). This only happens when the
thread is starting up.

We now check the thread finished starting up before accessing the Java peer.
This also prevents from returning non-started threads in the reply.

Bug: 16660101

(cherry picked from commit a22d115711b5158cfc67b4f260a5b40f3ab303ca)

Change-Id: Ib61dbd0b01f63bfdda708d3c93eac58284bbe236
a22d115711b5158cfc67b4f260a5b40f3ab303ca 12-Aug-2014 Sebastien Hertz <shertz@google.com> Fix crash in VirtualMachine.AllThreads JDWP command

When collecting all the started threads, we may encounter a thread in the
process of being started from Java code (Thread.start) in the threads list. The
crash occurs when we attempt to access the java.lang.Thread peer (calling
Thread::GetPeer) but the JNI global reference to it (Thread::jpeer) has not
been destroyed yet (which is verified with a check). This only happens when the
thread is starting up.

We now check the thread finished starting up before accessing the Java peer.
This also prevents from returning non-started threads in the reply.

Bug: 16660101

Change-Id: I9e445e5da3a6951143d6c3c9a0d4f136398fde2f
6bff7130878128c9836a21ae58d0cfdb0075b1b5 30-Jul-2014 Mathieu Chartier <mathieuc@google.com> Add support for bump pointer spaces to DdmSendHeapSegments.

Added support for bump pointer spaces as well as
differentiating between DlMallocSpaces and RosAllocSpaces.
Added logic to reset the start of next chunk to prevent
inbetween space regions counted as free.

Fixed a debug build bug where we were doing an mprotect after
creating a rosalloc space. In debug builds, this writes a magic
value in the page. This was faulting since it was set to PROT_NONE.
The fix moves the mprotect before the RosAlloc space creation.

Bug: 16408851

(cherry picked from commit 36dab3607e77505ce139eacef1c62a1c4bc4affd)

Change-Id: I5095feb01fa7e248178a2833da7f821f4fd52c89
36dab3607e77505ce139eacef1c62a1c4bc4affd 30-Jul-2014 Mathieu Chartier <mathieuc@google.com> Add support for bump pointer spaces to DdmSendHeapSegments.

Added support for bump pointer spaces as well as
differentiating between DlMallocSpaces and RosAllocSpaces.
Added logic to reset the start of next chunk to prevent
inbetween space regions counted as free.

Fixed a debug build bug where we were doing an mprotect after
creating a rosalloc space. In debug builds, this writes a magic
value in the page. This was faulting since it was set to PROT_NONE.
The fix moves the mprotect before the RosAlloc space creation.

Bug: 16408851
Change-Id: Ibe18198d05ff353fbb57d10b2f7719fdcbf1c5f0
5dc158e9b6635b6c5d3916ae4094e8886feb4580 16-Jul-2014 Sebastien Hertz <shertz@google.com> Fix access to long/double stack values from debugger

Long and double values live in a pair of DEX registers. When we compile DEX
code with the Quick compiler, a DEX register either lives in the stack or is
promoted to a physical register. In the case of a pair of DEX registers, the
Quick compiler assumes both registers live in the same "area": both live in
the stack or both are promoted to physical registers.

From the debugger, we used to access these values by reading/writing each DEX
register separately. However, this does not work when only one DEX register of
a pair is promoted and the other lives in the stack. In this case, the compiled
code reads from/writes to the stack only.

To fix that, the debugger must follow the same rule than the Quick compiler: if
both DEX registers are promoted, read/write them from/to physical registers,
otherwise read/write them from/to the stack. We add StackVisitor:GetVRegPair and
StackVisitor:SetVRegPair for this purpose.

We also follow the same rule when deoptimizing. However we need to do that only
when we know two consecutive DEX registers are part of a pair (long or double).
We know that thanks to the verifier.

Bug: 15527793

(cherry picked from commit c901dd7bdc80b953d04100ef2f54b8d1ca5f466b)

Change-Id: I981e088295254d75352f83a3e6ba0b292cfe3ed3
799eb3a5555254427db269921042419bc30d4d86 19-Jul-2014 Hiroshi Yamauchi <yamauchi@google.com> Add read barriers for the GC roots in Instrumentation.

Bug: 12687968
Change-Id: I324e2f950ce4500b0e00722044af3a9c82487b23
f3d874c60ee3ada19ce26a5c4e532312b6f3a9e9 18-Jul-2014 Ian Rogers <irogers@google.com> Avoid race in single thread suspension.

Don't allow more than one concurrent single thread suspension to avoid
potential cycles and deadlocks where threads try to suspend each other.
Bug: 16364458, 16354227

Change-Id: I907f1d5591a6aa5c241d37d6b4a34f968f98df77
c901dd7bdc80b953d04100ef2f54b8d1ca5f466b 16-Jul-2014 Sebastien Hertz <shertz@google.com> Fix access to long/double stack values from debugger

Long and double values live in a pair of DEX registers. When we compile DEX
code with the Quick compiler, a DEX register either lives in the stack or is
promoted to a physical register. In the case of a pair of DEX registers, the
Quick compiler assumes both registers live in the same "area": both live in
the stack or both are promoted to physical registers.

From the debugger, we used to access these values by reading/writing each DEX
register separately. However, this does not work when only one DEX register of
a pair is promoted and the other lives in the stack. In this case, the compiled
code reads from/writes to the stack only.

To fix that, the debugger must follow the same rule than the Quick compiler: if
both DEX registers are promoted, read/write them from/to physical registers,
otherwise read/write them from/to the stack. We add StackVisitor:GetVRegPair and
StackVisitor:SetVRegPair for this purpose.

We also follow the same rule when deoptimizing. However we need to do that only
when we know two consecutive DEX registers are part of a pair (long or double).
We know that thanks to the verifier.

Bug: 15527793
Change-Id: I04812285ff26ef0129f39792a1cf776f3591ca2d
6093a5c277e54bcd949dd6fac7b3856e5f371d06 18-Jul-2014 Ian Rogers <irogers@google.com> Avoid race in single thread suspension.

Don't allow more than one concurrent single thread suspension to avoid
potential cycles and deadlocks where threads try to suspend each other.
Bug: 16364458, 16354227

(cherry picked from commit f3d874c60ee3ada19ce26a5c4e532312b6f3a9e9)

Change-Id: I907f1d5591a6aa5c241d37d6b4a34f968f98df77
22d5e735f403c57525fe868304c7123f0ce66399 16-Jul-2014 Ian Rogers <irogers@google.com> Remove object_utils.h.

Break into object_lock, field_helper and method_helper.
Clean up header files following this.
Also tidy some of the Handle code in response to compiler errors when resolving
the changes in this CL.

Change-Id: I73e63015a0f02a754d0866bfaf58208aebcaa295
bae182cbc6adc8796154162a87fc54ae804e0469 17-Dec-2013 Sebastien Hertz <shertz@google.com> Fix method tracing from command-line

Transitions current thread to the new kWaitingForMethodTracingStart thread
state when starting method tracing.

Ensures there is a current thread when method tracing is stopped due to runtime
shutdown. If the current thread has been detached, we now re-attach it.
Note: we only do this if method tracing has been activated from command-line.

Fixes instrumentation when forcing interpreter mode (-Xint) with method tracing
enabled.

Removes unused parameter from UnsafeLogFatalForThreadSuspendAllTimeout.

Bug: https://code.google.com/p/android/issues/detail?id=72094
Bug: 11683397
Change-Id: I70f000fb46ddd95d6ad51ea0a8eee77697a045e9
0ec17d2ddb69d3f5c46ccad62e82c0ffd6219428 07-Jul-2014 Hiroshi Yamauchi <yamauchi@google.com> Remove Dbg::VisitRoots().

We replace the GC strong roots with JNI.

jdwp_test passes.

Bug: 12687968
Change-Id: I841f1aaa5dffa784ca25953a251600f70df273b2
4345c46b8a927cf13d9bbe38f8cf0593f5de181b 27-Jun-2014 Mathieu Chartier <mathieuc@google.com> Fix local reference leaks in debugger and use a cache.

Changed alloc record stack trace element to use jmethodID instead of
JNI weak global references. Added code to delete the local ref
created in AllocRecord::SetType.

Bug: 15886342
External bug: https://code.google.com/p/android/issues/detail?id=72330

Change-Id: Id18e765820baad02246768dc9d633aada60f4fed
aa9b3aee1e06f922e4518713f9b3dff00a0b2597 13-Jun-2014 Sebastien Hertz <shertz@google.com> Fix access to FP registers when visiting stack

Adds GetFPR and SetFPR to Context class so we can read from and write to
floating-point registers during stack visit. They return a boolean flag
indicating whether the read/write is successful. This allows the debugger to
return the JDWP error ABSENT_INFORMATION when we can't read/write a register.
We also update GetGPR and SetGPR for consistency. We keep a default GetGPR
implementation asserting the read was successful using a CHECK so we don't
silently fail.

Adds missing JDWP object tags for StackFrame.SetValues to avoid crash when
setting corresponding objects (thread, thread group, class object or class
loader). Also returns JDWP error INVALID_OBJECT (when the given object id is
invalid) instead of crashing with an unimplemented message.

Bug: 15433097
Change-Id: I70843c9280e694aec1eae5cf6f2dc155cb9ea10e
0bcb2902ec21393d71c94e63aa6733cb5311a0cc 17-Jun-2014 Sebastien Hertz <shertz@google.com> Revert "Revert "Fix access to FP registers when visiting stack""

This reverts commit 8ebd94ab2e0d9867a7d384f00fa4cab24235216f.

Fixes StackVisitor::GetVReg to read register value in a uintptr_t local and
cast it into uint32_t pointer argument.

Bug: 15433097
Change-Id: I4e13ed5446e823e9ec50fbc378b16be5b17b2294
8ebd94ab2e0d9867a7d384f00fa4cab24235216f 17-Jun-2014 Sebastien Hertz <shertz@google.com> Revert "Fix access to FP registers when visiting stack"

This reverts commit aa9b3aee1e06f922e4518713f9b3dff00a0b2597.

Change-Id: Ied27deb89cca5ec9094d391374e03f83fcb76c33
cc8c5c5433230818cfe31617308198f286cc2ee1 14-Jun-2014 Hiroshi Yamauchi <yamauchi@google.com> Avoid a non-root monitor vector in Dbg::GetOwnedMonitors().

Following up on CL 96571, remove the need to use stack-scoped vectors,
one of which is a non-root vector that holds Object*, which could
cause a GC bug.

Bug: 12687968
Change-Id: I8582fe6bfe71bae7018dbf844fe75ebe989b6535
b5a9e3d1cc1fd66683e43e365afc8c900e2800c4 09-Jun-2014 Hiroshi Yamauchi <yamauchi@google.com> Remove Object* weak roots from the debugger.

The weak roots were converted to JNI weak refs.

Since the weak roots are now normal JNI weak refs, we eliminate the
need to insert read barriers for those weak roots in the debugger and
the need for the GC to have a separate step to update them as part of
the system weak sweeping.

Bug: 12687968
Change-Id: If16396d4713457b8af4f1ea6a0c6ec6799cb615e
9f1020305292a21fd14a402b189c765a125226ab 23-May-2014 Sebastien Hertz <shertz@google.com> Fix exception reporting from interpreter

To comply with JDWP exception report rules, we must report an exception at the
location of the throw (or the first instruction encountered after a native
call). To do this, we use the CatchLocationFinder visitor to look for a catch
handler until we reach a native frame or the top frame.

Because interpreter handles pending exception on a method-by-method basis, we
need a flag to remember we already reported the exception and avoid reporting
it multiple times when unwinding methods. The drawback is we need to maintain
the state of this flag. We clear it when the exception is cleared. In the case
we temporarily clear the exception (when finding a catch handler for instance),
we restore the flag to its previous value at the same time we restore the
pending exception.

Bump oat version to force recompilation because we modify Thread offsets.

Bug: 14402770
Change-Id: Ic059c58f80b2023b118038301f8f0a24f1e18241
bfd9a4378eacaf2dc2bbe05ad48c5164fc93c9fe 22-May-2014 Mathieu Chartier <mathieuc@google.com> Change MethodHelper to use a Handle.

Added ConstHandle to help prevent errors where you modify the value
stored in the handle of the caller. Also fixed compaction bugs
related to not knowing MethodHelper::GetReturnType can resolve types.
This bug was present in interpreter RETURN_OBJECT.

Bug: 13077697

Change-Id: I71f964d4d810ab4debda1a09bc968af8f3c874a3
61c5ebc6aee2cac1c363de6fbdac25ada1697fdb 06-Jun-2014 Mathieu Chartier <mathieuc@google.com> Change FieldHelper to use a handle.

Fixed compaction bugs related to FieldHelper::GetType in:
artSet32InstanceFromCode
SetFieldValueImpl
CheckReceiver
Field_set
interpreter::DoFieldPut
MethodVerifier::VerifyISGet
MethodVerifier::VerifyISPut
MethodVerifier::VerifyIGetQuick

Bug: 13077697

Change-Id: I7de9ded2893b5568d43e4daa86fd135bf5508b72
4206eb5d86d3a2406361e59b2018152b2485cced 05-Jun-2014 Sebastien Hertz <shertz@google.com> Fix crash in JDWP ReferenceType.SourceFile command

Updates Dbg::GetSourceFile to return ABSENT_INFORMATION error code when
Class::GetSourceFile returns nullptr. This happens if the class has no source
file information.

Updates Class:GetSourceFile to return nullptr for classes which have no
ClassDef item like generated classes. This allows to remove the IsProxyClass
test from Dbg::GetSourceFile. Adds this test in proxy_test.

Bug: 15426710
Change-Id: I019da4ced83778d5264484c43b225f8b5c95632e
ffddfdf6fec0b9d98a692e27242eecb15af5ead2 03-Jun-2014 Tim Murray <timmurray@google.com> DO NOT MERGE

Merge ART from AOSP to lmp-preview-dev.

Change-Id: I0f578733a4b8756fd780d4a052ad69b746f687a9
46960fe5dcc1be07b39a55114338423a73554449 23-May-2014 Ian Rogers <irogers@google.com> Make the specification of when we need precise constants more precise.

Means that oatdump output showing values for deoptimization actually reflects
what we see at runtime.
Also, doesn't do precise in the case of determining methods and fields for the
quickened case, which may be an occasional performance win.

Change-Id: I62c7fb244f7996ba9d52e7a7ce75c046b663fa17
c4ddc042eaf5232a3f9b111f42af39eeab6e0294 13-May-2014 Christopher Ferris <cferris@google.com> Add support for jemalloc instead of dlmalloc.

Bug: 981363
Change-Id: I226ce3249c0d982eb1a9fdb9d04b25737f77345d
700a402244a1a423da4f3ba8032459f4b65fa18f 20-May-2014 Ian Rogers <irogers@google.com> Now we have a proper C++ library, use std::unique_ptr.

Also remove the Android.libcxx.mk and other bits of stlport compatibility
mechanics.

Change-Id: Icdf7188ba3c79cdf5617672c1cfd0a68ae596a61
f832284dd847ff077577bb5712225430bbbb3b67 16-May-2014 Mathieu Chartier <mathieuc@google.com> Delete ClassHelper and fix compaction bug in GetDirectInterface

Cleanup helps to prevent compaction bugs. Fixed a fairly serious
compaction error caused by calling ClassHelper::GetDirectInterface
without handling the case where it causes thread suspension due to
ResolveType.

Bug: 8981901

Change-Id: I82b3bb6dd48d21eb6ece7aae0733c4a23c2bc408
e713d9338ad122d6b8c7997387d0c9fc464eea3e 15-May-2014 Sebastien Hertz <shertz@google.com> Fix JDWP location event report on return instructions

After change https://android-review.googlesource.com/94334, the debugger may
listen to kDexPcChange event without listening for kMethodExit event. In this
case, we need to report kDexPcChange event on RETURN instructions.

Bug: 11874828
Change-Id: Ic61f4eec71e7ece494bee628d7f3358a616d31d3
7d2ae437a87ceb2bdda098ab11f4da588c6a75f5 15-May-2014 Sebastien Hertz <shertz@google.com> Fix build

Fix format error.

Change-Id: Ic793c52f46d645bf88ea6b28d5b4fa1bdb315a20
42cd43fa593e8f0427eb0ec158bef08814a6180b 13-May-2014 Sebastien Hertz <shertz@google.com> Register debugger for interesting instrumentation events only

This avoids the overhead of notifying events (like method entry/exit, field
read/write, ...) from the interpreter when they are not requested on the JDWP
side. It also avoids burning JDWP ids for objects and classes before we find
out we do not need to report the event.

When we register a JDWP event (like a breakpoint), we add the debugger as
a listener for the corresponding instrumentation event (like kDexPcChanged).
On the other hand, when a JDWP event is cleared, we remove the debugger as a
listener for the corresponding instrumentation event. To control we add/remove
the debugger as listener only once per instrumentation event, we use reference
counting.

Like deoptimization, we can update instrumentation listeners only when when all
mutator threads are suspended. To add or remove the debugger as listener, we
extend the support of deoptimization requests to a more general support dealing
with instrumentation requests.
We add kRegisterForEvent and kUnregisterForEvent request kinds, respectively to
add or remove the debugger as a listener for a given instrumentation event.
Note: we will rename the related classes, methods, ... to avoid pollution in
the code review.

This CL also fixes Instrumentation::IsActive to take field read/write events
into account.

Bug: 14401699
Bug: 14826953
Change-Id: Ic896469e82a8589de419ebea4b9dc3116925f3ab
eb8167a4f4d27fce0530f6724ab8032610cd146b 08-May-2014 Mathieu Chartier <mathieuc@google.com> Add Handle/HandleScope and delete SirtRef.

Delete SirtRef and replaced it with Handle. Handles are value types
which wrap around StackReference*.

Renamed StackIndirectReferenceTable to HandleScope.

Added a scoped handle wrapper which wraps around an Object** and
restores it in its destructor.

Renamed Handle::get -> Get.

Bug: 8473721

Change-Id: Idbfebd4f35af629f0f43931b7c5184b334822c7a
8379b2256be5d2be4ad083a76e9f8ec403c4d405 24-Feb-2014 Sebastien Hertz <shertz@google.com> Combine JDWP location events

The runtime now sends location events BREAKPOINT, SINGLE_STEP, METHOD_ENTRY,
METHOD_EXIT and METHOD_EXIT_WITH_RETURN_VALUE in the same JDWP event packet
when they relate to the same location.

We update the Dbg::UpdateDebugger method to take initial event flags and
returned value. It allows to call this method from DebugInstrumentationListener
so we can treat method entry/exit events with breakpoint and single-step.

In the interpreter, we ensure we do not call Instrumentation::DexPcMovedEvent
when Instrumentation::MethodEnterEvent has just been called or when we're about
to call Instrumentation::MethodExitEvent. This prevents from sending duplicated
events.

I measured the average performance impact on some benchmarks with a Nexus 4
without a debugger attached:
* 1%-2% for the computed-goto-based interpreter (default interpreter)
* 5%-10% for the switch-based interpreter.
This is mostly due to the test of the boolean flag for the method entry event.

Bug: https://code.google.com/p/android/issues/detail?id=68427
Bug: 11874828
Change-Id: Ic4ff61375ff6b4ed5825adeac09f61f97b4be619
4d466a8e4587422c989705dce3b2a19e7f0137f5 09-May-2014 Brian Carlstrom <bdc@google.com> Remove all LOG(DEBUG) which is not intended to be checked in

Bug: 14632493
Change-Id: Id9da8b87798af0a1b2bd2c178133e5f1ba47d43d
b0fa5dc7769c1e054032f39de0a3f6d6dd06f8cf 29-Apr-2014 Ian Rogers <irogers@google.com> Force inlining on trivial accessors.

Make volatility for GetFieldObject a template parameter.
Move some trivial mirror::String routines to a -inl.h.

Bug: 14285442

Change-Id: Ie23b11d4f18cb15a62c3bbb42837a8aaf6b68f92
280286ac8a0e3a30c68be511c8b7a0a4d62936d7 28-Apr-2014 Sebastien Hertz <shertz@google.com> Fix DDM recent allocations

A class may not have source file in which case ClassHelper::GetSourceFile
returns NULL. Adding the GetMethodSourceFile function helps us preventing
from dealing with null strings.

Bug: 14300208
Change-Id: I28707f883bacec4ee367ff703328d0f0240855f9
3f52eafe5577b8489f90dc8ed5981b3455206147 04-Apr-2014 Sebastien Hertz <shertz@google.com> Prepare field watchpoint support

Adds field read/write events in the instrumentation. The debugger now registers
as a listener for these events so JDWP field access and field modification
events can be reported.

This CL will be followed by another one to report these events from the
interpreter. Therefore no JDWP field access and field modification events
can be sent for now.

Bug: 8267708
Change-Id: If2a93eb590805567d69015c83cce9cd2ab712cbd
bb43b433c845e253a11346f0f03706d58a44f23c 14-Apr-2014 Sebastien Hertz <shertz@google.com> Clear unused roots from debugger

SingleStepControl and DebugInvokeReq hold roots which are only used during a
limited amount of time. Clear these roots once we finish using them.

Also cleans some code around single-step.

Change-Id: Ica2f65e04a4d60272199490cd40ad1803d3b9f02
7ec2f1ca3cbd021848da75d5566f7239ce29676f 27-Mar-2014 Sebastien Hertz <shertz@google.com> Speed up single-stepping

During single-stepping sequence, we need to deoptimize everything when we
register a single-step event and undeoptimize everything when it is done. This
causes a slow pattern where we continuously deoptimize-undeoptimize everything
for each single-step.

This CL introduces a special handling of single-step undeoptimization. We now
delay the undeoptimization to the next resume (one thread or all threads) or
the end of the debugging session. Indeed, a single-step event registration is
always followed by a resume command.
At the "resume" point, we know if a single-step event is registered and if we
really need to undeoptimize. At the "registration" point, we know we did not
undeoptimized everything so we don't need to deoptimize everything again.
Therefore, in a sequence of single-steps, we only do a full deoptimization for
the first single-step and a full undeoptimization for the last single-step.

We update logs at deoptimization points so we can track more precisely. Note
they are verbose logs that still must be enabled with -verbose:jdwp option.

We also make some improvement inside instrumentation:
* updates Instrumentation::ShouldNotifyMethodEnterExitEvents to comply with its
name.
* compute frame id only once when looking for the corresponding instrumentation
frame.
* compute the OatMethod once in ClassLinker::GetPortableOatCodeFor to avoid
looking for it again.

Bug: 13577964
Change-Id: If6fa198a676b515cd474b8c4d7bf7ef3626f2dc7
1d66e88ea74f7d85f75db7f145fe955d5f0f6872 07-Apr-2014 nikolay serdjuk <nikolay.y.serdjuk@intel.com> JDWP request is parsed incorrectly due to junk in the descriptor

The ClassHelper object is created and deleted on the same line.
Therefore it is wrong to refer to any class members of the object in
the next line. Any references to the object and the object itself
must have the same live ranges.

Change-Id: I792d7baa3828b0389254f2941705e006cab092cd
Signed-off-by: nikolay serdjuk <nikolay.y.serdjuk@intel.com>
dd7624d2b9e599d57762d12031b10b89defc9807 15-Mar-2014 Ian Rogers <irogers@google.com> Allow mixing of thread offsets between 32 and 64bit architectures.

Begin a more full implementation x86-64 REX prefixes.
Doesn't implement 64bit thread offset support for the JNI compiler.

Change-Id: If9af2f08a1833c21ddb4b4077f9b03add1a05147
4d8fd49509fdcf203107fb33c62d8f451b6eb1d0 28-Mar-2014 Sebastien Hertz <shertz@google.com> Return correct JDWP type tag for array class

Uses GetTypeTag function to get JDWP type tag for a class. This fixes the
returned type tag in ClassObjectReference.ReflectedType command.

Bug: 13689172
Change-Id: Ibb9006eb604d84cfb8e279eaeed1982a136d6510
1cd53dbb2163f18b689d2a65cf9c6bdcdb01b407 28-Mar-2014 Hiroshi Yamauchi <yamauchi@google.com> Fix a DCHECK failure when causing GC from DDMS.

Bug: 13647069
Change-Id: Iae2746b2b7b4493fcf5f0d40d2bf36a9b2d2efc8
a76a6d4cb3dedec909bd927f20bc0ab23198a337 20-Mar-2014 Sebastien Hertz <shertz@google.com> Support inlining with breakpoint

When installing/uninstalling a breakpoint in a method, we fully or selectively
deoptimize/undeoptimize depending on whether the method can be inlined. When
the method can be inlined, it requires full deoptimization. Otherwise, it only
requires selective deoptimization.

We add sanity check to control we are in a consistent state each time we add or
remove a breakpoint. We also add some comments to better describe the process
of deoptimization for breakpoint.

Bug: 12187616
Change-Id: Id15adc6e5e2fe783c83c925cbcd19ae02431b7e0
4d25df3f76f864b7629ac8c0046d46997f293d8d 21-Mar-2014 Sebastien Hertz <shertz@google.com> Refactor deoptimization support in debugger

This CL prepares breakpoint support for inlined methods where we'll have to
deoptimize everything.

We move deoptimization-related information to Dbg class only (deoptimization
request queue, full deoptimization event count and deoptimization lock). We
replace MethodInstrumentionRequest by DeoptimizationRequest. This is used to
know which kind of deoptimization is required for a particular event.

It also simplifies lock ordering a bit during event setup: we no longer need to
hold the deoptimization lock while holding the breakpoint lock. Moreover, the
deoptimization lock should be held only after the event list lock.

Bug: 12187616
Change-Id: Iff13f004adaeb25e5d609238bacce0b9720510e6
b98063a4d54c5a741152a1eebc262d8e223b3b25 26-Mar-2014 Sebastien Hertz <shertz@google.com> Fix alloc tracker locking issue

Fixes a lock level violation where we attempt to take the thread list lock
while already holding the alloc tracker lock. We now avoid holding the alloc
tracker lock when updating allocation entrypoints.

Bug: 13646642
Change-Id: Iab505dae67d0c754031fe30d50a7cbd5e4ba5785
3b05e9ba874449dbff65b01b8781001f7d93eea6 25-Mar-2014 Mathieu Chartier <mathieuc@google.com> Add missing debugger root visiting.

Bug: 13634574
Change-Id: I2a76f6c43f1d0ad1922f06deb40a71ff651129fd
83a47d8a950867da833dfb5c3d8ddfb3d87a8cfe 20-Mar-2014 Sebastien Hertz <shertz@google.com> Fix JDWP ObjectReference.InvokeMethod for virtual method call.

Fixes virtual method call by invoking the concrete method in sirt reference
after devirtualization, not the original method.

Bug: 13526099
Change-Id: I2e3548eca2f5434e8cece64c22aaf80d1cd8badf
5426324ea7a4c334cde1fdc4b8aae39f8a8e362d 19-Mar-2014 Sebastien Hertz <shertz@google.com> Fix thread suspension in ObjectReference.MonitorInfo JDWP command.

Uses ThreadList::SuspendAll and ThreadList::ResumeAll to suspend/resume all
the threads so we collect monitor info while all threads are suspended.

Bug: 13528439
Change-Id: I81ad0698a759cae428aa6a0149dafda3db4cd198
cb19ebf7609f74b223bd86c94f721498795f9bba 11-Mar-2014 Sebastien Hertz <shertz@google.com> Fix debugger crash in native method frames.

The main crash happens when we try to read (StackFrame::GetValues) or write
(StackFrame::SetValues) values in native frames. We use the method's vmap to
know where Dalvik registers live but native methods don't have vmap. The fix
is to reply with the OPAQUE_FRAME error which indicates local values are not
accessible in the frame.

We prevent from dereferencing null code item which causes some crashes too.
This happens when we compute the line table (Method::LineTable) and variable
table (Method::VariableTable) of methods without code: native, proxy and
abstract methods. We do not expect to encounter abstract methods though. We
take care of these kinds of method when mangling/demangling local value slots.

We also fix the location's pc of native and proxy frames where it must be -1
(as 8-byte value). We'll use this property to detect such frames in the JDWP
tests.

Bug: 13366758
Change-Id: I78e3263fbf2681b5573571c846390d52b9193849
53b8b09fc80329539585dcf43657bc5f4ecefdff 14-Mar-2014 Ian Rogers <irogers@google.com> Refactor reflective method invocation.

Move invocation code out of JNI internal into reflection, including ArgArray
code. Make reflective invocation use the ArgArray to build arguments rather
than allocating a jvalue[] and unboxing arguments into that.
Move reflection part of jni_internal_test into reflection_test.
Make greater use of fast JNI.

Change-Id: Ib381372df5f9a83679e30e7275de24fa0e6b1057
52d131d8e71ae9ea915ea84a3f95d49547e8e661 13-Mar-2014 Sebastien Hertz <shertz@google.com> Fix thread suspension assertion in debugger.

Updates Dbg::GetThreadGroup to ensure we do call EndAssertNoThreadSuspension
after StartAssertNoThreadSuspension and not returning in the middle. Note this
only happens in debug mode where this assertion is enabled.

Also add missing thread safety annotations.

Bug: 13425576
Change-Id: Idb9f32d289038b77771369c1283774676ff433c7
b7054baf28d4d652fbd98a94b089344a31898d53 13-Mar-2014 Sebastien Hertz <shertz@google.com> Fix debugger crashes in presence of proxy objects.

Fix ClassHelper::NumDirectInterfaces to use IfTable::Count instead of the
iftable array's length (which is twice the interface count). This happens when
processing ReferenceType::Interfaces command and was causing a crash.

Return ABSENT_INFORMATION error code when we're asked for the source file of a
proxy class. Otherwise we call ClassHelper::GetSourceFile which expect the
class has a corresponding ClassDef item in the DEX file which is not true for
proxy classes.

Add new proxy_test to check ClassHelper works correctly with proxy classes.

Bug: 13426918
Change-Id: I5c1212b1a697dd7dc1ab18e99552ee113c533a5a
719d1a33f6569864f529e5a3fff59e7bca97aad0 06-Mar-2014 Ian Rogers <irogers@google.com> Enable annotalysis on clang ART builds.

Fix clang build errors aswell as restructure locking/mutex code for correct
thread safety analysis support.
Reorder make dependencies so that host builds build first as they should
provide better compilation errors than target.
Remove host's use of -fno-omit-frame-pointer as it has no value with correct
use of CFI, which we should have.

Change-Id: I72cea8da9a3757b1a0b3acb4081feccb7c6cef90
6fac447555dc94a935b78198479cce645c837b89 26-Feb-2014 Ian Rogers <irogers@google.com> Make allocations report usable size.

Work-in-progress to allow arrays to fill usable size. Bug: 13028925.
Use C++11's override keyword on GCC >= 2.7 to ensure that we override GC and
allocator methods.
Move initial mirror::Class set up into a Functor so that all allocated objects
have non-zero sizes. Use this property to assert that all objects are never
larger than their usable size.
Other bits of GC related clean-up, missing initialization, missing use of
const, hot methods in .cc files, "unimplemented" functions that fail at
runtime in header files, reducing header file includes, move valgrind's space
into its own files, reduce number of array allocation routines.

Change-Id: Id5760041a2d7f94dcaf17ec760f6095ec75dadaa
62f57c9fdca07c423629a619eecdec71a6b9a8bc 25-Feb-2014 Sebastien Hertz <shertz@google.com> Merge "Fix debugger disconnection crash."
aaea7343831b64f4351c9abc7493ec062adfaf53 25-Feb-2014 Sebastien Hertz <shertz@google.com> Fix debugger disconnection crash.

Fixes a check failure where we uninstall instrumentation while we did not
install it before. This happens when the JDWP thread stops with no debugger
connected.

Bug: 13168905
Change-Id: I83766ced79721747e5a7aaf27ce01a853ad55f03
9837939678bb5dcba178e5fb00ed59b5d14c8d9b 25-Feb-2014 Ian Rogers <irogers@google.com> Avoid std::string allocations for finding an array class.

Introduce ClassLinker::FindArrayClass which performs an array class lookup
given the element/component class. This has a 16 element cache of recently
looked up arrays.
Pass the current thread to ClassLinker Find .. Class routines to avoid calls
to Thread::Current().
Avoid some uses of FindClass in the debugger where WellKnownClasses is a
faster and more compacting GC friendly alternative.

Change-Id: I60e231820b349543a7edb3ceb9cf1ce92db3c843
11d40c250ec86c784cf76b8c31e1cf9285d555dc 19-Feb-2014 Sebastien Hertz <shertz@google.com> Fix deoptimization deadlock

Fixes a deadlock occuring during undeoptimization on debugging session end.

Before disconnecting debugger, we must unregister all requested events. We take
the event list lock to browse all these events. Some of them (as METHOD_EXIT)
may have activated deoptimization so we need to undeoptimize. During this
process, we restore all original entrypoints of every method in the stack and
notify method exit events to the instrumentation listener (see method
InstrumentationLister::MethodExited). In our case, the instrumentation listener
is the debugger. It takes the event list lock (to browse the event list and see
if this event must be posted) but hangs waiting for it. Since it's already
holding the event list lock (which is not recursive), it ends up in a deadlock
situation.

This CL fixes the way we prevent from posting method enter/exit events during
the process of deoptimization/undeoptimization. We now explicitly set a flag
indicating if deoptimization is enabled (by the debugger).

Also removes unused field in InstallStackVisitor class and remove debugger as
listener before disabling deoptimization to ensure it does not receive any
event when disconnecting.

Change-Id: I49a2ae43e86cf29094f4b462bfa754d7740d3e97
de34eea060edb4eb34d6ecd840e6e1c4c6489642 14-Feb-2014 Yevgeny Rouban <yevgeny.y.rouban@intel.com> Do not set ACC_SUPER flag for interfaces

The debugger's GetModifier method forces the ACC_SUPER flag set for all
classes and interfaces because dex files don't contain this flag.
But according to the JVM Spec (Class File Structure) the ACC_SUPER flag
must not be set for interfaces:
If the ACC_INTERFACE flag of this class file is set,
its ACC_ABSTRACT flag must also be set (JLS 9.1.1.1). Such a class
file must not have its ACC_FINAL, ACC_SUPER or ACC_ENUM flags set.

The patch sets ACC_SUPER only if ACC_INTERFACE is not set.

Signed-off-by: Yevgeny Rouban <yevgeny.y.rouban@intel.com>
Change-Id: I6cc4b215a6584d177845a4f8cce1efeb1650f646
d2fe10a3a34af171bf1631219cd2d6ff6b7778b5 15-Jan-2014 Sebastien Hertz <shertz@google.com> Remove blacklist

Removes the class initialization blacklist and use transaction to detect and
revert class initialization attempting to invoke native method. This only
concerns class initialization happening at compilation time when generating an
image (like boot.art for the system).

In transactional mode, we log every object's field assignment and array update.
Therefore we're able to abort a transaction to restore values of fields and
array as they were before the transaction starts. We also log changes to the
intern string table so we can restore its state prior to transaction start.

Since transactional mode only happens at compilation time, we don't need to log
all these changes at runtime. In order to reduce the overhead of testing if
transactional mode is on/off, we templatize interfaces of mirror::Object and
mirror::Array, respectively responsible for setting a field and setting an
array element.

For various reasons, we skip some specific fields from transaction:
- Object's class and array's length must remain unchanged so garbage collector
can compute object's size.
- Immutable fields only set during class loading: list of fields, method,
dex caches, vtables, ... as all classes have been loaded and verified before a
transaction occurs.
- Object's monitor for performance reason.

Before generating the image, we browse the heap to collect objects that need to
be written into it. Since the heap may still holds references to unreachable
objects due to aborted transactions, we trigger one collection at the end of
the class preinitialization phase.

Since the transaction is held by the runtime and all compilation threads share
the same runtime, we need to ensure only one compilation thread has exclusive
access to the runtime. To workaround this issue, we force class initialization
phase to run with only one thread. Note this is only done when generating image
so application compilation is not impacted. This issue will be addressed in a
separate CL.

Bug: 9676614
Change-Id: I221910a9183a5ba6c2b99a277f5a5a68bc69b5f9
0177e53ea521ad58b70c305700dab32f1ac773b7 12-Feb-2014 Ian Rogers <irogers@google.com> Work in the direction of hard float quick ABIs.

Pass a shorty to ArtMethod::Invoke so that register setup can use it.
Document x86-64 ABI.
Add extra debug output for one JNI native method registration fails, namely a
dump of the Class and its dex file's location.
Add hack to get testing of OatMethod's without GC maps working in 64bit.

Change-Id: Ic06b68e18eac33637df2caf5e7e775ff95ae70f3
83c8ee000d525017ead8753fce6bc1020249b96a 28-Jan-2014 Mathieu Chartier <mathieuc@google.com> Add root types and thread id to root visiting.

Enables us to pass the root type and thread id to hprof.

Bug: 12680863
Change-Id: I6a0f1f9e3aa8f9b4033d695818ae7ca3460d67cb
412c7fced915fc8d4d5e4166e977d55c809168a6 07-Feb-2014 Mathieu Chartier <mathieuc@google.com> Make debugger / jdwp compaction safe.

Fixed GetInstances, GetReferringObjects, CountInstances to use
VisitObjects instead of the live bitmap.

We now treat the object registry as system weaks and update the
objects when/if they move. Also added the recent_allocation_records_
as roots.

Bug: 12936165

Change-Id: I615c289efbf2977ceab5c4ffa73d216d799e6e33
ef7d42fca18c16fbaf103822ad16f23246e2905d 06-Jan-2014 Ian Rogers <irogers@google.com> Object model changes to support 64bit.

Modify mirror objects so that references between them use an ObjectReference
value type rather than an Object* so that functionality to compress larger
references can be captured in the ObjectRefererence implementation.
ObjectReferences are 32bit and all other aspects of object layout remain as
they are currently.

Expand fields in objects holding pointers so they can hold 64bit pointers. Its
expected the size of these will come down by improving where we hold compiler
meta-data.
Stub out x86_64 architecture specific runtime implementation.
Modify OutputStream so that reads and writes are of unsigned quantities.
Make the use of portable or quick code more explicit.
Templatize AtomicInteger to support more than just int32_t as a type.
Add missing, and fix issues relating to, missing annotalysis information on the
mutator lock.
Refactor and share implementations for array copy between System and uses
elsewhere in the runtime.
Fix numerous 64bit build issues.

Change-Id: I1a5694c251a42c9eff71084dfdd4b51fff716822
0376e6b62bfb43b515b791f0a7afed2d0d8030bc 06-Feb-2014 Sebastien Hertz <shertz@google.com> Fix JDWP thread crash.

Fix a crash happenning when JDWP thread attempts to process incoming packets
from a closed socket. It happens when the runtime shuts down while JDWP thread
is still running and waiting for incoming JDWP packets.

When we close the JDWP connection from runtime destructor, we wake up the JDWP
thread. To avoid this, we call Dbg::Dispose before closing the connection.

Bug: 12578041
Change-Id: I8d03478b6c3f5f49e08899d476f292b7a401d5f3
65637ebbb3c5bdf3f287a76df29a0340c10414c8 10-Jan-2014 Sebastien Hertz <shertz@google.com> Fix JDWP IsCollected command handling.

Update the handling of the JDWP IsCollected command for 'null' object id and
invalid object id.

We follow the RI where 'null' object id triggers an INVALID_OBEJCT error but
an invalid object id does not trigger error and return 'true' result.

Also fix handling of 'null' object id to avoid confusion with valid object id.
We used to rely on ObjectRegistry::Get returning NULL to detect null object id
(in which case we return an INVALID_OBJECT error). The issue is this method
may also return NULL for a valid object id if the corresponding object has
been collected. In this case, we must not return any JDWP error and the result
of the command should be 'true' meaning the object identified by the given id
has been collected.

Bug: 12221035
Change-Id: I013f3759bac7cf5b1e9ee3e8c0d1bb2a11f1b654
138dbfc3336e379d74d157086f69a0fbe830089b 04-Dec-2013 Sebastien Hertz <shertz@google.com> Selective deoptimization.

Update the instrumentation to allow selective deoptimization.

Separate instrumentation listener registration from stubs configuration. A
listener is now responsible for configuring the appropriate stubs.
- The method tracing listener installs instrumentation entry/exit stubs or
the interpreter depending on the accuracy of events we want (controlled by
kDeoptimizeForAccurateMethodEntryExitListeners).
- The debugger registers itself as an instrumentation listener but does not
modify methods entrypoints. It only does this on demand when deoptimizing one
method or all the methods.

The selective deoptimization is used for breakpoint only. When a breakpoint is
requested, the debugger deoptimizes this method by setting its entrypoint to
the interpreter stub. As several breakpoints can be set on the same method, we
deoptimize only once. When the last breakpoint on a method is removed, we
reoptimize it by restoring the original entrypoints.

The full deoptimization is used for method entry, method exit and single-step
events. When one of these events is requested, we force eveything to run with
the interpreter (except native and proxy methods). When the last of these
events is removed, we restore all methods entrypoints except those which are
currently deoptimized.

Deoptimizing a method requires all mutator threads be suspended in order to
walk each thread's stack and ensure no code is actually executing while we
modify methods entrypoints. Suspending all the threads requires to not hold
any lock.
In the debugger, we deoptimize/undeoptimize when the JDWP event list changes
(add or remove a breakpoint for instance). During the update, we need to hold
the JDWP event list lock. This means we cannot suspend all the threads at this
time.
In order to deal with these constraints, we support a queue of deoptimization
requests. When an event needs selective/full deoptimization/undeoptimization,
we save its request in the queue. Once we release the JDWP event list lock, we
suspend all the threads, process this queue and finally resume all the threads.
This is done in Dbg::ManageDeoptimization. Note: threads already suspended
before doing this remain suspended so we don't "break" debugger suspensions.

When we deoptimize one method or every method, we need to browse each thread's
stack to install instrumentation exit PC as return PC and save information in
the instrumentation stack frame. Now we can deoptimize multiple times during
the execution of an application, we need to preserve exisiting instrumentation
frames (which is the result of a previous deoptimization). This require to push
new instrumentation frames before existing ones so we don't corrupt the
instrumentation stack frame while walking the stack.

Bug: 11538162
Change-Id: I477142df17edf2dab8ac5d879daacc5c08a67c39
e96060aa2483529d087031f7cdcc0405f1ef9218 11-Dec-2013 Sebastien Hertz <shertz@google.com> Manage JDWP errors related to garbage collection.

Returns INVALID_OBJECT error in case of invalid object ID or null object ID in
commands ObjectReference.DisableCollection, ObjectReference.EnableCollection
and ObjectReference.IsCollected.

Note: JDWP specs do not state ObjectReference.EnableCollection must return any
error code. We choose to be more strict so these three commands all behave the
same.

Change-Id: I06fb75b75f7d33cf4d23e121d9541bfd70b778bb
0630ab5239a7d7be24dedbc3f66c822332446fc3 28-Nov-2013 Sebastien Hertz <shertz@google.com> Fix null argument handling during invoke from JDWP.

Fix a crash when passing null argument to a JDWP invoke.

Change-Id: I167f93f3a411f0de8458db3ba5bed3169d557ee9
c528dba35b5faece51ca658fc008b688f8b690ad 26-Nov-2013 Mathieu Chartier <mathieuc@google.com> Enable moving classes.

Slight reduction in Zygote size, memory savings are in the noise.
Before: Zygote size: 8739224
After: Zygote size: 8733568

Fixed a bug where we didn't set the concurrent start bytes after
switching the allocator from bump pointer to ROSAlloc in the
zygote. This caused excessive memory usage.

Added the method verifiers as roots to fix an issue caused by
RegTypes holding a Class*.

Added logic to clear card table in the SemiSpace collector, this
reduces DalvikOther from ~2400k -> ~1760k when using the SemiSpace
collector.

Added a missing lock to the timing loggers which caused a rare
one time crash in std::set.

Bug: 11771255
Bug: 8499494
Bug: 10802951

Change-Id: I99d2b528cd51c1c5ed7012e3220b3aefded680ae
123756a041baf8421ed933312605daa5ef082f6f 27-Nov-2013 Sebastien Hertz <shertz@google.com> Fix JDWP class-only modifier.

Fix Dbg::MatchType which is used for class-only and exception-only modifiers.

Also fix crash happening when notifying an exception. A debugger may walk the
stack of the current thread so we need to keep the instrumentation stack frame
synced with the native stack.

Bug: 11856587
Change-Id: Ibf95f8a83ce9ee640abf945e498b42cc88ea92a0
87118ed6f3f99e7df33214c277cf200a7b9a7499 26-Nov-2013 Sebastien Hertz <shertz@google.com> Fix JDWP single-step removal.

Change-Id: I4b977ea7c60b32723009e571269ca5fc1c6e264e
d38667a055d507492fd05f78519a7e1f0b85ea03 25-Nov-2013 Sebastien Hertz <shertz@google.com> Minor field name cleanup in debugger.

Use the same naming convention for all fields of DebugInvokeReq structure.

Change-Id: Ieaf65eef592f96efa47975eef15334279ed4fc8a
cbb2d20bea2861f244da2e2318d8c088300a3710 15-Nov-2013 Mathieu Chartier <mathieuc@google.com> Refactor allocation entrypoints.

Adds support for switching entrypoints during runtime. Enables
addition of new allocators with out requiring significant copy
paste. Slight speedup on ritzperf probably due to more inlining.

TODO: Ensuring that the entire allocation path is inlined so
that the switch statement in the allocation code is optimized
out.

Rosalloc measurements:
4583
4453
4439
4434
4751

After change:
4184
4287
4131
4335
4097

Change-Id: I1352a3cbcdf6dae93921582726324d91312df5c9
61b7f1b05d1fe12d4009316263bf990903e4edff 15-Nov-2013 Sebastien Hertz <shertz@google.com> Move single-step control into thread.

This CL moves single-step control into the Thread structure. This is stored in
Thread::single_step_control_ member. This allows to support single-stepping of
multiple threads at the same time.

Since each thread holds its single-step information, we no longer need to use
the breakpoint lock to support single-stepping. It helps reduce lock contention
on this lock while debugging.

All JDWP tests passed on the host and on the target with this CL.

Bug: 11667502
Change-Id: I886d5c8c625ca5a072803e296c32eec5f7e9e82d
579b02416e05e32e535126e1ed61613a2cdb030e 18-Nov-2013 Jeff Hao <jeffhao@google.com> Add support for JDWP METHOD_EXIT_WITH_RETURN_VALUE events.

Bug: 11569539
Change-Id: Ibc7a80df83470ffd726d73695a05f4938248f292
51db44a194bafc3810a41164a8b39614f10e79df 19-Nov-2013 Sebastien Hertz <shertz@google.com> Propagate 'this_object' for method unwind event.

Propagates the 'this_object' to InstrumentationListener::MethodUnwind callback.

Change-Id: I12561f1a611b8399b94e669f9b8a6eaaf1a58631
cf58d4adf461eb9b8e84baa8019054c88cd8acc6 26-Sep-2013 Hiroshi Yamauchi <yamauchi@google.com> A custom 'runs-of-slots' memory allocator.

Bug: 9986565
Change-Id: I0eb73b9458752113f519483616536d219d5f798b
b7cefc7f5cac99a62fd4e662c1bdeec750434e28 14-Nov-2013 Jeff Hao <jeffhao@google.com> Put arguments first in debugger variable table and fix name bug.

Bug: 11569468

Change-Id: I63d45427ded0937c3ab2456fe5cec22da5558e53
590fee9e8972f872301c2d16a575d579ee564bee 13-Sep-2013 Mathieu Chartier <mathieuc@google.com> Compacting collector.

The compacting collector is currently similar to semispace. It works by
copying objects back and forth between two bump pointer spaces. There
are types of objects which are "non-movable" due to current runtime
limitations. These are Classes, Methods, and Fields.

Bump pointer spaces are a new type of continuous alloc space which have
no lock in the allocation code path. When you allocate from these it uses
atomic operations to increase an index. Traversing the objects in the bump
pointer space relies on Object::SizeOf matching the allocated size exactly.

Runtime changes:
JNI::GetArrayElements returns copies objects if you attempt to get the
backing data of a movable array. For GetArrayElementsCritical, we return
direct backing storage for any types of arrays, but temporarily disable
the GC until the critical region is completed.

Added a new runtime call called VisitObjects, this is used in place of
the old pattern which was flushing the allocation stack and walking
the bitmaps.

Changed image writer to be compaction safe and use object monitor word
for forwarding addresses.

Added a bunch of added SIRTs to ClassLinker, MethodLinker, etc..

TODO: Enable switching allocators, compacting on background, etc..

Bug: 8981901

Change-Id: I3c886fd322a6eef2b99388d19a765042ec26ab99
fa82427c68b09f4aedbee319dc71579afbfc66f5 06-Nov-2013 Ian Rogers <irogers@google.com> Fix oatdump and valgrind.

Bug: 11531382
Move allocation instrumentation out of runtime into instrumentation. Don't
attempt to suspend threads in unstarted runtimes.
Make indentation support sputc returning eof, on which it will sync and try
again. A further failure likely means the disk is full.
Move the dump-oat output directory to be art as now there's too much output to
fit all the dump-oat data in our standard /tmp.

Change-Id: I8ea848ace318552c180e2efa46570288ff1ca62c
dfb325e0ddd746cd8f7c2e3723b3a573eb7cc111 30-Oct-2013 Ian Rogers <irogers@google.com> Don't use UTF16 length as length for MUTF8.

Bug 11367555.

Change-Id: Ia0b07072a1a49d435c3b71ed9a668b316b7ff5d8
f2910eef247b45ce1d489e323b36b5de6b6157aa 19-Oct-2013 Sebastien Hertz <shertz@google.com> Fix JDWP line table output.

Bug: 11238911
Change-Id: I952fba04393b23b1d42dc6a2d22cd583ce2512ce
d9c4fc94fa618617f94e1de9af5f034549100753 02-Oct-2013 Ian Rogers <irogers@google.com> Inflate contended lock word by suspending owner.

Bug 6961405.
Don't inflate monitors for Notify and NotifyAll.
Tidy lock word, handle recursive lock case alongside unlocked case and move
assembly out of line (except for ARM quick). Also handle null in out-of-line
assembly as the test is quick and the enter/exit code is already a safepoint.
To gain ownership of a monitor on behalf of another thread, monitor contenders
must not hold the monitor_lock_, so they wait on a condition variable.
Reduce size of per mutex contention log.
Be consistent in calling thin lock thread ids just thread ids.
Fix potential thread death races caused by the use of FindThreadByThreadId,
make it invariant that returned threads are either self or suspended now.

Code size reduction on ARM boot.oat 0.2%.
Old nexus 7 speedup 0.25%, new nexus 7 speedup 1.4%, nexus 10 speedup 2.24%,
nexus 4 speedup 2.09% on DeltaBlue.

Change-Id: Id52558b914f160d9c8578fdd7fc8199a9598576a
d91d6d6a80748f277fd938a412211e5af28913b1 26-Sep-2013 Ian Rogers <irogers@google.com> Introduce Signature type to avoid string comparisons.

Method resolution currently creates strings to then compare with strings formed
from methods in other dex files. The temporary strings are purely created for
the sake of comparisons. This change creates a new Signature type that
represents a method signature but not as a string. This type supports
comparisons and so can be used when searching for methods in resolution.

With this change malloc is no longer the hottest method during dex2oat (now its
memset) and allocations during verification have been reduced. The verifier is
commonly what is populating the dex cache for methods and fields not declared
in the dex file itself.

Change-Id: I5ef0542823fbcae868aaa4a2457e8da7df0e9dae
3b4c18933c24b8a33f38573c2ebcdb9aa16efeb5 13-Sep-2013 Hiroshi Yamauchi <yamauchi@google.com> Split the allocation path into 'instrumented' and 'uninstrumented'
ones.

The instrumented path is equivalent to the existing allocation path
that checks for three instrumentation mechanisms (the debugger
allocation tracking, the runtime allocation stats collection, and
valgrind) for every allocation. The uinstrumented path does not
perform these checks. We use the uninstrumented path by default and
enable the instrumented path only when any of the three mechanisms is
enabled. The uninstrumented version of Heap::AllocObject() is inlined.

This change improves the Ritz MemAllocTest by ~4% on Nexus 4 and ~3%
on Host/x86.

Bug: 9986565
Change-Id: I3e68dfff6789d77bbdcea98457b694e1b5fcef5f
fc0e94bed3f88ed7e50854fd8dfaf5dcb345250f 24-Sep-2013 Ian Rogers <irogers@google.com> StringPiece clean up.

Profile guided clean up.
Try to avoid creating StringPieces with the contents of a dex file where
the length is known.
Try to avoid RegTypeCache::FromDescriptor when there's a class available.
Make ConstantType::ConstantValue inlinable.
Saving of about 50ms from a 2 threaded ThinkFree compile on host.

Change-Id: I47a12c3c76f46e2c9805be1c3a3e3870fe1f5d85
3e47a748eb646b8d2fc8e8c4f11b270d9ae2c607 10-Sep-2013 Ruben Brunk <rubenbrunk@google.com> Remove dependency on JNIHelp header side effects.

Bug: 10680559
Change-Id: I2f8ab34803a4554dac35c941ed58c0c845754655
920af3e556c730a5fbdab90a6d0ec1a2dbe8940b 29-Aug-2013 Jeff Hao <jeffhao@google.com> Fix thread status in THST chunk to use JDWP thread state.

Bug: 10492287

Change-Id: I830a2ce71d02c5b09c7040583be98d818eef9385
02e25119b15a6f619f17db99f5d05124a5807ff3 15-Aug-2013 Mathieu Chartier <mathieuc@google.com> Fix up TODO: c++0x, update cpplint.

Needed to update cpplint to handle const auto.

Fixed a few cpplint errors that were being missed before.

Replaced most of the TODO c++0x with ranged based loops. Loops which
do not have a descriptive container name have a concrete type instead
of auto.

Change-Id: Id7cc0f27030f56057c544e94277300b3f298c9c5
ea46f950e7a51585db293cd7f047de190a482414 30-Jul-2013 Brian Carlstrom <bdc@google.com> Refactor java.lang.reflect implementation

Cherry-picked from commit ed41d5c44299ec5d44b8514f6e17f802f48094d1.

Move to ArtMethod/Field instead of AbstractMethod/Field and have
java.lang.reflect APIs delegate to ArtMethod/ArtField.

Bug: 10014286.

Change-Id: Iafc1d8c5b62562c9af8fb9fd8c5e1d61270536e7
834b394ee759ed31c5371d8093d7cd8cd90014a8 31-Jul-2013 Brian Carlstrom <bdc@google.com> Merge remote-tracking branch 'goog/dalvik-dev' into merge-art-to-dalvik-dev

Change-Id: I323e9e8c29c3e39d50d9aba93121b26266c52a46
166db04e259ca51838c311891598664deeed85ad 26-Jul-2013 Ian Rogers <irogers@google.com> Move assembler out of runtime into compiler/utils.

Other directory layout bits of clean up. There is still work to separate quick
and portable in some files (e.g. argument visitor, proxy..).

Change-Id: If8fecffda8ba5c4c47a035f0c622c538c6b58351
7934ac288acfb2552bb0b06ec1f61e5820d924a4 26-Jul-2013 Brian Carlstrom <bdc@google.com> Fix cpplint whitespace/comments issues

Change-Id: Iae286862c85fb8fd8901eae1204cd6d271d69496
f52935278fca8c7aa220543eef4544e3d1105d91 19-Jul-2013 Brian Carlstrom <bdc@google.com> Move JDWP to std::vector<iovec> to remove runtime/arrays warning

Change-Id: I8494a25a65de4ebac2b1f4f41c0f5eedf117b7ac
2d88862f0752a7a0e65145b088f49dabd49d4284 19-Jul-2013 Brian Carlstrom <bdc@google.com> Fixing cpplint readability/casting issues

Change-Id: I6821da0e23737995a9b884a04e9b63fac640cd05
df62950e7a32031b82360c407d46a37b94188fbb 18-Jul-2013 Brian Carlstrom <bdc@google.com> Fix cpplint whitespace/parens issues

Change-Id: Ifc678d59a8bed24ffddde5a0e543620b17b0aba9
0cd7ec2dcd8d7ba30bf3ca420b40dac52849876c 18-Jul-2013 Brian Carlstrom <bdc@google.com> Fix cpplint whitespace/blank_line issues

Change-Id: Ice937e95e23dd622c17054551d4ae4cebd0ef8a2
93ba893c20532990a430741e0a97212900094e8c 18-Jul-2013 Brian Carlstrom <bdc@google.com> Fix cpplint runtime/explicit issues

Change-Id: I352ba0b427f1ff9b22887693952b180eae0839ba
7940e44f4517de5e2634a7e07d58d0fb26160513 12-Jul-2013 Brian Carlstrom <bdc@google.com> Create separate Android.mk for main build targets

The runtime, compiler, dex2oat, and oatdump now are in seperate trees
to prevent dependency creep. They can now be individually built
without rebuilding the rest of the art projects. dalvikvm and jdwpspy
were already this way. Builds in the art directory should behave as
before, building everything including tests.

Change-Id: Ic6b1151e5ed0f823c3dd301afd2b13eb2d8feb81