16 Commits

Author SHA1 Message Date
Orion Hodson
cc8b8ca466 Adds ToBits helper method to convert instructon opcode enum to bits
Bug: 142948359
Test: atest dex-builder-test
Change-Id: Ic1c02e74dd787107c08bd34ca861eee89d6d1423
2019-11-04 16:58:26 +00:00
Orion Hodson
59d07201d9 Switch to slicer DEX opcode definitions
Removes dependency on art/libdexfile and uses equivalent definitions
from the dexter/slicer library.

Bug: 133140750
Bug: 142948359
Test: m
Test: atest dex-builder-test \
            view-compiler-tests \
            android.view.cts.PrecompiledLayoutTest
Change-Id: I49562ac4867254ecde287b828f76d23cb5132dd0
2019-11-01 11:38:56 +00:00
Eric Holk
5c6a1a516b Refactor DexViewBuilder
The code was previously pretty messy and hard to follow. This reworks some
things to make it more manageable. Among the changes:

* Pull out fragments of code into their own method, so the high level steps are
  more apparent in methods like DexViewBuilder::Start.
* Pull frequently used types into global constants in dex_layout_compiler.cc.
* Rework register handling to track liveness so a strict stack discipline is no
  longer needed.

Change-Id: Idb4b41f88c96a1ac4efb2c7b9bed05c2de0da999
2019-09-18 17:04:50 -07:00
Eric Holk
f3b9589e7b [view compiler] Add DexBuilder support for getting and setting instance fields
Bug: 111895153
Change-Id: I5fa2936501c79e30a66f3863b76229ec83433928
2019-07-30 14:47:06 -07:00
Eric Holk
70445d0d89 [viewcompiler] Add support for static field put to DexBuilder
Bug: 111895153
Change-Id: I12b38fa520790debec545d7d1f6b3522a65ce03b
2019-07-26 09:46:18 -07:00
Eric Holk
3092f99ae6 [viewcompiler] Add static field get instructions to DexBuilder
This allows us to generate code that can read static fields in a class. Once we
include several other field operations, we will be able to generate more
specialized inflation code in the view compiler.

Bug: 111895153
Change-Id: Ia11195b1cea6d5a3ddbc60d972922586a062c853
2019-07-26 09:42:41 -07:00
Eric Holk
d1b4383660 [viewcompiler] Support more than 16 registers in invoke instructions
This was causing the viewcompiler to crash on deeper layout hierarchies.

We fix this by reserving several scratch registers. When an invoke instruction
uses registers that don't fit in a 4-bit field, we move all of these values into
the scratch registers and use an invoke/range instruction instead. The scratch
registers are all above the highest allocated register, so they are guaranteed
not to clobber meaningful values.

Supporting more registers for invoke also required supporting
register-to-register moves, which some how we'd gotten by without so far.

Finally, to make viewcompiler fail more loudly when things go wrong, many
DCHECKs have been changed to CHECKs.

Bug: 123517491
Test: atest
Change-Id: I9eb7c9bcf1fc7d713e664b331804bdcddafc95a4
2019-01-31 15:15:14 -08:00
Chih-Hung Hsieh
81aff0fbab Fix/suppress startop google-explicit-constructor warnings
* Add explicit to conversion constructors/operators

Bug: 28341362
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,google-explicit-constructor
Change-Id: I9e7b929cfa65c68f4cdb4710c1c5c6760d56e4d5
2018-12-20 13:53:28 -08:00
Eric Holk
44d8cdfb06 [view-compiler] DexBuilder: Add check-cast instruction
Bug: 111895153
Test: atest

Change-Id: I767e56713fab6beaa6970e58c4fc4d3560cc1304
2018-12-18 16:47:05 +00:00
Eric Holk
c69449d95c [view-compiler] DexBuilder: Add more instructions
This CL adds the ability to generate code that calls static and virtual methods
which return objects, as well as the not-equal-to-zero comparison operator.

Bug: 111895153
Change-Id: I4ae9b3cb2edc6540671112b73c02bf6380d23051
2018-12-14 09:14:12 -08:00
Eric Holk
1c0f3f099c [view_compiler] cleanup: Use format-specific bytecode encoding functions
This change corrals most of the bit shifting and ORing needed to encode Dex
instructions into EncodeXXX functions that follow the naming scheme at
https://source.android.com/devices/tech/dalvik/instruction-formats. Overall, it
makes the code easier to follow and probably even less error prone because we
only have to make the format right in one place.

Bug: 111895153
Change-Id: I902ec3c8bca6b5dc4ad900503af7aef58d4bbf5f
2018-11-15 17:44:03 +00:00
Eric Holk
b392758a65 [view_compiler] DexBuilder: Add support for new and calling constructors
This change also includes support for calling methods with more that one
argument. In fact, we can go up to four.

Bug: 111895153
Change-Id: I49472171cefcf57cdfce2ac4d41646ed4df29074
2018-11-13 13:47:29 -08:00
Eric Holk
3cc4afc610 [view_compiler] DexBuilder: add support for string literals and null pointers
Bug: 111895153
Change-Id: If6bdd9a280f6feed175be4da57733f3442e6dd14
2018-11-13 13:41:56 -08:00
Eric Holk
d62c5aa954 [view compiler] Add conditional branch instruction
This CL adds support for the if-eqz instruction. It should be easy to add
additional comparisons as needed.

This also introduces a new kind of Value called a Label. Labels may be created
any time and then must be bound to a location in code at some point. References
to labels are tracked, and when a label is bound all references are patched to
refer to the concrete address.

Bug: 111895153
Change-Id: I15424aec75425004f0f1f4bbc6e760bac3a6c7de
2018-11-10 00:46:07 +00:00
Eric Holk
faefd4f6c7 [view-compiler] Support method declaration and invocation in Dex builder
The Dex builder can now generate calls to methods (although not in all forms
yet). To help do this, we add a new virtual Instruction and Value class. This is
needed to generate code with values that are not known until the entire method
has been generated. In particular, we can now refer to function parameters.

The test method now accepts a String and returns the the length of the string.

Bug: 111895153
Change-Id: I11d52b083ae51d8151fccb1a65e45d40ff05fd81
2018-11-07 00:05:48 +00:00
Eric Holk
acf3fbde82 Move startop/tools/view_compiler to startop/view_compiler
This is planned to ship on device, so by convention the view_compiler should not
be in a tools directory.

Change-Id: I0eb03812d77ec38edc3908725acb40bacb345ecd
2018-10-22 11:13:42 -07:00