} FieldMethodInfo;
/*
- * Get 2 little-endian bytes.
- */
+ * Get 2 little-endian bytes.
+ */
static inline u2 get2LE(unsigned char const* pSrc)
{
return pSrc[0] | (pSrc[1] << 8);
-}
+}
/*
- * Get 4 little-endian bytes.
- */
+ * Get 4 little-endian bytes.
+ */
static inline u4 get4LE(unsigned char const* pSrc)
{
return pSrc[0] | (pSrc[1] << 8) | (pSrc[2] << 16) | (pSrc[3] << 24);
-}
+}
/*
* Converts a single-character primitive type into its human-readable
{
#define NUM_FLAGS 18
static const char* kAccessStrings[kAccessForMAX][NUM_FLAGS] = {
- {
+ {
/* class, inner class */
"PUBLIC", /* 0x0001 */
"PRIVATE", /* 0x0002 */
if (triesSize == 0) {
printf(" catches : (none)\n");
return;
- }
+ }
printf(" catches : %d\n", triesSize);
u4 start = pTry->startAddr;
u4 end = start + pTry->insnCount;
DexCatchIterator iterator;
-
+
printf(" 0x%04x - 0x%04x\n", start, end);
dexCatchIteratorInit(&iterator, pCode, pTry->handlerOff);
for (;;) {
DexCatchHandler* handler = dexCatchIteratorNext(&iterator);
const char* descriptor;
-
+
if (handler == NULL) {
break;
}
-
- descriptor = (handler->typeIdx == kDexNoIndex) ? "<any>" :
+
+ descriptor = (handler->typeIdx == kDexNoIndex) ? "<any>" :
dexStringByTypeIdx(pDexFile, handler->typeIdx);
-
+
printf(" %s -> 0x%04x\n", descriptor,
handler->address);
}
/*
* Dump the positions list.
*/
-void dumpPositions(DexFile* pDexFile, const DexCode* pCode,
+void dumpPositions(DexFile* pDexFile, const DexCode* pCode,
const DexMethod *pDexMethod)
{
printf(" positions : \n");
- const DexMethodId *pMethodId
+ const DexMethodId *pMethodId
= dexGetMethodId(pDexFile, pDexMethod->methodIdx);
const char *classDescriptor
= dexStringByTypeIdx(pDexFile, pMethodId->classIdx);
const char *signature)
{
printf(" 0x%04x - 0x%04x reg=%d %s %s %s\n",
- startAddress, endAddress, reg, name, descriptor,
+ startAddress, endAddress, reg, name, descriptor,
signature);
}
{
printf(" locals : \n");
- const DexMethodId *pMethodId
+ const DexMethodId *pMethodId
= dexGetMethodId(pDexFile, pDexMethod->methodIdx);
- const char *classDescriptor
+ const char *classDescriptor
= dexStringByTypeIdx(pDexFile, pMethodId->classIdx);
dexDecodeDebugInfo(pDexFile, pCode, classDescriptor, pMethodId->protoIdx,
pMethInfo->name = dexStringById(pDexFile, pMethodId->nameIdx);
pMethInfo->signature = dexCopyDescriptorFromMethodId(pDexFile, pMethodId);
- pMethInfo->classDescriptor =
+ pMethInfo->classDescriptor =
dexStringByTypeIdx(pDexFile, pMethodId->classIdx);
return true;
}
insnWidth = 2 + get2LE((const u1*)(insns+1)) * 4;
} else if (instr == kArrayDataSignature) {
int width = get2LE((const u1*)(insns+1));
- int size = get2LE((const u1*)(insns+2)) |
+ int size = get2LE((const u1*)(insns+2)) |
(get2LE((const u1*)(insns+3))<<16);
- // The plus 1 is to round up for odd size and width
+ // The plus 1 is to round up for odd size and width
insnWidth = 4 + ((size * width) + 1) / 2;
} else {
opCode = instr & 0xff;
printf("Trouble reading class data (#%d)\n", idx);
goto bail;
}
-
+
classDescriptor = dexStringByTypeIdx(pDexFile, pClassDef->classIdx);
/*
*/
/*
* Dalvik opcode names.
- */
+ */
#ifndef _DEXDUMP_OPCODENAMES
#define _DEXDUMP_OPCODENAMES
fprintf(stderr, "Trouble reading class data\n");
return;
}
-
+
if (pClassDef->sourceFileIdx == 0xffffffff) {
fileName = NULL;
} else {
fileName = dexStringById(pDexFile, pClassDef->sourceFileIdx);
}
-
- /*
+
+ /*
* TODO: Each class def points at a sourceFile, so maybe that
* should be printed out. However, this needs to be coordinated
* with the tools that parse this output.
*/
-
+
for (i = 0; i < (int) pClassData->header.directMethodsSize; i++) {
dumpMethod(pDexFile, fileName, &pClassData->directMethods[i], i);
}
no arrays of <code>long</code> or <code>double</code>, but reference
types are acceptable). The constructed
instance is stored as a "result" in the same way that the method invocation
- instructions store their results, so the constructed instance must
+ instructions store their results, so the constructed instance must
be moved to a register with an immediately subsequent
<code>move-result-object</code> instruction (if it is to be used).</td>
</tr>
float result = a % b;
</td>
<td>Floating point remainder after division. This function is different
- than IEEE 754 remainder and is defined as
+ than IEEE 754 remainder and is defined as
<code>result == a - roundTowardZero(a / b) * b</code>.
</td>
</tr>
double result = a % b;
</td>
<td>Floating point remainder after division. This function is different
- than IEEE 754 remainder and is defined as
+ than IEEE 754 remainder and is defined as
<code>result == a - roundTowardZero(a / b) * b</code>.
</td>
</tr>
<title>Dalvik bytecode constraints</title>
<link rel=stylesheet href="dalvik-constraints.css">
</head>
-
+
<body>
-
+
<h1>Dalvik bytecode constraints</h1>
-
+
<!--
<h1>General integrity constraints</h1>
<th>
Identifier
</th>
-
+
<th>
Description
</th>
</tr>
-
+
<tr>
<td>
A1
</td>
-
+
<td>
The magic number of the DEX file must be "dex\n035\0".
</td>
<td>
A1
</td>
-
+
<td>
The checksum must be an Adler-32 checksum of the whole file contents
except magic and checksum field.
The header_size must have the value 0x70.
The endian_tag must have either the value ENDIAN_CONSTANT or
-REVERSE_ENDIAN_CONSTANT.
-
+REVERSE_ENDIAN_CONSTANT.
+
For each of the link, string_ids, type_ids, proto_ids, field_ids, method_ids, class_defs
and data sections, the offset and size fields must be either both zero or both
non-zero. In the latter case, the offset must be four-byte-aligned.
All offset fields in the header except map_off must be four-byte-aligned.
-
+
The map_off field must be either zero or point into the data section. In the
latter case, the data section must exist.
...
-->
-
+
<h2>
Static constraints
</h2>
They usually can be checked without employing control or data-flow analysis
techniques.
</p>
-
+
<table>
<tr>
<th>
Identifier
</th>
-
+
<th>
Description
</th>
-
+
<th>
Spec equivalent
</th>
</tr>
-
+
<tr>
<td>
A1
</td>
-
+
<td>
- The <code>insns</code> array must not be empty.
+ The <code>insns</code> array must not be empty.
</td>
-
+
<td>
4.8.1.1
</td>
</tr>
-
+
<tr>
<td>
A2
</td>
-
+
<td>
The first opcode in the <code>insns</code> array must have index zero.
</td>
-
+
<td>
4.8.1.3
</td>
</tr>
-
+
<tr>
<td>
A3
</td>
-
+
<td>
The <code>insns</code> array must only contain valid Dalvik opcodes.
</td>
-
+
<td>
4.8.1.4
</td>
</tr>
-
+
<tr>
<td>
A4
</td>
-
+
<td>
The index of instruction <code>n+1</code> must equal the index of
instruction <code>n</code> plus the length of instruction
<code>n</code>, taking into account possible operands.
</td>
-
+
<td>
4.8.1.5
</td>
</tr>
-
+
<tr>
<td>
A5
</td>
-
+
<td>
The last instruction in the <code>insns</code> array must end at index
- <code>insns_size-1</code>.
+ <code>insns_size-1</code>.
</td>
-
+
<td>
4.8.1.6
</td>
</tr>
-
+
<tr>
<td>
A6
</td>
-
+
<td>
All <code>goto</code> and <code>if-<kind></code> targets must
be opcodes within in the same method.
</td>
-
+
<td>
4.8.1.7
</td>
</tr>
-
+
<tr>
<td>
A7
</td>
-
+
<td>
All targets of a <code>packed-switch</code> instruction must be
opcodes within in the same method. The size and the list of targets
- must be consistent.
+ must be consistent.
</td>
-
+
<td>
4.8.1.8
</td>
</tr>
-
+
<tr>
<td>
A8
</td>
-
+
<td>
All targets of a <code>sparse-switch</code> instruction must be
opcodes within in the same method. The corresponding table must be
- consistent and sorted low-to-high.
+ consistent and sorted low-to-high.
</td>
-
+
<td>
4.8.1.9
</td>
</tr>
-
+
<tr>
<td>
A9
</td>
-
+
<td>
The <code>B</code> operand of the <code>const-string</code> and
<code>const-string/jumbo</code> instructions must be a valid index
into the string constant pool.
</td>
-
+
<td>
4.8.1.10
</td>
<td>
A10
</td>
-
+
<td>
The <code>C</code> operand of the <code>iget<kind></code> and
<code>iput<kind></code> instructions must be a valid index into
the field constant pool. The referenced entry must represent an
instance field.
</td>
-
+
<td>
4.8.1.12
</td>
</tr>
-
+
<tr>
<td>
A11
</td>
-
+
<td>
The <code>C</code> operand of the <code>sget<kind></code> and
<code>sput<kind></code> instructions must be a valid index into
the field constant pool. The referenced entry must represent a static
field.
</td>
-
+
<td>
4.8.1.12
</td>
<td>
A12
</td>
-
+
<td>
The <code>C</code> operand of the <code>invoke-virtual</code>,
<code>invoke-super</code>, <code<invoke-direct</code> and
<code>invoke-static</code> instructions must be a valid index into the
method constant pool. In all cases, the referenced
- <code>method_id</code> must belong to a class (not an interface).
+ <code>method_id</code> must belong to a class (not an interface).
</td>
-
+
<td>
4.8.1.13
</td>
</tr>
-
+
<tr>
<td>
A13
</td>
-
+
<td>
The <code>B</code> operand of the <code>invoke-virtual/range</code>,
<code>invoke-super/range</code>, <code>invoke-direct/range</code>, and
<code>invoke-static/range</code> instructions must be a valid index
into the method constant pool. In all cases, the referenced
- <code>method_id</code> must belong to a class (not an interface).
+ <code>method_id</code> must belong to a class (not an interface).
</td>
-
+
<td>
4.8.1.13
</td>
<td>
A14
</td>
-
+
<td>
A method the name of which starts with a '<' must only be invoked
implicitly by the VM, not by code originating from a Dex file. The
only exception is the instance initializer, which may be invoked by
<code>invoke-direct</code>.
</td>
-
+
<td>
4.8.1.14
</td>
</tr>
-
+
<tr>
<td>
A15
</td>
-
+
<td>
The <code>C</code> operand of the <code>invoke-interface</code>
instruction must be a valid index into the method constant pool. The
referenced <code>method_id</code> must belong to an interface (not a
class).
</td>
-
+
<td>
4.8.1.15
</td>
</tr>
-
+
<tr>
<td>
A16
</td>
-
+
<td>
The <code>B</code> operand of the <code>invoke-interface/range</code>
instruction must be a valid index into the method constant pool.
The referenced <code>method_id</code> must belong to an interface (not
a class).
</td>
-
+
<td>
4.8.1.15
</td>
</tr>
-
+
<tr>
<td>
A17
</td>
-
+
<td>
The <code>B</code> operand of the <code>const-class</code>,
<code>check-cast</code>, <code>new-instance</code>, and
<code>filled-new-array/range</code> instructions must be a valid index
into the type constant pool.
</td>
-
+
<td>
4.8.1.16
</td>
</tr>
-
+
<tr>
<td>
A18
</td>
-
+
<td>
The <code>C</code> operand of the <code>instance-of</code>,
<code>new-array</code>, and <code>filled-new-array</code>
instructions must be a valid index into the type constant pool.
</td>
-
+
<td>
4.8.1.16
</td>
<td>
A19
</td>
-
+
<td>
The dimensions of an array created by a <code>new-array</code>
instruction must be less than <code>256</code>.
</td>
-
+
<td>
4.8.1.17
</td>
</tr>
-
+
<tr>
<td>
A20
</td>
-
+
<td>
The <code>new</code> instruction must not refer to array classes,
interfaces, or abstract classes.
</td>
-
+
<td>
4.8.1.18
</td>
</tr>
-
+
<tr>
<td>
A21
</td>
-
+
<td>
The type referred to by a <code>new-array</code> instruction must be
a valid, non-reference type.
</td>
-
+
<td>
4.8.1.20
</td>
</tr>
-
+
<tr>
<td>
A22
</td>
-
+
<td>
All registers referred to by an instruction in a single-width
(non-pair) fashion must be valid for the current method. That is,
their indices must be non-negative and smaller than
- <code>registers_size</code>.
+ <code>registers_size</code>.
</td>
-
+
<td>
4.8.1.21
</td>
</tr>
-
+
<tr>
<td>
A23
</td>
-
+
<td>
All registers referred to by an instruction in a double-width (pair)
fashion must be valid for the current method. That is, their indices
- must be non-negative and smaller than <code>registers_size-1</code>.
+ must be non-negative and smaller than <code>registers_size-1</code>.
</td>
-
+
<td>
4.8.1.23
</td>
</tr>
</table>
-
+
<h2>
Structural constraints
</h2>
-
+
<p>
Structural constraints are constraints on relationships between several
elements of the bytecode. They usually can't be checked without employing
<th>
Identifier
</th>
-
+
<th>
Description
</th>
-
+
<th>
Spec equivalent
</th>
</tr>
-
+
<tr>
<td>
B1
</td>
-
+
<td>
The number and types of arguments (registers and immediate values)
must always match the instruction.
</td>
-
+
<td>
4.8.2.1
</td>
</tr>
-
+
<tr>
<td>
B2
</td>
-
+
<td>
- Register pairs must never be broken up.
+ Register pairs must never be broken up.
</td>
-
+
<td>
4.8.2.3
</td>
</tr>
-
+
<tr>
<td>
B3
</td>
-
+
<td>
A register (or pair) has to be assigned first before it can be
read.
</td>
-
+
<td>
4.8.2.4
</td>
</tr>
-
+
<tr>
<td>
B4
</td>
-
+
<td>
An <code>invoke-direct</code> instruction must only invoke an instance
initializer or a method in the current class or one of its
- superclasses.
+ superclasses.
</td>
-
+
<td>
4.8.2.7
</td>
</tr>
-
+
<tr>
<td>
B5
</td>
-
+
<td>
An instance initializer must only be invoked on an uninitialized
instance.
</td>
-
+
<td>
4.8.2.8
</td>
</tr>
-
+
<tr>
<td>
B6
</td>
-
+
<td>
Instance methods may only be invoked on and instance fields may only
- be accessed on already initialized instances.
+ be accessed on already initialized instances.
</td>
-
+
<td>
4.8.2.9
</td>
</tr>
-
+
<tr>
<td>
B7
</td>
-
+
<td>
A register which holds the result of a <code>new-instance</code>code>
instruction must not be used if the same
<code>new-instance</code>code> instruction is again executed before
- the instance is initialized.
+ the instance is initialized.
</td>
-
+
<td>
4.8.2.10
</td>
</tr>
-
+
<tr>
<td>
B8
</td>
-
+
<td>
An instance initializer must call another instance initializer (same
class or superclass) before any instance members can be accessed.
Exceptions are non-inherited instance fields, which can be assigned
before calling another initializer, and the <code>Object</code> class
- in general.
+ in general.
</td>
-
+
<td>
4.8.2.11
</td>
</tr>
-
+
<tr>
<td>
B9
</td>
-
+
<td>
All actual method arguments must be assignment-compatible with their
- respective formal arguments.
+ respective formal arguments.
</td>
-
+
<td>
4.8.2.12
</td>
</tr>
-
+
<tr>
<td>
B10
</td>
-
+
<td>
For each instance method invocation, the actual instance must be
assignment-compatible with the class or interface specified in the
instruction.
</td>
-
+
<td>
4.8.2.13
</td>
</tr>
-
+
<tr>
<td>
B11
</td>
-
+
<td>
A <code>return<kind></code> instruction must match its
- method's return type.
+ method's return type.
</td>
-
+
<td>
4.8.2.14
</td>
</tr>
-
+
<tr>
<td>
B12
</td>
-
+
<td>
When accessing protected members of a superclass, the actual type of
the instance being accessed must be either the current class or one
of its subclasses.
</td>
-
+
<td>
4.8.2.15
</td>
</tr>
-
+
<tr>
<td>
B13
</td>
-
+
<td>
The type of a value stored into a static field must be
assignment-compatible with or convertible to the field's type.
</td>
-
+
<td>
4.8.2.16
</td>
</tr>
-
+
<tr>
<td>
B14
</td>
-
+
<td>
The type of a value stored into a field must be assignment-compatible
with or convertible to the field's type.
</td>
-
+
<td>
4.8.2.17
</td>
</tr>
-
+
<tr>
<td>
B15
</td>
-
+
<td>
The type of every value stored into an array must be
assignment-compatible with the array's component type.
</td>
-
+
<td>
4.8.2.18
</td>
</tr>
-
+
<tr>
<td>
B16
</td>
-
+
<td>
The <code>A</code> operand of a <code>throw</code> instruction must
- be assignment-compatible with <code>java.lang.Throwable</code>.
+ be assignment-compatible with <code>java.lang.Throwable</code>.
</td>
-
+
<td>
4.8.2.19
</td>
</tr>
-
+
<tr>
<td>
B17
</td>
-
+
<td>
The last reachable instruction of a method must either be a backwards
<code>goto</code> or branch, a <code>return</code>, or a
<code>throw</code> instruction. It must not be possible to leave the
<code>insns</code> array at the bottom.
</td>
-
+
<td>
4.8.2.20
</td>
</tr>
-
+
<tr>
<td>
B18
</td>
-
+
<td>
The unassigned half of a former register pair may not be read (is
considered invalid) until it has been re-assigned by some other
instruction.
- </td>
-
+ </td>
+
<td>
4.8.2.3, 4.8.2.4
</td>
<td>
B19
</td>
-
+
<td>
A <code>move-result<kind></code> instruction must be immediately
preceded (in the <code>insns</code> array) by an
<code><invoke-kind></code> instruction. The only exception is
the <code>move-result-object</code> instruction, which may also be
- preceded by a <code>filled-new-array</code> instruction.
+ preceded by a <code>filled-new-array</code> instruction.
</td>
-
+
<td>
-
</td>
<td>
B20
</td>
-
+
<td>
A <code>move-result<kind></code> instruction must be immediately
preceded (in actual control flow) by a matching
<code>return-<kind></code> instruction (it must not be jumped
to). The only exception is the <code>move-result-object</code>
instruction, which may also be preceded by a
- <code>filled-new-array</code> instruction.
+ <code>filled-new-array</code> instruction.
</td>
-
+
<td>
-
</td>
<td>
B21
</td>
-
+
<td>
A <code>move-exception</code> instruction must only appear as the
first instruction in an exception handler.
</td>
-
+
<td>
-
</td>
</tr>
-
+
<tr>
<td>
B22
</td>
-
+
<td>
The <code>packed-switch-data</code>, <code>sparse-switch-data</code>,
and <code>fill-array-data</code> pseudo-instructions must not be
reachable by control flow.
</td>
-
+
<td>
-
</td>
background: #eeeeff;
}
-table p {
+table p {
margin-bottom: 0pt;
}
/* for the bnf syntax sections */
-table.bnf {
+table.bnf {
background: #eeeeff;
border-color: #aaaaff;
border-style: solid;
padding-right: 6pt;
}
-table.bnf td {
+table.bnf td {
border: none;
padding-left: 6pt;
padding-right: 6pt;
padding-bottom: 1pt;
}
-table.bnf td:first-child {
+table.bnf td:first-child {
padding-right: 0pt;
width: 8pt;
}
-table.bnf td:first-child td {
+table.bnf td:first-child td {
padding-left: 0pt;
}
<tr>
<td>data_off</td>
<td>uint</td>
- <td>offset from the start of the file to the start of the
+ <td>offset from the start of the file to the start of the
<code>data</code> section.
</td>
</tr>
<td>data</td>
<td>ubyte[]</td>
<td>a series of MUTF-8 code units (a.k.a. octets, a.k.a. bytes)
- followed by a byte of value <code>0</code>. See
+ followed by a byte of value <code>0</code>. See
"MUTF-8 (Modified UTF-8) Encoding" above for details and
discussion about the data format.
<p><b>Note:</b> It is acceptable to have a string which includes
</tbody>
</table>
-<p><b>Note:</b> All elements' <code>field_id</code>s and
+<p><b>Note:</b> All elements' <code>field_id</code>s and
<code>method_id</code>s must refer to the same defining class.</p>
<h3><code>encoded_field</code> Format</h3>
<tr>
<td>debug_info_off</td>
<td>uint</td>
- <td>offset from the start of the file to the debug info (line numbers +
- local variable info) sequence for this code, or <code>0</code> if
- there simply is no information. The offset, if non-zero, should be
- to a location in the <code>data</code> section. The format of
+ <td>offset from the start of the file to the debug info (line numbers +
+ local variable info) sequence for this code, or <code>0</code> if
+ there simply is no information. The offset, if non-zero, should be
+ to a location in the <code>data</code> section. The format of
the data is specified by "<code>debug_info_item</code>" below.
</td>
</tr>
should be associated with the next positions table entry emitted by
the state machine. It is initialized in the sequence header, and may
change in positive or negative directions but must never be less than
-<code>1</code>. The <code>source_file</code> register represents the
+<code>1</code>. The <code>source_file</code> register represents the
source file that the line number entries refer to. It is initialized to
the value of <code>source_file_idx</code> in <code>class_def_item</code>.
The other two variables, <code>prologue_end</code> and
<tr>
<td>line_start</td>
<td>uleb128</td>
- <td>the initial value for the state machine's <code>line</code> register.
+ <td>the initial value for the state machine's <code>line</code> register.
Does not represent an actual positions entry.
</td>
</tr>
<code>name_idx</code>: string index of the name<br/>
<code>type_idx</code>: type index of the type
</td>
- <td>introduces a local variable at the current address. Either
+ <td>introduces a local variable at the current address. Either
<code>name_idx</code> or <code>type_idx</code> may be
<code>NO_INDEX</code> to indicate that that value is unknown.
</td>
uleb128p1 name_idx<br/>
uleb128p1 type_idx<br/>
uleb128p1 sig_idx
- </td>
+ </td>
<td><code>register_num</code>: register that will contain local<br/>
<code>name_idx</code>: string index of the name<br/>
<code>type_idx</code>: type index of the type<br/>
<td>0x05</td>
<td>uleb128 register_num</td>
<td><code>register_num</code>: register that contained local</td>
- <td>marks a currently-live local variable as out of scope at the current
+ <td>marks a currently-live local variable as out of scope at the current
address
</td>
</tr>
<td>0x07</td>
<td></td>
<td><i>(none)</i></td>
- <td>sets the <code>prologue_end</code> state machine register,
- indicating that the next position entry that is added should be
- considered the end of a method prologue (an appropriate place for
+ <td>sets the <code>prologue_end</code> state machine register,
+ indicating that the next position entry that is added should be
+ considered the end of a method prologue (an appropriate place for
a method breakpoint). The <code>prologue_end</code> register is
cleared by any special (<code>>= 0x0a</code>) opcode.
</td>
<td>0x08</td>
<td></td>
<td><i>(none)</i></td>
- <td>sets the <code>epilogue_begin</code> state machine register,
- indicating that the next position entry that is added should be
- considered the beginning of a method epilogue (an appropriate place
+ <td>sets the <code>epilogue_begin</code> state machine register,
+ indicating that the next position entry that is added should be
+ considered the beginning of a method epilogue (an appropriate place
to suspend execution before method exit).
The <code>epilogue_begin</code> register is cleared by any special
(<code>>= 0x0a</code>) opcode.
<tr>
<td>DBG_SET_FILE</td>
<td>0x09</td>
- <td>uleb128p1 name_idx</td>
+ <td>uleb128p1 name_idx</td>
<td><code>name_idx</code>: string index of source file name;
<code>NO_INDEX</code> if unknown
</td>
</tr>
<tr>
<td><i>Special Opcodes</i></td>
- <!-- When updating the range below, make sure to search for other
+ <!-- When updating the range below, make sure to search for other
instances of 0x0a in this section. -->
<td>0x0a…0xff</td>
<td></td>
</tbody>
</table>
-<p><b>Note:</b> All elements' <code>field_id</code>s and
+<p><b>Note:</b> All elements' <code>field_id</code>s and
<code>method_id</code>s must refer to the same defining class.</p>
<h3><code>field_annotation</code> Format</h3>
% <font color="green">dx --dex --output=foo.jar Foo.class</font><br>
% <font color="green">adb push foo.jar /sdcard</font><br>
% <font color="green">adb shell dalvikvm -cp /sdcard/foo.jar Foo</font><br>
-Hello, world
+Hello, world
</code>
</p><p>
The <code>-cp</code> option sets the classpath. The initial directory
width: 22%;
}
-table.format p {
+table.format p {
margin-bottom: 0pt;
}
\ No newline at end of file
}
}
-h1 {
+h1 {
text-align: center;
}
border-width: 0;
}
-td.outer {
+td.outer {
width: 25%;
padding: 0;
}
-td.outer table {
+td.outer table {
width: 100%;
}
-td.outer td {
+td.outer td {
border-width: 0;
background: #f8f8f8;
padding: 1pt;
padding-right: 2pt;
}
-tr.d td {
+tr.d td {
background: #dddddd;
}
-td.outer td + td + td {
+td.outer td + td + td {
font-family: monospace;
font-weight: bold;
padding-right: 5pt;
constraint will fail during the Dx conversion or during verification in
the VM itself.
</p>
-
+
<h2>
Static constraints
</h2>
They usually can be checked without employing control or data-flow analysis
techniques.
</p>
-
+
<table>
<tr>
<th>
Identifier
</th>
-
+
<th>
Description
</th>
-
+
<th>
Spec equivalent
</th>
-
+
<th>
Failure mode
</th>
</tr>
-
+
<tr>
<td>
A1
</td>
-
+
<td>
- The <code>code</code> array must not be empty.
+ The <code>code</code> array must not be empty.
</td>
-
+
<td>
4.8.1.1
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A2
</td>
-
+
<td>
- The <code>code</code> array must not be larger than 65535 bytes.
+ The <code>code</code> array must not be larger than 65535 bytes.
</td>
-
+
<td>
4.8.1.2
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A3
</td>
-
+
<td>
The first opcode in <code>code</code> array must have index
<code>0</code>.
</td>
-
+
<td>
4.8.1.3
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A4
</td>
-
+
<td>
The <code>code</code> array must only contain valid opcodes.
</td>
-
+
<td>
4.8.1.4
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A5
</td>
-
+
<td>
The index of instruction <code>n+1</code> must equal the index of
instruction <code>n</code> plus the length of instruction
<code>n</code>, taking into account a possible <code>wide</code>
instruction. Opcodes modified by a <code>wide</code> instruction must
- not be directly reachable.
+ not be directly reachable.
</td>
-
+
<td>
4.8.1.5
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A6
</td>
-
+
<td>
The last instruction in <code>code</code> array must end at index
- <code>code_length-1</code>.
+ <code>code_length-1</code>.
</td>
-
+
<td>
4.8.1.6
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A7
</td>
-
+
<td>
All jump and branch targets must be opcodes within the same method.
Opcodes modified by a <code>wide</code> instruction must not be
- directly reachable via a jump or branch instruction.
+ directly reachable via a jump or branch instruction.
</td>
-
+
<td>
4.8.1.7
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A8
</td>
-
+
<td>
All targets of a <code>tableswitch</code> instruction must be opcodes
within the same method. Upper and lower bounds must be consistent.
Opcodes modified by a <code>wide</code> instruction must not be
- directly reachable via a <code>tableswitch</code> instruction.
+ directly reachable via a <code>tableswitch</code> instruction.
</td>
-
+
<td>
4.8.1.8
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A9
</td>
-
+
<td>
All targets of a <code>lookupswitch</code> instruction must be opcodes
within the same method. Its table must be consistent and sorted
low-to-high. Opcodes modified by a <code>wide</code> instruction must
- not be directly reachable via a <code>lookupswitch</code> instruction.
+ not be directly reachable via a <code>lookupswitch</code> instruction.
</td>
-
+
<td>
4.8.1.9
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A10
</td>
-
+
<td>
The operands of <code>ldc</code> and <code>ldc_w</code> instructions
must be valid indices into the constant pool. The respective entries
must be of type <code>CONSTANT_Integer</code>,
- <code>CONSTANT_Float</code>, or <code>CONSTANT_String</code>.
+ <code>CONSTANT_Float</code>, or <code>CONSTANT_String</code>.
</td>
-
+
<td>
4.8.1.10
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A11
</td>
-
+
<td>
The operands of <code>ldc2_w</code> instructions must be valid indices
into the constant pool. The respective entries must be of type
<code>CONSTANT_Long</code> or <code>CONSTANT_Double</code>. The
subsequent constant pool entry must be valid and remain unused.
</td>
-
+
<td>
4.8.1.11
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A12
</td>
-
+
<td>
The Operands of <code>get<kind></code> and
<code>put<kind></code> instructions must be valid indices into
constant pool. The respective entries must be of type
<code>CONSTANT_Fieldref</code>.
</td>
-
+
<td>
4.8.1.12
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A13
</td>
-
+
<td>
The first two operands of <code>invokevirtual</code>,
<code>invokespecial</code>, and <code>invokestatic</code> must form a
valid 16-bit index into the constant pool. The respective entries must
be of type <code>CONSTANT_Methodref</code>.
</td>
-
+
<td>
4.8.1.13
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A14
</td>
-
+
<td>
Methods whose names start with '<' must only be invoked implicitly by
the VM, not by class file code. The only exception is the instance
initializer, which may be invoked by <code>invokespecial</code>.
</td>
-
+
<td>
4.8.1.14
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A15
</td>
-
+
<td>
The first two operands of <code>invokeinterface</code> must form a
valid 16-bit index into the constant pool. The entry must be of type
specify number of local variables and the fourth operand must always
be zero.
</td>
-
+
<td>
4.8.1.15
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A16
</td>
-
+
<td>
The operands of <code>instanceof</code>, <code>checkcast</code>,
<code>new</code>, and <code>anewarray</code> instructions must
into the constant pool. All respective entries must be of type
<code>CONSTANT_Class</code>.
</td>
-
+
<td>
4.8.1.16
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A17
</td>
-
+
<td>
The dimensions of an array created by <code>anewarray</code>
instructions must be less than <code>256</code>.
</td>
-
+
<td>
4.8.1.17
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A18
</td>
-
+
<td>
The <code>new</code> instruction must not reference array classes,
interfaces, or abstract classes.
</td>
-
+
<td>
4.8.1.18
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A19
</td>
-
+
<td>
The type referenced by a <code>multinewarray</code> instruction must
have at least as many dimensions as specified in the instruction. The
- dimensions operand must not be <code>0</code>
+ dimensions operand must not be <code>0</code>
</td>
-
+
<td>
4.8.1.19
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A20
</td>
-
+
<td>
The type referenced by a <code>newarray</code> instruction must be a
valid, non-reference type.
</td>
-
+
<td>
4.8.1.20
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A21
</td>
-
+
<td>
The index operand of instructions explicitly referencing single-width
local variables must be non-negative and smaller than
<code>max_locals</code>.
</td>
-
+
<td>
4.8.1.21
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A22
</td>
-
+
<td>
The index operand of instructions implicitly referencing single-width
local variables must be non-negative and smaller than
<code>max_locals</code>.
</td>
-
+
<td>
4.8.1.22
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A23
</td>
-
+
<td>
The index operand of instructions explicitly referencing double-width
local variables must be non-negative and smaller than
<code>max_locals-1</code>.
</td>
-
+
<td>
4.8.1.23
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A24
</td>
-
+
<td>
The index operand of instructions implicitly referencing double-width
local variables must be non-negative and smaller than
<code>max_locals-1</code>.
</td>
-
+
<td>
4.8.1.24
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A25
</td>
-
+
<td>
The index operand of <code>wide</code> instructions explicitly
referencing single-width local variables must be non-negative and
smaller than <code>max_locals</code>.
</td>
-
+
<td>
4.8.1.25
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
A26
</td>
-
+
<td>
The index operand of <code>wide</code> instructions explicitly
referencing double-width local variables must be non-negative and
smaller than <code>max_locals-1</code>.
</td>
-
+
<td>
4.8.1.25
</td>
-
+
<td>
DX
</td>
</tr>
</table>
-
+
<h2>
Structural constraints
</h2>
-
+
<p>
Structural constraints are constraints on relationships between several
elements of the bytecode. They usually can't be checked without employing
<th>
Identifier
</th>
-
+
<th>
Description
</th>
-
+
<th>
Spec equivalent
</th>
-
+
<th>
Failure mode
</th>
</tr>
-
+
<tr>
<td>
B1
</td>
-
+
<td>
The number and types of arguments (operands and local variables) must
always match the instruction.
</td>
-
+
<td>
4.8.2.1
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
B2
</td>
-
+
<td>
The operand stack must have the same depth for all executions paths
- leading to an instruction.
+ leading to an instruction.
</td>
-
+
<td>
4.8.2.2
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
B3
</td>
-
+
<td>
- Local variable pairs must never be broken up.
+ Local variable pairs must never be broken up.
</td>
-
+
<td>
4.8.2.3
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
B4
</td>
-
+
<td>
A local variable (or pair) has to be assigned first before it can be
read.
</td>
-
+
<td>
4.8.2.4
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
B5
</td>
-
+
<td>
- The operand stack must never grow beyond <code>max_stack</code>.
+ The operand stack must never grow beyond <code>max_stack</code>.
</td>
-
+
<td>
4.8.2.5
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
B6
</td>
-
+
<td>
- The operand stack must never underflow.
+ The operand stack must never underflow.
</td>
-
+
<td>
4.8.2.6
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
B7
</td>
-
+
<td>
An <code>invokespecial</code> instruction must only invoke an instance
initializer or a method in the current class or one of its
- superclasses.
+ superclasses.
</td>
-
+
<td>
4.8.2.7
</td>
-
+
<td>
VM
</td>
</tr>
-
+
<tr>
<td>
B8
</td>
-
+
<td>
An instance initializer must only be invoked on an uninitialized
- instance residing on the operand stack.
+ instance residing on the operand stack.
</td>
-
+
<td>
4.8.2.8
</td>
-
+
<td>
VM
</td>
</tr>
-
+
<tr>
<td>
B9
</td>
-
+
<td>
Instance methods may only be invoked on and instance fields may only
- be accessed on already initialized instances.
+ be accessed on already initialized instances.
</td>
-
+
<td>
4.8.2.9
</td>
-
+
<td>
VM
</td>
</tr>
-
+
<tr>
<td>
B10
</td>
-
+
<td>
The must be no backwards branches with uninitialized instances on the
operand stack or in local variables. There must be no code protected
by an exception handler that contains local variables with
uninitialized instances.
</td>
-
+
<td>
4.8.2.10
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
B11
</td>
-
+
<td>
An instance initializer must call another instance initializer (same
class or superclass) before any instance members can be accessed.
Exceptions are non-inherited instance fields, which can be assigned
before calling another initializer, and the <code>Object</code> class
- in general.
+ in general.
</td>
-
+
<td>
4.8.2.11
</td>
-
+
<td>
VM
</td>
</tr>
-
+
<tr>
<td>
B12
</td>
-
+
<td>
All actual method arguments must be assignment-compatible with formal
- arguments.
+ arguments.
</td>
-
+
<td>
4.8.2.12
</td>
-
+
<td>
VM
</td>
</tr>
-
+
<tr>
<td>
B13
</td>
-
+
<td>
For each instance method invocation, the actual instance must be
assignment-compatible with the class or interface specified in the
instruction.
</td>
-
+
<td>
4.8.2.13
</td>
-
+
<td>
VM
</td>
</tr>
-
+
<tr>
<td>
B14
</td>
-
+
<td>
- A returns instruction must match its method's return type.
+ A returns instruction must match its method's return type.
</td>
-
+
<td>
4.8.2.14
</td>
-
+
<td>
VM
</td>
</tr>
-
+
<tr>
<td>
B15
</td>
-
+
<td>
When accessing protected members of a superclass, the actual type of
the instance being accessed must be either the current class or one
of its subclasses.
</td>
-
+
<td>
4.8.2.15
</td>
-
+
<td>
VM
</td>
</tr>
-
+
<tr>
<td>
B16
</td>
-
+
<td>
The type of a value stored into a static field must be
assignment-compatible with or convertible to the field's type.
</td>
-
+
<td>
4.8.2.16
</td>
-
+
<td>
VM
</td>
</tr>
-
+
<tr>
<td>
B17
</td>
-
+
<td>
The type of a value stored into a field must be assignment-compatible
with or convertible to the field's type.
</td>
-
+
<td>
4.8.2.17
</td>
-
+
<td>
VM
</td>
</tr>
-
+
<tr>
<td>
B18
</td>
-
+
<td>
The type of every value stored into an array must be
assignment-compatible with the array's component type.
</td>
-
+
<td>
4.8.2.18
</td>
-
+
<td>
VM
</td>
</tr>
-
+
<tr>
<td>
B19
</td>
-
+
<td>
The operand of an <code>athrow</code> instruction must be
- assignment-compatible with <code>java.lang.Throwable</code>.
+ assignment-compatible with <code>java.lang.Throwable</code>.
</td>
-
+
<td>
4.8.2.19
</td>
-
+
<td>
VM
</td>
</tr>
-
+
<tr>
<td>
B20
</td>
-
+
<td>
The last reachable instruction of a method must either be a backwards
jump or branch, a return, or an <code>athrow</code> instruction. It
must not be possible to leave the <code>code</code> array at the
bottom.
</td>
-
+
<td>
4.8.2.20
</td>
-
+
<td>
VM
</td>
</tr>
-
+
<tr>
<td>
B21
</td>
-
+
<td>
Local variable values must not be used as return addresses.
</td>
-
+
<td>
4.8.2.21
</td>
-
+
<td>
VM
</td>
</tr>
-
+
<tr>
<td>
B22
</td>
-
+
<td>
There must be a single, uniquely determined return instruction per
subroutine call.
</td>
-
+
<td>
4.8.2.22
</td>
-
+
<td>
VM
</td>
</tr>
-
+
<tr>
<td>
B23
</td>
-
+
<td>
Subroutine calls must not be directly or indirectly self-recursive.
</td>
-
+
<td>
4.8.2.23
</td>
-
+
<td>
DX
</td>
</tr>
-
+
<tr>
<td>
B24
</td>
-
+
<td>
<code>ReturnAddress</code> instances must not be reused. If a
subroutine returns to a <code>ReturnAddress</code> further up the
<code>ReturnAddress</code> instances further down the stack must
never be used.
</td>
-
+
<td>
4.8.2.24
</td>
-
+
<td>
DX
</td>
</tr>
-
+
</table>
</body>
</html>
* class/field/method IDs for this class. Returns false on failure.
*/
native private static boolean nativeClassInit();
-
+
/*
* Invoke the native initializer when the class is loaded.
*/
<head>
<title>Dalvik Libraries</title>
-
+
<link rel=stylesheet href="dex-format.css">
<link href="prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="prettify.js"></script>
<p>
Note: It is legal to move from vN to either vN-1 or vN+1, so implementations
must arrange for both halves of a register pair to be read before anything is
-written.
+written.
</p>
<h2>Details</h2>
becomes undefined.
</li>
</ul>
-
+
<h2>Exceptions</h2>
<p>
Move the single-word non-object result of the most recent invoke-kind into the
indicated register. This must be done as the instruction immediately after an
invoke-kind whose (single-word, non-object) result is not to be ignored;
-anywhere else is invalid.
+anywhere else is invalid.
</p>
<h2>Details</h2>
<li>
The result delivered by the invoke-kind instruction must not be a reference
value or require a register pair.
- </li>
+ </li>
</ul>
<h2>Behavior</h2>
becomes undefined.
</li>
</ul>
-
+
<h2>Exceptions</h2>
<p>
This instruction can also be thought of as reading the contents of a special
"result" register that is made valid and defined by executing a non-void return
instruction or a filled-new-array instruction. The execution of any other
-instruction (including this one) renders this special register invalid.
+instruction (including this one) renders this special register invalid.
</p>
</body>
Move the double-word result of the most recent invoke-kind into the indicated
register pair. This must be done as the instruction immediately after an
invoke-kind whose (double-word) result is not to be ignored; anywhere else is
-invalid.
+invalid.
</p>
<h2>Details</h2>
or a double value.
</li>
</ul>
-
+
<h2>Behavior</h2>
<ul>
becomes undefined.
</li>
</ul>
-
+
<h2>Exceptions</h2>
<p>
becomes undefined.
</li>
</ul>
-
+
<h2>Exceptions</h2>
<p>
This instruction can also be thought of as reading the contents of a special
"result" register that is made valid and defined by executing a non-void return
instruction or a filled-new-array instruction. The execution of any other
-instruction (including this one) renders this special register invalid.
+instruction (including this one) renders this special register invalid.
</p>
</body>
Save a just-caught exception into the given register. This should be the first
instruction of any exception handler whose caught exception is not to be
ignored, and this instruction may only ever occur as the first instruction of an
-exception handler; anywhere else is invalid.
+exception handler; anywhere else is invalid.
</p>
<h2>Details</h2>
the handlers defined for the method in the Dex file.
</li>
</ul>
-
+
<h2>Behavior</h2>
<ul>
<h2>Purpose</h2>
<p>
-Return from a void method.
+Return from a void method.
</p>
<h2>Details</h2>
</li>
</ul>
</li>
-</ul>
-
+</ul>
+
<h2>Exceptions</h2>
<p>
<li>
The type of vA must match the return type of the method.
</li>
-</ul>
-
+</ul>
+
<h2>Behavior</h2>
<ul>
</ul>
</li>
</ul>
-
+
<h2>Exceptions</h2>
<p>
The type of vA must match the return type of the method.
</li>
</ul>
-
+
<h2>Behavior</h2>
<ul>
</li>
</ul>
</li>
-</ul>
+</ul>
<h2>Exceptions</h2>
<p>
Move the given literal value (sign-extended to 32 bits, if necessary) into the
-specified register.
+specified register.
</p>
<h2>Details</h2>
<ul>
<li>
If we are executing the /high16 variant, then B is left-shifted by 16
- bits, that is, B'=B << 0x10
+ bits, that is, B'=B << 0x10
<li>
Otherwise, if B is a 4 bit or 16 bit constant, it is sign-extended to 32
bits, that is, B'=sign-extended(B).
If v(A+1) is the upper half of a register pair, v(A+1)' becomes undefined.
</li>
</ul>
-
+
<h2>Exceptions</h2>
<p>
<p>
Move the given literal value (sign-extended to 64 bits) into the specified
-register-pair.
+register-pair.
</p>
<h2>Details</h2>
<li>
If v(A+2) is the upper half of a register pair, v(A+2)' becomes undefined.
</li>
-</ul>
+</ul>
<h2>Exceptions</h2>
<p>
Move a reference to the string specified by the given index into the specified
-register.
+register.
</p>
<h2>Details</h2>
</li>
<li>
B must be a valid index into the string constant pool.
- </li>
+ </li>
</ul>
<h2>Behavior</h2>
</li>
<li>
If v(A+1) is the upper half of a register pair, v(A+1)' becomes undefined.
- </li>
+ </li>
</ul>
<h2>Exceptions</h2>
<p>
Move a reference to the class specified by the given index into the specified
register. In the case where the indicated type is primitive, this will store a
-reference to the primitive type's degenerate class.
+reference to the primitive type's degenerate class.
</p>
<h2>Details</h2>
<h2>Purpose</h2>
<p>
-Acquire the monitor for the indicated object.
+Acquire the monitor for the indicated object.
</p>
<h2>Details</h2>
Register vA must contain a reference to an object.
</li>
</ul>
-
+
<h2>Behavior</h2>
<ul>
catch-all (e.g., finally) block as the monitor cleanup for that block itself,
as a way to handle the arbitrary exceptions that might get thrown due to the
historical implementation of Thread.stop(), while still managing to have proper
-monitor hygiene.
+monitor hygiene.
</p>
<h2>Details</h2>
Register vA must contain a reference to an object.
</li>
</ul>
-
+
<h2>Behavior</h2>
<ul>
an exception handler it cannot be distinguished from the same type of
exception being thrown immediately after the monitor-exit instruction.
</li>
-</ul>
+</ul>
<h2>Exceptions</h2>
<p>
Throw if the reference in the given register cannot be cast to the indicated
-type. The type must be a reference type (not a primitive type).
+type. The type must be a reference type (not a primitive type).
</p>
<h2>Details</h2>
<li>
Type pool entry B must contain a valid type descriptor for a reference type.
</li>
-</ul>
-
+</ul>
+
<h2>Behavior</h2>
<ul>
<li>
Type constant pool entry C must contain a valid type descriptor for a
reference type.
- </li>
+ </li>
</ul>
<h2>Behavior</h2>
</li>
<li>
If v(A+1) is the upper half of a register pair, v(A+1)' becomes undefined.
- </li>
+ </li>
<h2>Exceptions</h2>
Register vB must contain a reference to an array.
</li>
</ul>
-
+
<h2>Behavior</h2>
<ul>
<p>
Construct a new instance of the indicated type, storing a reference to it in the
-destination. The type must refer to a non-array class.
+destination. The type must refer to a non-array class.
</p>
<h2>Details</h2>
</li>
<li>
If v(A+1) is the upper part of a register pair, v(A+1)' becomes undefined.
- </li>
+ </li>
</ul>
<h2>Exceptions</h2>
</li>
<li>
All exceptions that are possible during instantiation can occur.
- </li>
+ </li>
</ul>
</body>
<p>
Construct a new array of the indicated type and size. The type must be an array
-type.
+type.
</p>
<h2>Details</h2>
</li>
<li>
Type constant pool entry C must contain a valid array type descriptor.
- </li>
+ </li>
</ul>
<h2>Behavior</h2>
</li>
<li>
If v(A+1) is the upper half of a register pair, v(A+1)' becomes undefined.
- </li>
+ </li>
</ul>
<h2>Exceptions</h2>
</li>
<li>
All exceptions that are possible during instantiation can occur.
- </li>
+ </li>
</ul>
</body>
store their results, so the constructed instance must be moved to a register
with a subsequent move-result-object instruction (if it is to be used).
</p>
-
+
<h2>Details</h2>
<table class="instruc">
<li>
If the element type is a reference type, then all actual arguments
(vD .. vA, depending on B) must be references, too.
- </li>
+ </li>
</ul>
-
+
<h2>Behavior</h2>
<ul>
If B > 3 then R[3] = vG
</li>
<li>
- If B > 4 then R[4] = vA
+ If B > 4 then R[4] = vA
</li>
</ul>
</li>
No reference to R is stored in any register. Instead, R can be accessed by a
move-result-object instruction immediately following this filled-new-array
instruction.
- </li>
+ </li>
</ul>
<h2>Exceptions</h2>
</li>
<li>
All exceptions that are possible during instantiation can occur.
- </li>
+ </li>
</ul>
</body>
<p>
Construct an array of the given type and size, filling it with the supplied
contents. Clarifications and restrictions are the same as filled-new-array,
-described above.
+described above.
</p>
<h2>Details</h2>
</li>
<li>
The element size of the type denoted by B must be no larger than 32 bits.
- </li>
+ </li>
</ul>
<h2>Behavior</h2>
...
</li>
<li>
- J[vA] = vN
+ J[vA] = vN
</li>
</ul>
</li>
No reference to J is stored in any register. Instead, J can be accessed by a
move-result-object instruction immediately following this filled-new-array
instruction.
- </li>
+ </li>
</ul>
<h2>Exceptions</h2>
Note: The address of the table is guaranteed to be even (that is, 4-byte
aligned). If the code size of the method is otherwise odd, then an extra code
unit is inserted between the main code and the table whose value is the same as
-a nop.
+a nop.
</p>
<h2>Details</h2>
<li>
The table size must be equal or smaller than the array length.
</li>
-</ul>
-
+</ul>
+
<h2>Behavior</h2>
<ul>
<ul>
<li>
- NullPointerException if vA is null.
+ NullPointerException if vA is null.
</li>
</ul>
to the usual rules of the Java programming language.
</li>
</ul>
-
+
<h2>Behavior</h2>
<ul>
</li>
<li>
Otherwise, the indicated exception.
- </li>
+ </li>
</ul>
</body>
</p>
<p>
Note: The branch offset may not be 0. (A spin loop may be legally constructed
-either with goto/32 or by including a nop as a target before the branch.)
+either with goto/32 or by including a nop as a target before the branch.)
</p>
<h2>Details</h2>
</li>
<li>
A must not be 0.
- </li>
+ </li>
</ul>
<h2>Behavior</h2>
</li>
<li>
Executions resumes at PC'.
- </li>
+ </li>
</ul>
<h2>Exceptions</h2>
</p>
<p>
Note: The branch offset may not be 0. (A spin loop may be legally constructed
-either with goto/32 or by including a nop as a target before the branch.)
+either with goto/32 or by including a nop as a target before the branch.)
</p>
<h2>Details</h2>
</li>
<li>
A must not be 0.
- </li>
+ </li>
</ul>
<h2>Behavior</h2>
</li>
<li>
Executions resumes at PC'.
- </li>
+ </li>
</ul>
<h2>Exceptions</h2>
</li>
<li>
Executions resumes at PC'.
- </li>
+ </li>
</ul>
<h2>Exceptions</h2>
Note: The address of the table is guaranteed to be even (that is, 4-byte
aligned). If the code size of the method is otherwise odd, then an extra code
unit is inserted between the main code and the table whose value is the same as
-a nop.
+a nop.
</p>
<h2>Details</h2>
statement.
</li>
</ul>
-
+
<h2>Exceptions</h2>
<p>
Note: The address of the table is guaranteed to be even (that is, 4-byte
aligned). If the code size of the method is otherwise odd, then an extra code
unit is inserted between the main code and the table whose value is the same as
-a nop.
+a nop.
</p>
<h2>Details</h2>
</li>
</ul>
</li>
- <li>
+ <li>
Otherwise execution continues at the instruction following the sparse-switch
statement.
</li>
-</ul>
+</ul>
<h2>Exceptions</h2>
For example, to check to see if floating point a < b, then it is advisable to
use cmpg-float; a result of -1 indicates that the test was true, and the other
values indicate it was false either due to a valid comparison or because one
-or the other values was NaN.
+or the other values was NaN.
</p>
<h2>Details</h2>
For the -long variant, both both vB and vC must be the lower part of a
register pair holding a long value.
</li>
-</ul>
+</ul>
<h2>Behavior</h2>
<li>
If v(A+1) is the upper half of a register pair, v(A+1)' becomes undefined.
</li>
-</ul>
-
+</ul>
+
<h2>Exceptions</h2>
<p>
<p>
Note: The branch offset may not be 0. (A spin loop may be legally constructed
either by branching around a backward goto or by including a nop as a target
-before the branch.)
+before the branch.)
</p>
<h2>Details</h2>
</li>
C must of a signed offset that, when added to the PC of the instruction,
points to a valid bytecode instruction inside the same method.
- </li>
+ </li>
</ul>
<h2>Behavior</h2>
</li>
</ul>
</li>
-</ul>
+</ul>
<h2>Exceptions</h2>
<p>
Note: The branch offset may not be 0. (A spin loop may be legally constructed
either by branching around a backward goto or by including a nop as a target
- before the branch.)
+ before the branch.)
</p>
<h2>Details</h2>
</li>
<li>
B must not be 0.
- </li>
+ </li>
</ul>
<h2>Behavior</h2>
<p>
Perform the identified array operation at the identified index of the given
-array, storing into the value register.
+array, storing into the value register.
</p>
<h2>Details</h2>
</li>
<li>
Register vC must contain an integer value.
- </li>
+ </li>
</ul>
<h2>Behavior</h2>
v(A+2)' becomes undefined.
</li>
</ul>
-
+
<h2>Exceptions</h2>
<ul>
<li>
ArrayIndexOutOfBoundsException if vC < 0 or vC >= array.length.
</li>
-</ul>
+</ul>
</body>
</html>
<ul>
<li>
- The given operation <unop> is performed according to the semantics
+ The given operation <unop> is performed according to the semantics
specified in table XXX.
</li>
<li>
var newlineRe = /\r\n?|\n/g;
var trailingSpaceRe = /[ \r\n]$/;
var lastWasSpace = true; // the last text chunk emitted ended with a space.
-
+
// A helper function that is responsible for opening sections of decoration
// and outputing properly escaped chunks of source
function emitTextUpTo(sourceIdx) {
LOCAL_SHARED_LIBRARIES := \
libcutils
-LOCAL_C_INCLUDES :=
+LOCAL_C_INCLUDES :=
-LOCAL_CFLAGS :=
+LOCAL_CFLAGS :=
-LOCAL_MODULE := dvz
+LOCAL_MODULE := dvz
include $(BUILD_EXECUTABLE)
int err;
g_pid = pid;
-
+
my_pgid = getpgid(0);
if (my_pgid < 0) {
perror ("error with getpgid()");
// The zygote was unable to move this process into our pgid
// We have to forward signals
- int forward_signals[]
- = {SIGHUP, SIGINT, SIGTERM, SIGWINCH,
+ int forward_signals[]
+ = {SIGHUP, SIGINT, SIGTERM, SIGWINCH,
SIGTSTP, SIGTTIN, SIGTTOU, SIGCONT};
struct sigaction sa;
/**
* Constructs an instance.
- *
+ *
* @param value {@code non-null;} the annotation default value
* @param byteLength {@code >= 0;} attribute data length in the original
* classfile (not including the attribute header)
/**
* Gets the annotation default value.
- *
+ *
* @return {@code non-null;} the value
*/
public Constant getValue() {
/**
* Constructs an instance.
- *
+ *
* @param maxStack {@code >= 0;} the stack size
* @param maxLocals {@code >= 0;} the number of locals
* @param code {@code non-null;} array containing the bytecode per se
/**
* Gets the maximum stack size.
- *
+ *
* @return {@code >= 0;} the maximum stack size
*/
public int getMaxStack() {
/**
* Gets the number of locals.
- *
+ *
* @return {@code >= 0;} the number of locals
*/
public int getMaxLocals() {
/**
* Gets the bytecode array.
- *
+ *
* @return {@code non-null;} the bytecode array
*/
public BytecodeArray getCode() {
/**
* Gets the exception table.
- *
+ *
* @return {@code non-null;} the exception table
*/
public ByteCatchList getCatches() {
/**
* Gets the associated attribute list.
- *
+ *
* @return {@code non-null;} the attribute list
*/
public AttributeList getAttributes() {
/**
* Constructs an instance.
- *
+ *
* @param constantValue {@code non-null;} the constant value, which must
* be an instance of one of: {@code CstString},
* {@code CstInteger}, {@code CstLong},
* is an instance of one of: {@code CstString},
* {@code CstInteger}, {@code CstLong},
* {@code CstFloat}, or {@code CstDouble}.
- *
+ *
* @return {@code non-null;} the constant value
*/
public TypedConstant getConstantValue() {
/**
* Constructs an instance.
- *
+ *
* @param type {@code non-null;} the innermost enclosing class
* @param method {@code null-ok;} the name-and-type of the innermost enclosing
* method, if any
/**
* Gets the innermost enclosing class.
- *
+ *
* @return {@code non-null;} the innermost enclosing class
*/
public CstType getEnclosingClass() {
/**
* Gets the name-and-type of the innermost enclosing method, if
* any.
- *
+ *
* @return {@code null-ok;} the name-and-type of the innermost enclosing
* method, if any
*/
/**
* Constructs an instance.
- *
+ *
* @param exceptions {@code non-null;} list of classes, presumed but not
* verified to be subclasses of {@code Throwable}
*/
* Gets the list of classes associated with this instance. In
* general, these classes are not pre-verified to be subclasses of
* {@code Throwable}.
- *
+ *
* @return {@code non-null;} the list of classes
*/
public TypeList getExceptions() {
/**
* Constructs an instance.
- *
+ *
* @param innerClasses {@code non-null;} list of inner class entries
*/
public AttInnerClasses(InnerClassList innerClasses) {
/**
* Gets the list of "inner class" entries associated with this instance.
- *
+ *
* @return {@code non-null;} the list
*/
public InnerClassList getInnerClasses() {
/**
* Constructs an instance.
- *
+ *
* @param lineNumbers {@code non-null;} list of line number entries
*/
public AttLineNumberTable(LineNumberList lineNumbers) {
/**
* Gets the list of "line number" entries associated with this instance.
- *
+ *
* @return {@code non-null;} the list
*/
public LineNumberList getLineNumbers() {
/**
* Constructs an instance.
- *
+ *
* @param localVariables {@code non-null;} list of local variable entries
*/
public AttLocalVariableTable(LocalVariableList localVariables) {
/**
* Constructs an instance.
- *
+ *
* @param localVariables {@code non-null;} list of local variable entries
*/
public AttLocalVariableTypeTable(LocalVariableList localVariables) {
/**
* Constructs an instance.
- *
+ *
* @param annotations {@code non-null;} the list of annotations
* @param byteLength {@code >= 0;} attribute data length in the original
* classfile (not including the attribute header)
/**
* Constructs an instance.
- *
+ *
* @param parameterAnnotations {@code non-null;} the parameter annotations
* @param byteLength {@code >= 0;} attribute data length in the original
* classfile (not including the attribute header)
/**
* Constructs an instance.
- *
+ *
* @param annotations {@code non-null;} the list of annotations
* @param byteLength {@code >= 0;} attribute data length in the original
* classfile (not including the attribute header)
/**
* Constructs an instance.
- *
+ *
* @param annotations {@code non-null;} the parameter annotations
* @param byteLength {@code >= 0;} attribute data length in the original
* classfile (not including the attribute header)
/**
* Constructs an instance.
- *
+ *
* @param signature {@code non-null;} the signature string
*/
public AttSignature(CstUtf8 signature) {
/**
* Gets the signature string.
- *
+ *
* @return {@code non-null;} the signature string
*/
public CstUtf8 getSignature() {
/**
* Constructs an instance.
- *
+ *
* @param sourceFile {@code non-null;} the name of the source file
*/
public AttSourceFile(CstUtf8 sourceFile) {
/**
* Gets the source file name of this instance.
- *
+ *
* @return {@code non-null;} the source file
*/
public CstUtf8 getSourceFile() {
/**
* Constructs an instance.
- *
+ *
* @param attributeName {@code non-null;} the name of the attribute
* @param annotations {@code non-null;} the list of annotations
* @param byteLength {@code >= 0;} attribute data length in the original
/**
* Gets the list of annotations associated with this instance.
- *
+ *
* @return {@code non-null;} the list
*/
public final Annotations getAnnotations() {
/**
* Constructs an instance.
- *
+ *
* @param name {@code non-null;} attribute name
*/
public BaseAttribute(String name) {
/**
* Constructs an instance.
- *
+ *
* @param name {@code non-null;} attribute name
* @param localVariables {@code non-null;} list of local variable entries
*/
/**
* Gets the list of "local variable" entries associated with this instance.
- *
+ *
* @return {@code non-null;} the list
*/
public final LocalVariableList getLocalVariables() {
/**
* Constructs an instance.
- *
+ *
* @param attributeName {@code non-null;} the name of the attribute
* @param parameterAnnotations {@code non-null;} the annotations
* @param byteLength {@code >= 0;} attribute data length in the original
/**
* Gets the list of annotation lists associated with this instance.
- *
+ *
* @return {@code non-null;} the list
*/
public final AnnotationsList getParameterAnnotations() {
/**
* {@code null-ok;} constant pool to use for resolution of cpis in {@link
- * #data}
+ * #data}
*/
private final ConstantPool pool;
/**
* Constructs an instance.
- *
+ *
* @param name {@code non-null;} attribute name
* @param data {@code non-null;} attribute data
* @param pool {@code null-ok;} constant pool to use for cpi resolution
/**
* Constructs an instance from a sub-array of a {@link ByteArray}.
- *
+ *
* @param name {@code non-null;} attribute name
* @param data {@code non-null;} array containing the attribute data
* @param offset offset in {@code data} to the attribute data
/**
* Get the raw data of the attribute.
- *
+ *
* @return {@code non-null;} the data
*/
public ByteArray getData() {
* Gets the constant pool to use for cpi resolution, if any. It
* presumably came from the class file that this attribute came
* from.
- *
+ *
* @return {@code null-ok;} the constant pool
*/
public ConstantPool getPool() {
/**
* Base implementation of {@link Machine}.
- *
+ *
* <p><b>Note:</b> For the most part, the documentation for this class
* ignores the distinction between {@link Type} and {@link
* TypeBearer}.</p>
public abstract class BaseMachine implements Machine {
/* {@code non-null;} the prototype for the associated method */
private final Prototype prototype;
-
+
/** {@code non-null;} primary arguments */
private TypeBearer[] args;
/**
* Constructs an instance.
- *
+ *
* @param prototype {@code non-null;} the prototype for the associated method
*/
public BaseMachine(Prototype prototype) {
public void popArgs(Frame frame, Prototype prototype) {
StdTypeList types = prototype.getParameterTypes();
int size = types.size();
-
+
// Use the above method to do the actual popping...
popArgs(frame, size);
/**
* Gets the number of primary arguments.
- *
+ *
* @return {@code >= 0;} the number of primary arguments
*/
protected final int argCount() {
/**
* Gets the width of the arguments (where a category-2 value counts as
* two).
- *
+ *
* @return {@code >= 0;} the argument width
*/
protected final int argWidth() {
/**
* Gets the {@code n}th primary argument.
- *
+ *
* @param n {@code >= 0, < argCount();} which argument
* @return {@code non-null;} the indicated argument
*/
/**
* Gets the type auxiliary argument.
- *
+ *
* @return {@code null-ok;} the salient type
*/
protected final Type getAuxType() {
/**
* Gets the {@code int} auxiliary argument.
- *
+ *
* @return the argument value
*/
protected final int getAuxInt() {
/**
* Gets the constant auxiliary argument.
- *
+ *
* @return {@code null-ok;} the argument value
*/
protected final Constant getAuxCst() {
/**
* Gets the branch target auxiliary argument.
- *
+ *
* @return the argument value
*/
protected final int getAuxTarget() {
/**
* Gets the switch cases auxiliary argument.
- *
+ *
* @return {@code null-ok;} the argument value
*/
protected final SwitchList getAuxCases() {
}
/**
* Gets the last local index accessed.
- *
+ *
* @return {@code >= -1;} the salient local index or {@code -1} if none
* was set since the last time {@link #clearArgs} was called
*/
* by a previous call to {@link #localTarget} with the type of what
* should be the sole result set by a call to {@link #setResult} (or
* the combination {@link #clearResult} then {@link #addResult}.
- *
+ *
* @return {@code null-ok;} the salient register spec or {@code null} if no
* local target was set since the last time {@link #clearArgs} was
* called
}
if (resultCount != 1) {
- throw new SimException("local target with " +
+ throw new SimException("local target with " +
((resultCount == 0) ? "no" : "multiple") + " results");
}
/**
* Sets the results list to be the given single value.
- *
+ *
* <p><b>Note:</b> If there is more than one result value, the
* others may be added by using {@link #addResult}.</p>
- *
+ *
* @param result {@code non-null;} result value
*/
protected final void setResult(TypeBearer result) {
/**
* Adds an additional element to the list of results.
- *
+ *
* @see #setResult
- *
+ *
* @param result {@code non-null;} result value
*/
protected final void addResult(TypeBearer result) {
/**
* Gets the count of results. This throws an exception if results were
* never set. (Explicitly clearing the results counts as setting them.)
- *
+ *
* @return {@code >= 0;} the count
*/
protected final int resultCount() {
/**
* Gets the width of the results (where a category-2 value counts as
* two).
- *
+ *
* @return {@code >= 0;} the result width
*/
protected final int resultWidth() {
/**
* Gets the {@code n}th result value.
- *
+ *
* @param n {@code >= 0, < resultCount();} which result
* @return {@code non-null;} the indicated result value
*/
* there is a local target (see {@link #localTarget}), then the sole
* result is stored to that target; otherwise any results are pushed
* onto the stack.
- *
+ *
* @param frame {@code non-null;} frame to operate on
*/
protected final void storeResults(Frame frame) {
/**
* Throws an exception that indicates a mismatch in local variable
* types.
- *
+ *
* @param found {@code non-null;} the encountered type
* @param local {@code non-null;} the local variable's claimed type
*/
TypeBearer local) {
throw new SimException("local variable type mismatch: " +
"attempt to set or access a value of type " +
- found.toHuman() +
- " using a local variable of type " +
+ found.toHuman() +
+ " using a local variable of type " +
local.toHuman() +
". This is symptomatic of .class transformation tools " +
"that ignore local variable information.");
/**
* {@code non-null, sparse;} for each instruction offset to a branch of
- * some sort, the list of targets for that instruction
+ * some sort, the list of targets for that instruction
*/
private final IntList[] targetLists;
/**
* {@code non-null, sparse;} for each instruction offset to a throwing
- * instruction, the list of exception handlers for that instruction
+ * instruction, the list of exception handlers for that instruction
*/
private final ByteCatchList[] catchLists;
* Identifies and enumerates the basic blocks in the given method,
* returning a list of them. The returned list notably omits any
* definitely-dead code that is identified in the process.
- *
+ *
* @param method {@code non-null;} method to convert
* @return {@code non-null;} list of basic blocks
*/
/**
* Constructs an instance. This class is not publicly instantiable; use
* {@link #identifyBlocks}.
- *
+ *
* @param method {@code non-null;} method to convert
*/
private BasicBlocker(ConcreteMethod method) {
if ((type == Type.INT) || (type == Type.LONG)) {
visitThrowing(offset, length, true);
}
- break;
+ break;
}
default: {
visitCommon(offset, length, true);
/**
* Extracts the list of basic blocks from the bit sets.
- *
+ *
* @return {@code non-null;} the list of basic blocks
*/
private ByteBlockList getBlockList() {
/**
* Sets a bit in the work set, but only if the instruction in question
* isn't yet known to be possibly-live.
- *
+ *
* @param offset offset to the instruction in question
* @param blockStart {@code true} iff this instruction starts a
* basic block
/**
* Helper method used by all the visitor methods.
- *
+ *
* @param offset offset to the instruction
* @param length length of the instruction, in bytes
* @param nextIsLive {@code true} iff the instruction after
* Helper method used by all the visitor methods that deal with
* opcodes that possibly throw. This method should be called after calling
* {@link #visitCommon}.
- *
+ *
* @param offset offset to the instruction
* @param length length of the instruction, in bytes
* @param nextIsLive {@code true} iff the instruction after
private final ByteCatchList catches;
/**
- * Constructs an instance.
- *
+ * Constructs an instance.
+ *
* @param label {@code >= 0;} target label for this block
* @param start {@code >= 0;} bytecode offset (inclusive) of the start
* of the block
/**
* Gets the label of this block.
- *
+ *
* @return {@code >= 0;} the label
*/
public int getLabel() {
/**
* Gets the bytecode offset (inclusive) of the start of this block.
- *
+ *
* @return {@code >= 0;} the start offset
*/
public int getStart() {
/**
* Gets the bytecode offset (exclusive) of the end of this block.
- *
+ *
* @return {@code > getStart();} the end offset
*/
public int getEnd() {
}
/**
- * Gets the list of successors that this block may branch to
+ * Gets the list of successors that this block may branch to
* non-exceptionally.
- *
+ *
* @return {@code non-null;} the successor list
*/
public IntList getSuccessors() {
/**
* Gets the list of exceptions caught and their handler targets.
- *
+ *
* @return {@code non-null;} the catch list
*/
public ByteCatchList getCatches() {
* is <i>not</i> found for the exception type of the given item in
* the given array. A match is considered to be either an exact type
* match or the class {@code Object} which represents a catch-all.
- *
+ *
* @param item {@code non-null;} item with the exception type to look for
* @param arr {@code non-null;} array to search in
* @param count {@code non-null;} maximum number of elements in the array to check
* is a list of all the exception handler addresses, with the given
* {@code noException} address appended if appropriate. The
* result is automatically made immutable.
- *
+ *
* @param noException {@code >= -1;} the no-exception address to append, or
* {@code -1} not to append anything
* @return {@code non-null;} list of exception targets, with
/**
* "l": {@code op local}; category-1 local; implies
* {@code max_locals} is at least two more than the given
- * local number
+ * local number
*/
public static final int FMT_LOCAL_1 = 10;
/**
* "m": {@code op local}; category-2 local; implies
* {@code max_locals} is at least two more than the given
- * local number
+ * local number
*/
public static final int FMT_LOCAL_2 = 11;
/**
* "y": {@code op #byte} ({@code bipush} and
- * {@code newarray})
+ * {@code newarray})
*/
public static final int FMT_LITERAL_BYTE = 12;
/**
* {@code non-null;} map from opcodes to format or'ed with allowed constant
- * pool types
+ * pool types
*/
private static final int[] OPCODE_INFO = new int[256];
/**
* Gets the name of the given opcode.
- *
+ *
* @param opcode {@code >= 0, <= 255;} the opcode
* @return {@code non-null;} its name
*/
/**
* Gets the format and allowed cp types of the given opcode.
- *
+ *
* @param opcode {@code >= 0, <= 255;} the opcode
* @return its format and allowed cp types
*/
/**
* Constructs an instance.
- *
+ *
* @param bytes {@code non-null;} underlying bytes
* @param pool {@code non-null;} constant pool to use when resolving constant
* pool indices
/**
* Gets the underlying byte array.
- *
+ *
* @return {@code non-null;} the byte array
*/
public ByteArray getBytes() {
/**
* Gets the size of the bytecode array, per se.
- *
+ *
* @return {@code >= 0;} the length of the bytecode array
*/
public int size() {
* Gets the total length of this structure in bytes, when included in
* a {@code Code} attribute. The returned value includes the
* array size plus four bytes for {@code code_length}.
- *
+ *
* @return {@code >= 4;} the total length, in bytes
*/
public int byteLength() {
/**
* Parses each instruction in the array, in order.
- *
+ *
* @param visitor {@code null-ok;} visitor to call back to for each instruction
*/
public void forEach(Visitor visitor) {
/**
* Finds the offset to each instruction in the bytecode array. The
* result is a bit set with the offset of each opcode-per-se flipped on.
- *
+ *
* @see Bits
* @return {@code non-null;} appropriately constructed bit set
*/
* the indicated offset (that is, the bit index), repeating until the
* work set is empty. It is expected that the visitor will regularly
* set new bits in the work set during the process.
- *
+ *
* @param workSet {@code non-null;} the work set to process
* @param visitor {@code non-null;} visitor to call back to for each instruction
*/
* Parses the instruction at the indicated offset. Indicate the
* result by calling the visitor if supplied and by returning the
* number of bytes consumed by the instruction.
- *
+ *
* <p>In order to simplify further processing, the opcodes passed
* to the visitor are canonicalized, altering the opcode to a more
* universal one and making formerly implicit arguments
* explicit. In particular:</p>
- *
+ *
* <ul>
* <li>The opcodes to push literal constants of primitive types all become
* {@code ldc}.
- * E.g., {@code fconst_0}, {@code sipush}, and
+ * E.g., {@code fconst_0}, {@code sipush}, and
* {@code lconst_0} qualify for this treatment.</li>
* <li>{@code aconst_null} becomes {@code ldc} of a
* "known null."</li>
* their pushed type. E.g., {@code arraylength} gets type
* {@code Type.INT}.</li>
* </ul>
- *
+ *
* @param offset {@code >= 0, < bytes.size();} offset to the start of the
* instruction
* @param visitor {@code null-ok;} visitor to call back to
case ByteOps.LDC: {
int idx = bytes.getUnsignedByte(offset + 1);
Constant cst = pool.get(idx);
- int value = (cst instanceof CstInteger) ?
+ int value = (cst instanceof CstInteger) ?
((CstInteger) cst).getValue() : 0;
visitor.visitConstant(ByteOps.LDC, offset, 2, cst, value);
return 2;
case ByteOps.LDC_W: {
int idx = bytes.getUnsignedShort(offset + 1);
Constant cst = pool.get(idx);
- int value = (cst instanceof CstInteger) ?
+ int value = (cst instanceof CstInteger) ?
((CstInteger) cst).getValue() : 0;
visitor.visitConstant(ByteOps.LDC, offset, 3, cst, value);
return 3;
/**
* Helper to deal with {@code tableswitch}.
- *
+ *
* @param offset the offset to the {@code tableswitch} opcode itself
* @param visitor {@code non-null;} visitor to use
* @return instruction length, in bytes
/**
* Helper to deal with {@code lookupswitch}.
- *
+ *
* @param offset the offset to the {@code lookupswitch} opcode itself
* @param visitor {@code non-null;} visitor to use
* @return instruction length, in bytes
}
}
-
+
/**
* Helper to deal with {@code wide}.
- *
+ *
* @param offset the offset to the {@code wide} opcode itself
* @param visitor {@code non-null;} visitor to use
* @return instruction length, in bytes
public interface Visitor {
/**
* Visits an invalid instruction.
- *
+ *
* @param opcode the opcode
* @param offset offset to the instruction
* @param length length of the instruction, in bytes
/**
* Visits an instruction which has no inline arguments
* (implicit or explicit).
- *
+ *
* @param opcode the opcode
* @param offset offset to the instruction
* @param length length of the instruction, in bytes
/**
* Visits an instruction which has a local variable index argument.
- *
+ *
* @param opcode the opcode
* @param offset offset to the instruction
* @param length length of the instruction, in bytes
* should-be-zero value left-shifted by 8. In the case of entries
* of type {@code int}, the {@code value} field always
* holds the raw value (for convenience of clients).
- *
+ *
* <p><b>Note:</b> In order to avoid giving it a barely-useful
* visitor all its own, {@code newarray} also uses this
* form, passing {@code value} as the array type code and
* {@code cst} as a {@link CstType} instance
* corresponding to the array type.</p>
- *
+ *
* @param opcode the opcode
* @param offset offset to the instruction
* @param length length of the instruction, in bytes
/**
* Visits an instruction which has a branch target argument.
- *
+ *
* @param opcode the opcode
* @param offset offset to the instruction
* @param length length of the instruction, in bytes
/**
* Visits a switch instruction.
- *
+ *
* @param opcode the opcode
* @param offset offset to the instruction
* @param length length of the instruction, in bytes
return previousOffset;
}
}
-
+
/**
* Base implementation of {@link Visitor}, which has empty method
* bodies for all methods.
/**
* {@code null-ok;} the class's {@code SourceFile} attribute value,
- * if any
+ * if any
*/
private final CstUtf8 sourceFile;
/**
* whether the class that this method is part of is defined with
- * {@code ACC_SUPER}
+ * {@code ACC_SUPER}
*/
private final boolean accSuper;
/**
* Constructs an instance.
- *
+ *
* @param method {@code non-null;} the method to be based on
* @param cf {@code non-null;} the class file that contains this method
* @param keepLines whether to keep the line number information
/**
* Gets whether the class that this method is part of is defined with
* {@code ACC_SUPER}.
- *
+ *
* @return the {@code ACC_SUPER} value
*/
public boolean getAccSuper() {
/**
* Gets the maximum stack size.
- *
+ *
* @return {@code >= 0;} the maximum stack size
*/
public int getMaxStack() {
/**
* Gets the number of locals.
- *
+ *
* @return {@code >= 0;} the number of locals
*/
public int getMaxLocals() {
/**
* Gets the bytecode array.
- *
+ *
* @return {@code non-null;} the bytecode array
*/
public BytecodeArray getCode() {
/**
* Gets the exception table.
- *
+ *
* @return {@code non-null;} the exception table
*/
public ByteCatchList getCatches() {
/**
* Gets the line number list.
- *
+ *
* @return {@code non-null;} the line number list
*/
public LineNumberList getLineNumbers() {
/**
* Gets the local variable list.
- *
+ *
* @return {@code non-null;} the local variable list
*/
public LocalVariableList getLocalVariables() {
/**
* Returns a {@link SourcePosition} instance corresponding to the
* given bytecode offset.
- *
+ *
* @param offset {@code >= 0;} the bytecode offset
* @return {@code non-null;} an appropriate instance
*/
/**
* Representation of a Java method execution stack.
- *
+ *
* <p><b>Note:</b> For the most part, the documentation for this class
* ignores the distinction between {@link Type} and {@link
* TypeBearer}.</p>
/**
* {@code >= 0;} stack pointer (points one past the end) / current stack
- * size
+ * size
*/
private int stackPtr;
/**
- * Constructs an instance.
- *
+ * Constructs an instance.
+ *
* @param maxStack {@code >= 0;} the maximum size of the stack for this
* instance
*/
/**
* Makes and returns a mutable copy of this instance.
- *
+ *
* @return {@code non-null;} the copy
*/
public ExecutionStack copy() {
/**
* Annotates (adds context to) the given exception with information
* about this instance.
- *
+ *
* @param ex {@code non-null;} the exception to annotate
*/
public void annotate(ExceptionWithContext ex) {
/**
* Replaces all the occurrences of the given uninitialized type in
* this stack with its initialized equivalent.
- *
+ *
* @param type {@code non-null;} type to replace
*/
public void makeInitialized(Type type) {
/**
* Gets the maximum stack size for this instance.
- *
+ *
* @return {@code >= 0;} the max stack size
*/
public int getMaxStack() {
/**
* Gets the current stack size.
- *
+ *
* @return {@code >= 0, < getMaxStack();} the current stack size
*/
public int size() {
/**
* Pushes a value of the given type onto the stack.
- *
+ *
* @param type {@code non-null;} type of the value
* @throws SimException thrown if there is insufficient room on the
* stack for the value
* {@code n == 0} means to peek at the top of the stack. Note that
* this will return {@code null} if the indicated element is the
* deeper half of a category-2 value.
- *
+ *
* @param n {@code >= 0;} which element to peek at
* @return {@code null-ok;} the type of value stored at that element
- * @throws SimException thrown if {@code n >= size()}
+ * @throws SimException thrown if {@code n >= size()}
*/
public TypeBearer peek(int n) {
if (n < 0) {
* stack, returning the type per se, as opposed to the
* <i>type-bearer</i>. This method is just a convenient shorthand
* for {@code peek(n).getType()}.
- *
+ *
* @see #peek
*/
public Type peekType(int n) {
/**
* Pops the top element off of the stack.
- *
+ *
* @return {@code non-null;} the type formerly on the top of the stack
* @throws SimException thrown if the stack is empty
*/
* contexts, particularly when merging two instances. As such, it places
* the following restriction on its behavior: You may only replace
* values with other values of the same category.
- *
+ *
* @param n {@code >= 0;} which element to change, where {@code 0} is
* the top element of the stack
* @param type {@code non-null;} type of the new value
* Gets the string form for a stack element. This is the same as
* {@code toString()} except that {@code null} is converted
* to {@code "<invalid>"}.
- *
+ *
* @param type {@code null-ok;} the stack element
* @return {@code non-null;} the string form
*/
/**
* Throws a properly-formatted exception.
- *
+ *
* @param msg {@code non-null;} useful message
* @return never (keeps compiler happy)
*/
} catch (NullPointerException ex) {
throw new NullPointerException("can't return from non-subroutine");
}
-
+
return (subLocals == null) ? null
: new Frame(subLocals, stack, newSubroutines);
}
* Merges this frame's subroutine lists with another. The result
* is the deepest common nesting (effectively, the common prefix of the
* two lists).
- *
+ *
* @param otherSubroutines label list of subroutine start blocks, from
* least-nested to most-nested.
* @return {@code non-null;} merged subroutine nest list as described above
RuntimeException("Incompatible merged subroutines");
}
}
-
+
}
return new Frame(resultLocals, resultStack, resultSubroutines);
/**
* Returns an instance which is the concatenation of the two given
* instances.
- *
+ *
* @param list1 {@code non-null;} first instance
* @param list2 {@code non-null;} second instance
* @return {@code non-null;} combined instance
/**
* Constructs an instance.
- *
+ *
* @param count the number of elements to be in the list
*/
public LineNumberList(int count) {
/**
* Gets the indicated item.
- *
+ *
* @param n {@code >= 0;} which item
* @return {@code null-ok;} the indicated item
*/
/**
* Sets the item at the given index.
- *
+ *
* @param n {@code >= 0, < size();} which element
* @param item {@code non-null;} the item
*/
/**
* Sets the item at the given index.
- *
+ *
* @param n {@code >= 0, < size();} which element
* @param startPc {@code >= 0;} start pc of this item
* @param lineNumber {@code >= 0;} corresponding line number
/**
* Gets the line number associated with the given address.
- *
+ *
* @param pc {@code >= 0;} the address to look up
* @return {@code >= -1;} the associated line number, or {@code -1} if
* none is known
/**
* Constructs an instance.
- *
+ *
* @param startPc {@code >= 0;} start pc of this item
* @param lineNumber {@code >= 0;} corresponding line number
*/
/**
* Gets the start pc of this item.
- *
+ *
* @return the start pc
*/
public int getStartPc() {
/**
* Gets the line number of this item.
- *
+ *
* @return the line number
*/
public int getLineNumber() {
/**
* Returns an instance which is the concatenation of the two given
* instances. The result is immutable.
- *
+ *
* @param list1 {@code non-null;} first instance
* @param list2 {@code non-null;} second instance
* @return {@code non-null;} combined instance
* any element whose {name, index, start, length} matches an
* element in the signature list gets augmented with the
* corresponding signature. The result is immutable.
- *
+ *
* @param descriptorList {@code non-null;} list with descriptors
* @param signatureList {@code non-null;} list with signatures
* @return {@code non-null;} the merged result
item = item.withSignature(signature);
}
result.set(i, item);
- }
+ }
result.setImmutable();
return result;
/**
* Constructs an instance.
- *
+ *
* @param count the number of elements to be in the list
*/
public LocalVariableList(int count) {
/**
* Gets the indicated item.
- *
+ *
* @param n {@code >= 0;} which item
* @return {@code null-ok;} the indicated item
*/
/**
* Sets the item at the given index.
- *
+ *
* @param n {@code >= 0, < size();} which element
* @param item {@code non-null;} the item
*/
/**
* Sets the item at the given index.
- *
+ *
* <p><b>Note:</b> At least one of {@code descriptor} or
* {@code signature} must be passed as non-null.</p>
- *
+ *
* @param n {@code >= 0, < size();} which element
* @param startPc {@code >= 0;} the start pc of this variable's scope
* @param length {@code >= 0;} the length (in bytecodes) of this variable's
* Gets the local variable information in this instance which matches
* the given {@link com.android.dx.cf.code.LocalVariableList.Item}
* in all respects but the type descriptor and signature, if any.
- *
+ *
* @param item {@code non-null;} local variable information to match
* @return {@code null-ok;} the corresponding local variable information stored
* in this instance, or {@code null} if there is no matching
* and local index, if any. <b>Note:</b> In standard classfiles, a
* variable's start point is listed as the address of the instruction
* <i>just past</i> the one that sets the variable.
- *
+ *
* @param pc {@code >= 0;} the address to look up
* @param index {@code >= 0;} the local variable index
* @return {@code null-ok;} the associated local variable information, or
/**
* Constructs an instance.
- *
+ *
* <p><b>Note:</b> At least one of {@code descriptor} or
* {@code signature} must be passed as non-null.</p>
- *
+ *
* @param startPc {@code >= 0;} the start pc of this variable's scope
* @param length {@code >= 0;} the length (in bytecodes) of this variable's
* scope
/**
* Gets the start pc of this variable's scope.
- *
+ *
* @return {@code >= 0;} the start pc of this variable's scope
*/
public int getStartPc() {
/**
* Gets the length (in bytecodes) of this variable's scope.
- *
+ *
* @return {@code >= 0;} the length (in bytecodes) of this variable's scope
*/
public int getLength() {
/**
* Gets the variable's local index.
- *
+ *
* @return {@code >= 0;} the variable's local index
*/
public int getIndex() {
/**
* Gets the variable's type descriptor. This is a convenient shorthand
* for {@code Type.intern(getDescriptor().getString())}.
- *
+ *
* @return {@code non-null;} the variable's type
*/
public Type getType() {
/**
* Constructs and returns an instance which is identical to this
* one, except that the signature is changed to the given value.
- *
+ *
* @param newSignature {@code non-null;} the new signature
* @return {@code non-null;} an appropriately-constructed instance
*/
/**
* Gets whether this instance matches (describes) the given
* address and index.
- *
+ *
* @param pc {@code >= 0;} the address in question
* @param index {@code >= 0;} the local variable index in question
* @return {@code true} iff this instance matches {@code pc}
* Gets whether this instance matches (describes) the given
* other instance exactly in all fields except type descriptor and
* type signature.
- *
+ *
* @param other {@code non-null;} the instance to compare to
* @return {@code true} iff this instance matches
*/
/**
* Representation of an array of local variables, with Java semantics.
- *
+ *
* <p><b>Note:</b> For the most part, the documentation for this class
* ignores the distinction between {@link Type} and {@link
* TypeBearer}.</p>
* Constructs an instance, explicitly indicating the mutability.
*
* @param mutable {@code true} if this instance is mutable
- */
+ */
protected LocalsArray(boolean mutable) {
super(mutable);
}
/**
* Makes and returns a mutable copy of this instance.
- *
+ *
* @return {@code non-null;} the copy
*/
public abstract LocalsArray copy();
/**
* Annotates (adds context to) the given exception with information
* about this instance.
- *
+ *
* @param ex {@code non-null;} the exception to annotate
*/
public abstract void annotate(ExceptionWithContext ex);
/**
* Replaces all the occurrences of the given uninitialized type in
* this array with its initialized equivalent.
- *
+ *
* @param type {@code non-null;} type to replace
*/
public abstract void makeInitialized(Type type);
/**
* Gets the maximum number of locals this instance can refer to.
- *
+ *
* @return the max locals
*/
public abstract int getMaxLocals();
* by the operation. In case of either category, if the <i>previous</i>
* local contains a category-2 value, then it too is invalidated by
* this operation.
- *
+ *
* @param idx {@code >= 0, < getMaxLocals();} which local
* @param type {@code non-null;} new type for the local at {@code idx}
*/
* to that register spec (which includes type and optional name
* information). This is identical to calling
* {@code set(spec.getReg(), spec)}.
- *
+ *
* @param spec {@code non-null;} register spec to use as the basis for the update
*/
public abstract void set(RegisterSpec spec);
/**
* Invalidates the local at the given index.
- *
+ *
* @param idx {@code >= 0, < getMaxLocals();} which local
*/
public abstract void invalidate(int idx);
/**
* Gets the type stored at the given local index, or {@code null}
* if the given local is uninitialized / invalid.
- *
+ *
* @param idx {@code >= 0, < getMaxLocals();} which local
* @return {@code null-ok;} the type of value stored in that local
*/
* Gets the type stored at the given local index, only succeeding if
* the given local contains a valid type (though it is allowed to
* be an uninitialized instance).
- *
+ *
* @param idx {@code >= 0, < getMaxLocals();} which local
* @return {@code non-null;} the type of value stored in that local
* @throws SimException thrown if {@code idx} is valid, but
/**
* Gets the type stored at the given local index, which is expected
* to be an initialized category-1 value.
- *
+ *
* @param idx {@code >= 0, < getMaxLocals();} which local
* @return {@code non-null;} the type of value stored in that local
* @throws SimException thrown if {@code idx} is valid, but
/**
* Gets the type stored at the given local index, which is expected
* to be a category-2 value.
- *
+ *
* @param idx {@code >= 0, < getMaxLocals();} which local
* @return {@code non-null;} the type of value stored in that local
* @throws SimException thrown if {@code idx} is valid, but
super(primary.getMaxLocals() > 0);
this.primary = primary;
- this.secondaries = secondaries;
+ this.secondaries = secondaries;
}
/**
* Gets the effective prototype of the method that this instance is
* being used for. The <i>effective</i> prototype includes an initial
* {@code this} argument for instance methods.
- *
+ *
* @return {@code non-null;} the method prototype
*/
public Prototype getPrototype();
-
+
/**
* Clears the regular and auxiliary arguments area.
*/
/**
* Merges two locals arrays. If the merged result is the same as the first
* argument, then return the first argument (not a copy).
- *
+ *
* @param locals1 {@code non-null;} a locals array
* @param locals2 {@code non-null;} another locals array
* @return {@code non-null;} the result of merging the two locals arrays
/**
* Merges two stacks. If the merged result is the same as the first
* argument, then return the first argument (not a copy).
- *
+ *
* @param stack1 {@code non-null;} a stack
* @param stack2 {@code non-null;} another stack
* @return {@code non-null;} the result of merging the two stacks
/**
* Merges two frame types.
- *
+ *
* @param ft1 {@code non-null;} a frame type
* @param ft2 {@code non-null;} another frame type
* @return {@code non-null;} the result of merging the two types
* type {@code Object} is the supertype of all reference
* types and all arrays are assignable to
* {@code Serializable} and {@code Cloneable}.
- *
+ *
* @param supertypeBearer {@code non-null;} the supertype
* @param subtypeBearer {@code non-null;} the subtype
*/
/**
* Constructs an instance.
- *
+ *
* @param subroutineAddress {@code >= 0;} the start address of the
* subroutine being returned from
*/
/**
* Gets the subroutine address.
- *
+ *
* @return {@code >= 0;} the subroutine address
*/
public int getSubroutineAddress() {
/**
* {@code non-null;} method constant for use in converting
- * {@code multianewarray} instructions
+ * {@code multianewarray} instructions
*/
private static final CstMethodRef MULTIANEWARRAY_METHOD =
new CstMethodRef(ARRAY_REFLECT_TYPE,
/**
* {@code null-ok;} the appropriate {@code return} op or {@code null}
- * if it is not yet known
+ * if it is not yet known
*/
private Rop returnOp;
/**
* {@code null-ok;} the source position for the return block or {@code null}
- * if it is not yet known
+ * if it is not yet known
*/
private SourcePosition returnPosition;
/**
* Constructs an instance.
- *
+ *
* @param ropper {@code non-null;} ropper controlling this instance
* @param method {@code non-null;} method being converted
* @param advice {@code non-null;} translation advice to use
public RopperMachine(Ropper ropper, ConcreteMethod method,
TranslationAdvice advice) {
super(method.getEffectiveDescriptor());
-
+
if (ropper == null) {
throw new NullPointerException("ropper == null");
}
/**
* Gets the instructions array. It is shared and gets modified by
* subsequent calls to this instance.
- *
+ *
* @return {@code non-null;} the instructions array
*/
public ArrayList<Insn> getInsns() {
/**
* Gets the return opcode encountered, if any.
- *
+ *
* @return {@code null-ok;} the return opcode
*/
public Rop getReturnOp() {
/**
* Gets the return position, if known.
- *
+ *
* @return {@code null-ok;} the return position
*/
public SourcePosition getReturnPosition() {
/**
* Gets whether {@link #catches} was used. This indicates that the
* last instruction in the block is one of the ones that can throw.
- *
+ *
* @return whether {@code catches} has been used
*/
public boolean wereCatchesUsed() {
/**
* Gets whether the block just processed ended with a
* {@code return}.
- *
+ *
* @return whether the block returns
*/
public boolean returns() {
* successor. This may return something other than
* {@code -1} in the case of an instruction with no
* successors at all (primary or otherwise).
- *
+ *
* @return {@code >= -1;} the primary successor index
*/
public int getPrimarySuccessorIndex() {
* Gets how many extra blocks will be needed to represent the
* block currently being translated. Each extra block should consist
* of one instruction from the end of the original block.
- *
+ *
* @return {@code >= 0;} the number of extra blocks needed
*/
public int getExtraBlockCount() {
* the "temporary stack" area defined for the method, and
* then move stuff back down onto the main "stack" in the
* arrangement specified by the stack op pattern.
- *
+ *
* Note: This code ends up emitting a lot of what will
* turn out to be superfluous moves (e.g., moving back and
* forth to the same local when doing a dup); however,
stackPointer += type.getType().getCategory();
}
return;
- }
+ }
TypeBearer destType = (dest != null) ? dest : Type.VOID;
Constant cst = getAuxCst();
* Add an array constructor for the int[] containing all the
* dimensions.
*/
- RegisterSpec dimsReg =
+ RegisterSpec dimsReg =
RegisterSpec.make(dest.getNextReg(), Type.INT_ARRAY);
rop = Rops.opFilledNewArray(Type.INT_ARRAY, sourceCount);
insn = new ThrowingCstInsn(rop, pos, sources, catches,
/*
* Add a const-class instruction for the specified array
- * class.
+ * class.
*/
/*
RegisterSpec objectReg =
RegisterSpec.make(dest.getReg(), Type.OBJECT);
-
+
insn = new ThrowingCstInsn(
Rops.opInvokeStatic(MULTIANEWARRAY_METHOD.getPrototype()),
pos, RegisterSpecList.make(classReg, dimsReg),
* action we take here is to convert these initialization
* bytecodes into a single fill-array-data ROP which lays out
* all the constant values in a table.
- */
+ */
if (initValues != null) {
extraBlockCount++;
insn = new FillArrayDataInsn(Rops.FILL_ARRAY_DATA, pos,
/**
* Helper for {@link #run}, which gets the list of sources for the.
* instruction.
- *
+ *
* @param opcode the opcode being translated
* @param stackPointer {@code >= 0;} the stack pointer after the
* instruction's arguments have been popped
if (count == 0) {
// We get an easy out if there aren't any sources.
return RegisterSpecList.EMPTY;
- }
+ }
int localIndex = getLocalIndex();
RegisterSpecList sources;
/**
* Sets or updates the information about the return block.
- *
+ *
* @param op {@code non-null;} the opcode to use
* @param pos {@code non-null;} the position to use
*/
/**
* Gets the register opcode for the given Java opcode.
- *
+ *
* @param jop {@code >= 0;} the Java opcode
* @param cst {@code null-ok;} the constant argument, if any
* @return {@code >= 0;} the corresponding register opcode
case ByteOps.LDC2_W: {
return RegOps.CONST;
}
- case ByteOps.ILOAD:
+ case ByteOps.ILOAD:
case ByteOps.ISTORE: {
return RegOps.MOVE;
}
private static final String LOCAL_MISMATCH_ERROR =
"This is symptomatic of .class transformation tools that ignore " +
"local variable information.";
-
+
/** {@code non-null;} machine to use when simulating */
private final Machine machine;
/**
* Constructs an instance.
- *
+ *
* @param machine {@code non-null;} machine to use when simulating
* @param method {@code non-null;} method data to use
*/
/**
* Simulates the effect of executing the given basic block. This modifies
* the passed-in frame to represent the end result.
- *
+ *
* @param bb {@code non-null;} the basic block
* @param frame {@code non-null;} frame to operate on
*/
/**
* Simulates the effect of the instruction at the given offset, by
* making appropriate calls on the given frame.
- *
+ *
* @param offset {@code >= 0;} offset of the instruction to simulate
* @param frame {@code non-null;} frame to operate on
* @return the length of the instruction, in bytes
private final Machine machine;
/**
- * {@code null-ok;} frame to use; set with each call to
+ * {@code null-ok;} frame to use; set with each call to
* {@link Simulator#simulate}
*/
private Frame frame;
/**
* Sets the frame to act on.
- *
+ *
* @param frame {@code non-null;} the frame
*/
public void setFrame(Frame frame) {
if (stack.peekType(0).isCategory2()) {
throw illegalTos();
}
-
+
if (stack.peekType(1).isCategory2()) {
// "form 2" in vmspec-2
machine.popArgs(frame, 2);
/**
* Checks whether the prototype is compatible with returning the
* given type, and throws if not.
- *
+ *
* @param encountered {@code non-null;} the encountered return type
*/
private void checkReturnType(Type encountered) {
* possible, we replace the type with the one indicated in
* the local variable table, though we still need to check
* to make sure it's valid for the opcode.
- *
+ *
* The reason we use (offset + length) for the localOffset
* for a store is because it is only after the store that
* the local type becomes valid. On the other hand, the
* Get the instance prototype, and use it to direct
* the machine.
*/
- Prototype prototype =
+ Prototype prototype =
((CstMethodRef) cst).getPrototype(false);
machine.popArgs(frame, prototype);
break;
* Get the static prototype, and use it to direct
* the machine.
*/
- Prototype prototype =
+ Prototype prototype =
((CstMethodRef) cst).getPrototype(true);
machine.popArgs(frame, prototype);
break;
/**
* {@code non-null;} list of targets corresponding to the test values; there
* is always one extra element in the target list, to hold the
- * default target
+ * default target
*/
private final IntList targets;
/**
* Constructs an instance.
- *
+ *
* @param size {@code >= 0;} the number of elements to be in the table
*/
public SwitchList(int size) {
/**
* Gets the size of the list.
- *
+ *
* @return {@code >= 0;} the list size
*/
public int size() {
/**
* Gets the indicated test value.
- *
+ *
* @param n {@code >= 0;}, < size(); which index
- * @return the test value
+ * @return the test value
*/
public int getValue(int n) {
return values.get(n);
/**
* Gets the indicated target. Asking for the target at {@code size()}
* returns the default target.
- *
+ *
* @param n {@code >= 0, <= size();} which index
* @return {@code >= 0;} the target
*/
/**
* Gets the default target. This is just a shorthand for
* {@code getTarget(size())}.
- *
+ *
* @return {@code >= 0;} the default target
*/
public int getDefaultTarget() {
/**
* Gets the list of all targets. This includes one extra element at the
* end of the list, which holds the default target.
- *
+ *
* @return {@code non-null;} the target list
*/
public IntList getTargets() {
/**
* Gets the list of all case values.
- *
+ *
* @return {@code non-null;} the case value list
*/
public IntList getValues() {
/**
* Sets the default target. It is only valid to call this method
* when all the non-default elements have been set.
- *
+ *
* @param target {@code >= 0;} the absolute (not relative) default target
* address
*/
/**
* Adds the given item.
- *
+ *
* @param value the test value
* @param target {@code >= 0;} the absolute (not relative) target address
*/
public class ValueAwareMachine extends BaseMachine {
/**
* Constructs an instance.
- *
+ *
* @param prototype {@code non-null;} the prototype for the associated
* method
*/
case ByteOps.IUSHR:
case ByteOps.IAND:
case ByteOps.IOR:
- case ByteOps.IXOR:
+ case ByteOps.IXOR:
case ByteOps.IINC:
case ByteOps.I2L:
case ByteOps.I2F:
}
Type type = ((TypeBearer) getAuxCst()).getType();
if (type == Type.VOID) {
- clearResult();
+ clearResult();
} else {
setResult(type);
}
/**
* -1 || >= 10; the end offset of this constant pool in the
* {@code byte[]} which it came from or {@code -1} if not
- * yet parsed
+ * yet parsed
*/
private int endOffset;
/**
* Constructs an instance.
- *
+ *
* @param bytes {@code non-null;} the bytes of the file
*/
public ConstantPoolParser(ByteArray bytes) {
/**
* Sets the parse observer for this instance.
- *
+ *
* @param observer {@code null-ok;} the observer
*/
public void setObserver(ParseObserver observer) {
/**
* Gets the end offset of this constant pool in the {@code byte[]}
* which it came from.
- *
+ *
* @return {@code >= 10;} the end offset
*/
public int getEndOffset() {
/**
* Gets the actual constant pool.
- *
+ *
* @return {@code non-null;} the constant pool
*/
public StdConstantPool getPool() {
* parsed, also storing it in the constant pool. This will also
* have the side effect of parsing any entries the indicated one
* depends on.
- *
+ *
* @param idx which constant
* @return {@code non-null;} the parsed constant
*/
/**
* Parses a utf8 constant.
- *
+ *
* @param at offset to the start of the constant (where the tag byte is)
* @return {@code non-null;} the parsed value
*/
* was parsed
*/
private int parseCursor;
-
+
/**
* Constructs an instance.
- *
+ *
* @param cf {@code non-null;} class file to parse from
* @param offset {@code >= 0;} offset into the class file data to parse at
* @param length {@code >= 0;} number of bytes left in the attribute data
this.input = bytes.makeDataInputStream();
this.parseCursor = 0;
}
-
+
/**
* Parses an annotation value ({@code element_value}) attribute.
- *
+ *
* @return {@code non-null;} the parsed constant value
*/
public Constant parseValueAttribute() {
Constant result;
-
+
try {
result = parseValue();
/**
* Parses a parameter annotation attribute.
- *
+ *
* @param visibility {@code non-null;} visibility of the parsed annotations
* @return {@code non-null;} the parsed list of lists of annotations
*/
public AnnotationsList parseParameterAttribute(
AnnotationVisibility visibility) {
AnnotationsList result;
-
+
try {
result = parseAnnotationsList(visibility);
return result;
}
-
+
/**
* Parses an annotation attribute, per se.
- *
+ *
* @param visibility {@code non-null;} visibility of the parsed annotations
* @return {@code non-null;} the list of annotations read from the attribute
* data
public Annotations parseAnnotationAttribute(
AnnotationVisibility visibility) {
Annotations result;
-
+
try {
result = parseAnnotations(visibility);
/**
* Parses a list of annotation lists.
- *
+ *
* @param visibility {@code non-null;} visibility of the parsed annotations
* @return {@code non-null;} the list of annotation lists read from the attribute
* data
/**
* Parses an annotation list.
- *
+ *
* @param visibility {@code non-null;} visibility of the parsed annotations
* @return {@code non-null;} the list of annotations read from the attribute
* data
/**
* Parses a single annotation.
- *
+ *
* @param visibility {@code non-null;} visibility of the parsed annotation
* @return {@code non-null;} the parsed annotation
*/
annotation.setImmutable();
return annotation;
}
-
+
/**
* Parses a {@link NameValuePair}.
- *
+ *
* @return {@code non-null;} the parsed element
*/
private NameValuePair parseElement() throws IOException {
requireLength(5);
-
+
int elementNameIndex = input.readUnsignedShort();
CstUtf8 elementName = (CstUtf8) pool.get(elementNameIndex);
-
+
if (observer != null) {
parsed(2, "element_name: " + elementName.toHuman());
parsed(0, "value: ");
/**
* Parses an annotation value.
- *
+ *
* @return {@code non-null;} the parsed value
*/
private Constant parseValue() throws IOException {
int classInfoIndex = input.readUnsignedShort();
CstUtf8 value = (CstUtf8) pool.get(classInfoIndex);
Type type = Type.internReturnType(value.getString());
-
+
if (observer != null) {
parsed(2, "class_info: " + type.toHuman());
}
int constNameIndex = input.readUnsignedShort();
CstUtf8 typeName = (CstUtf8) pool.get(typeNameIndex);
CstUtf8 constName = (CstUtf8) pool.get(constNameIndex);
-
+
if (observer != null) {
parsed(2, "type_name: " + typeName.toHuman());
parsed(2, "const_name: " + constName.toHuman());
}
}
}
-
+
/**
* Helper for {@link #parseValue}, which parses a constant reference
* and returns the referred-to constant value.
- *
+ *
* @return {@code non-null;} the parsed value
*/
private Constant parseConstant() throws IOException {
Constant value = (Constant) pool.get(constValueIndex);
if (observer != null) {
- String human = (value instanceof CstUtf8)
- ? ((CstUtf8) value).toQuoted()
+ String human = (value instanceof CstUtf8)
+ ? ((CstUtf8) value).toQuoted()
: value.toHuman();
parsed(2, "constant_value: " + human);
}
/**
* Helper which will throw an exception if the given number of bytes
* is not available to be read.
- *
+ *
* @param requiredLength the number of required bytes
*/
private void requireLength(int requiredLength) throws IOException {
throw new ParseException("truncated annotation attribute");
}
}
-
+
/**
* Helper which indicates that some bytes were just parsed. This should
* only be used (for efficiency sake) if the parse is known to be
* observed.
- *
+ *
* @param length {@code >= 0;} number of bytes parsed
* @param message {@code non-null;} associated message
*/
/**
* Convenience wrapper that simply calls through to
* {@code observer.changeIndent()}.
- *
+ *
* @param indent the amount to change the indent by
*/
private void changeIndent(int indent) {
* indicated position in the given array. This method figures out
* the name, and then does all the setup to call on to {@link #parse0},
* which does the actual construction.
- *
+ *
* @param cf {@code non-null;} class file to parse from
* @param context context to parse in; one of the {@code CTX_*}
* constants
return parse0(cf, context, name.getString(), offset + 6, length,
observer);
} catch (ParseException ex) {
- ex.addContext("...while parsing " +
+ ex.addContext("...while parsing " +
((name != null) ? (name.toHuman() + " ") : "") +
"attribute at offset " + Hex.u4(offset));
throw ex;
* Parses attribute content. The base class implements this by constructing
* an instance of {@link RawAttribute}. Subclasses are expected to
* override this to do something better in most cases.
- *
+ *
* @param cf {@code non-null;} class file to parse from
* @param context context to parse in; one of the {@code CTX_*}
* constants
byte[] buf = new byte[20000];
boolean any = false;
- ArrayList<? extends java.util.zip.ZipEntry> entriesList
+ ArrayList<? extends java.util.zip.ZipEntry> entriesList
= Collections.list(zip.entries());
if (sort) {
/**
* Constructs an instance.
- *
+ *
* @param bytes {@code non-null;} actual array of bytecode
* @param observer {@code non-null;} observer to inform of parsing
*/
/**
* Helper to produce the first bit of output for each instruction.
- *
+ *
* @param offset the offset to the start of the instruction
*/
private String header(int offset) {
/**
* Helper for {@link #visitConstant} where the constant is an
* {@code int}.
- *
+ *
* @param opcode the opcode
* @param offset offset to the instruction
* @param length instruction length
/**
* Helper for {@link #visitConstant} where the constant is a
* {@code long}.
- *
+ *
* @param opcode the opcode
* @param offset offset to the instruction
* @param length instruction length
/**
* Helper for {@link #visitConstant} where the constant is a
* {@code float}.
- *
+ *
* @param opcode the opcode
* @param offset offset to the instruction
* @param length instruction length
/**
* Helper for {@link #visitConstant} where the constant is a
* {@code double}.
- *
+ *
* @param opcode the opcode
* @param offset offset to the instruction
* @param length instruction length
/**
* minimum {@code .class} file major version
- *
+ *
* The class file definition (vmspec/2nd-edition) says:
- *
+ *
* "Implementations of version 1.2 of the
* Java 2 platform can support class file
* formats of versions in the range 45.0
* through 46.0 inclusive."
- *
+ *
* The class files generated by the build are currently
* (as of 11/2006) reporting version 49.0 (0x31.0x00),
* however, so we use that as our upper bound.
- *
+ *
* Valid ranges are typically of the form
* "A.0 through B.C inclusive" where A <= B and C >= 0,
* which is why we don't have a CLASS_FILE_MIN_MINOR_VERSION.
/**
* {@code non-null;} the file path for the class, excluding any base directory
- * specification
+ * specification
*/
private final String filePath;
* whether to be strict about parsing; if
* {@code false}, this avoids doing checks that only exist
* for purposes of verification (such as magic number matching and
- * path-package consistency checking)
+ * path-package consistency checking)
*/
private final boolean strictParse;
/**
* {@code null-ok;} the constant pool; only ever {@code null}
- * before the constant pool is successfully parsed
+ * before the constant pool is successfully parsed
*/
private StdConstantPool pool;
/**
* the class file field {@code access_flags}; will be {@code -1}
- * before the file is successfully parsed
+ * before the file is successfully parsed
*/
private int accessFlags;
/**
* {@code null-ok;} the class file field {@code super_class}, interpreted
- * as a type constant if non-zero
+ * as a type constant if non-zero
*/
private CstType superClass;
/**
* {@code null-ok;} the class file field {@code interfaces}; only
* ever {@code null} before the file is successfully
- * parsed
+ * parsed
*/
private TypeList interfaces;
/**
* {@code null-ok;} the class file field {@code fields}; only ever
- * {@code null} before the file is successfully parsed
+ * {@code null} before the file is successfully parsed
*/
private FieldList fields;
/**
* {@code null-ok;} the class file field {@code methods}; only ever
- * {@code null} before the file is successfully parsed
+ * {@code null} before the file is successfully parsed
*/
private MethodList methods;
/**
* {@code null-ok;} the class file field {@code attributes}; only
* ever {@code null} before the file is successfully
- * parsed
+ * parsed
*/
private StdAttributeList attributes;
/**
* Returns the string form of an object or {@code "(none)"}
* (rather than {@code "null"}) for {@code null}.
- *
+ *
* @param obj {@code null-ok;} the object to stringify
* @return {@code non-null;} the appropriate string form
*/
/**
* Constructs an instance.
- *
+ *
* @param bytes {@code non-null;} the bytes of the file
* @param filePath {@code non-null;} the file path for the class,
* excluding any base directory specification
/**
* Constructs an instance.
- *
+ *
* @param bytes {@code non-null;} the bytes of the file
* @param filePath {@code non-null;} the file path for the class,
* excluding any base directory specification
/**
* Sets the parse observer for this instance.
- *
+ *
* @param observer {@code null-ok;} the observer
*/
public void setObserver(ParseObserver observer) {
/**
* Sets the attribute factory to use.
- *
+ *
* @param attributeFactory {@code non-null;} the attribute factory
*/
public void setAttributeFactory(AttributeFactory attributeFactory) {
/**
* Gets the {@link ByteArray} that this instance's data comes from.
- *
+ *
* @return {@code non-null;} the bytes
*/
public ByteArray getBytes() {
* translated to type constants. Instance construction will fail
* if any of the (alleged) indices turn out not to refer to
* constant pool entries of type {@code Class}.
- *
+ *
* @param offset offset into {@link #bytes} for the start of the
* data
* @param size number of elements in the list (not number of bytes)
if (pool == null) {
throw new IllegalStateException("pool not yet initialized");
}
-
+
return new DcfTypeList(bytes, offset, size, pool, observer);
}
/**
* Gets the class file field {@code magic}, but without doing any
* checks or parsing first.
- *
+ *
* @return the magic value
*/
public int getMagic0() {
/**
* Gets the class file field {@code minor_version}, but
* without doing any checks or parsing first.
- *
+ *
* @return the minor version
*/
public int getMinorVersion0() {
/**
* Gets the class file field {@code major_version}, but
* without doing any checks or parsing first.
- *
+ *
* @return the major version
*/
public int getMajorVersion0() {
/**
* Sees if the .class file header magic/version are within
* range.
- *
+ *
* @param magic the value of a classfile "magic" field
* @param minorVersion the value of a classfile "minor_version" field
* @param majorVersion the value of a classfile "major_version" field
if (observer != null) {
observer.parsed(bytes, at, 2,
- "access_flags: " +
+ "access_flags: " +
AccessFlags.classString(accessFlags));
observer.parsed(bytes, at + 2, 2, "this_class: " + thisClass);
observer.parsed(bytes, at + 4, 2, "super_class: " +
private static class DcfTypeList implements TypeList {
/** {@code non-null;} array containing the data */
private final ByteArray bytes;
-
+
/** number of elements in the list (not number of bytes) */
private final int size;
/**
* Constructs an instance.
- *
+ *
* @param bytes {@code non-null;} original classfile's bytes
* @param offset offset into {@link #bytes} for the start of the
* data
/** {@inheritDoc} */
public TypeList withAddedType(Type type) {
throw new UnsupportedOperationException("unsupported");
- }
+ }
}
}
/**
* Constructs an instance.
- *
+ *
* @param cf {@code non-null;} the class file to parse from
* @param definer {@code non-null;} class being defined
* @param offset offset in {@code bytes} to the start of the list
/**
* Gets the parsed list.
- *
+ *
* @return {@code non-null;} the parsed list
*/
public StdFieldList getList() {
/**
* Gets the human-oriented name for what this instance is parsing.
* Subclasses must override this method.
- *
+ *
* @return {@code non-null;} the human oriented name
*/
protected abstract String humanName();
/**
* Gets the {@code CTX_*} constant to use when parsing attributes.
* Subclasses must override this method.
- *
+ *
* @return {@code non-null;} the human oriented name
*/
protected abstract int getAttributeContext();
/**
* Constructs an instance.
- *
+ *
* @param cf {@code non-null;} the class file to parse from
* @param definer {@code non-null;} class being defined
* @param offset offset in {@code bytes} to the start of the list
/**
* Gets the parsed list.
- *
+ *
* @return {@code non-null;} the parsed list
*/
public StdMethodList getList() {
if (observer != null) {
observer.parsed(bytes, offset, 2, "class: " + type);
- observer.parsed(bytes, offset + 2, 2, "method: " +
+ observer.parsed(bytes, offset + 2, 2, "method: " +
DirectClassFile.stringOrNone(method));
}
list.set(i, innerClass, outerClass, name, accessFlags);
if (observer != null) {
observer.parsed(bytes, offset, 2,
- "inner_class: " +
+ "inner_class: " +
DirectClassFile.stringOrNone(innerClass));
observer.parsed(bytes, offset + 2, 2,
- " outer_class: " +
+ " outer_class: " +
DirectClassFile.stringOrNone(outerClass));
observer.parsed(bytes, offset + 4, 2,
- " name: " +
+ " name: " +
DirectClassFile.stringOrNone(name));
observer.parsed(bytes, offset + 6, 2,
" access_flags: " +
/**
* Parse the table part of either a {@code LocalVariableTable}
* or a {@code LocalVariableTypeTable}.
- *
+ *
* @param bytes {@code non-null;} bytes to parse, which should <i>only</i>
* contain the table data (no header)
* @param pool {@code non-null;} constant pool to use
CstUtf8 type = (CstUtf8) pool.get(typeIdx);
CstUtf8 descriptor = null;
CstUtf8 signature = null;
-
+
if (typeTable) {
signature = type;
} else {
descriptor = type;
}
-
+
list.set(i, startPc, length, name,
descriptor, signature, index);
AnnotationParser ap =
new AnnotationParser(cf, offset, length, observer);
- Annotations annotations =
+ Annotations annotations =
ap.parseAnnotationAttribute(AnnotationVisibility.BUILD);
return new AttRuntimeInvisibleAnnotations(annotations, length);
AnnotationParser ap =
new AnnotationParser(cf, offset, length, observer);
- Annotations annotations =
+ Annotations annotations =
ap.parseAnnotationAttribute(AnnotationVisibility.RUNTIME);
return new AttRuntimeVisibleAnnotations(annotations, length);
/**
* Throws the right exception when a known attribute has a way too short
* length.
- *
+ *
* @return never
* @throws ParseException always thrown
*/
/**
* Throws the right exception when a known attribute has a too short
* length.
- *
+ *
* @return never
* @throws ParseException always thrown
*/
/**
* Throws the right exception when an attribute has an unexpected length
* (given its contents).
- *
+ *
* @param expected expected length
* @return never
* @throws ParseException always thrown
public ConstantPool getConstantPool();
/**
- * Gets the field {@code interfaces} (along with
+ * Gets the field {@code interfaces} (along with
* {@code interfaces_count}).
*
* @return {@code non-null;} the list of interfaces
implements AttributeList {
/**
* Constructs an instance. All indices initially contain {@code null}.
- *
+ *
* @param size the size of the list
*/
public StdAttributeList(int size) {
/**
* Sets the attribute at the given index.
- *
+ *
* @param n {@code >= 0, < size();} which attribute
* @param attribute {@code null-ok;} the attribute object
*/
public final class StdField extends StdMember implements Field {
/**
* Constructs an instance.
- *
+ *
* @param definingClass {@code non-null;} the defining class
* @param accessFlags access flags
* @param nat {@code non-null;} member name and type (descriptor)
public final class StdFieldList extends FixedSizeList implements FieldList {
/**
* Constructs an instance. All indices initially contain {@code null}.
- *
+ *
* @param size the size of the list
*/
public StdFieldList(int size) {
/**
* Sets the field at the given index.
- *
+ *
* @param n {@code >= 0, < size();} which field
* @param field {@code null-ok;} the field object
*/
/**
* Constructs an instance.
- *
+ *
* @param definingClass {@code non-null;} the defining class
* @param accessFlags access flags
* @param nat {@code non-null;} member name and type (descriptor)
/**
* Constructs an instance.
- *
+ *
* @param definingClass {@code non-null;} the defining class
* @param accessFlags access flags
* @param nat {@code non-null;} member name and type (descriptor)
public final class StdMethodList extends FixedSizeList implements MethodList {
/**
* Constructs an instance. All indices initially contain {@code null}.
- *
+ *
* @param size the size of the list
*/
public StdMethodList(int size) {
/**
* Sets the method at the given index.
- *
+ *
* @param n {@code >= 0, < size();} which method
* @param method {@code null-ok;} the method object
*/
" Dump classfiles, or transformations thereof, in a " +
"human-oriented format.\n" +
" dx --junit [-wait] <TestClass>\n" +
- " Run the indicated unit test.\n" +
+ " Run the indicated unit test.\n" +
" dx -J<option> ... <arguments, in one of the above " +
"forms>\n" +
" Pass VM-specific options to the virtual machine that " +
").\n" +
" dx --help\n" +
" Print this message.";
-
+
/**
* This class is uninstantiable.
*/
} catch (Throwable ex) {
System.err.println("\nUNEXPECTED TOP-LEVEL ERROR:");
ex.printStackTrace();
- if ((ex instanceof NoClassDefFoundError)
+ if ((ex instanceof NoClassDefFoundError)
|| (ex instanceof NoSuchMethodError)) {
System.err.println(
"Note: You may be using an incompatible " +
"with recent releases of GCJ.)");
}
System.exit(3);
- }
+ }
if (!gotCmd) {
System.err.println("error: no command specified");
case CLASS:
case INNERCLASS:
case METHOD:
- matchPackages.add(packageName);
+ matchPackages.add(packageName);
break;
case PACKAGE:
System.out.println(packageName.replace('/','.'));
InvalidArgumentException() {
super();
}
-
+
InvalidArgumentException(String s) {
super(s);
}
CLASS,
INNERCLASS,
METHOD,
- PACKAGE
+ PACKAGE
}
}
});
- return opener.process();
+ return opener.process();
}
/**
if (! args.coreLibrary) {
checkClassName(name);
}
-
+
try {
ClassDefItem clazz =
CfTranslator.translate(name, bytes, args.cfOptions);
* Check the class name to make sure it's not a "core library"
* class. If there is a problem, this updates the error count and
* throws an exception to stop processing.
- *
+ *
* @param name {@code non-null;} the fully-qualified internal-form
* class name
*/
private static void checkClassName(String name) {
boolean bogus = false;
-
+
if (name.startsWith("java/")) {
bogus = true;
} else if (name.startsWith("javax/")) {
*/
DxConsole.err.println("\ntrouble processing \"" + name + "\":");
- DxConsole.err.println("\n" +
+ DxConsole.err.println("\n" +
"Attempt to include a core class (java.* or javax.*) in " +
"something other\n" +
"than a core library. It is likely that you have " +
meth.debugPrint(pw, args.verboseDump);
/*
- * The (default) source file is an attribute of the class, but
+ * The (default) source file is an attribute of the class, but
* it's useful to see it in method dumps.
*/
CstUtf8 sourceFile = clazz.getSourceFile();
private static class StopProcessing extends RuntimeException {
// This space intentionally left blank.
}
-
+
/**
* Command-line argument parser and access.
*/
/**
* {@code non-null;} the file path for the class, excluding any base
- * directory specification
+ * directory specification
*/
private final String filePath;
/**
* Constructs an instance.
- *
+ *
* @param bytes {@code non-null;} bytes of the (alleged) class file
* on the left)
* @param out {@code non-null;} where to dump to
/**
* Gets the current dump cursor (that is, the offset of the expected
* next byte to dump).
- *
+ *
* @return {@code >= 0;} the dump cursor
*/
protected final int getAt() {
/**
* Sets the dump cursor to the indicated offset in the given array.
- *
+ *
* @param arr {@code non-null;} array in question
* @param offset {@code >= 0;} offset into the array
*/
/**
* Gets the array of {@code byte}s to process.
- *
+ *
* @return {@code non-null;} the bytes
*/
protected final byte[] getBytes() {
/**
* Gets the filesystem/jar path of the file being dumped.
- *
+ *
* @return {@code non-null;} the path
*/
protected final String getFilePath() {
/**
* Gets whether to be strict about parsing.
- *
+ *
* @return whether to be strict about parsing
*/
protected final boolean getStrictParse() {
/**
* Prints the given string to this instance's output stream.
- *
+ *
* @param s {@code null-ok;} string to print
*/
protected final void print(String s) {
/**
* Prints the given string to this instance's output stream, followed
* by a newline.
- *
+ *
* @param s {@code null-ok;} string to print
*/
protected final void println(String s) {
/**
* Gets whether this dump is to include raw bytes.
- *
+ *
* @return the raw bytes flag
*/
protected final boolean getRawBytes() {
/**
* Gets the width of the first column of output. This is {@code 0}
* unless raw bytes are being included in the output.
- *
+ *
* @return {@code >= 0;} the width of the first column
*/
protected final int getWidth1() {
/**
* Gets the width of the second column of output.
- *
+ *
* @return {@code >= 0;} the width of the second column
*/
protected final int getWidth2() {
/**
* Constructs a hex data dump of the given portion of {@link #bytes}.
- *
+ *
* @param offset offset to start dumping at
* @param len length to dump
* @return {@code non-null;} the dump
/**
* Combines a pair of strings as two columns, or if this is one-column
* output, format the otherwise-second column.
- *
+ *
* @param s1 {@code non-null;} the first column's string
* @param s2 {@code non-null;} the second column's string
* @return {@code non-null;} the combined output
/**
* {@code null-ok;} the class file object being constructed;
- * becomes non-null during {@link #dump}
+ * becomes non-null during {@link #dump}
*/
protected DirectClassFile classFile;
/**
* Dumps the given array, interpreting it as a class file and dumping
* methods with indications of block-level stuff.
- *
+ *
* @param bytes {@code non-null;} bytes of the (alleged) class file
* @param out {@code non-null;} where to dump to
* @param filePath the file path for the class, excluding any base
if (!shouldDumpMethod(name)) {
return;
}
-
+
ConcreteMethod meth = new ConcreteMethod((Method) member, classFile,
true, true);
/**
* Does a regular basic block dump.
- *
+ *
* @param meth {@code non-null;} method data to dump
*/
private void regularDump(ConcreteMethod meth) {
CstType exceptionClass = one.getExceptionClass();
parsed(bytes, end, 0,
"catch " +
- ((exceptionClass == CstType.OBJECT) ? "<any>" :
+ ((exceptionClass == CstType.OBJECT) ? "<any>" :
exceptionClass.toHuman()) + " -> " +
Hex.u2(one.getHandlerPc()));
}
/**
* Does a registerizing dump.
- *
+ *
* @param meth {@code non-null;} method data to dump
*/
private void ropDump(ConcreteMethod meth) {
public class SsaDumper extends BlockDumper {
/**
* Does the dump.
- *
+ *
* @param bytes {@code non-null;} bytes of the original class file
* @param out {@code non-null;} where to dump to
* @param filePath the file path for the class, excluding any base
/**
* Constructs an instance.
- *
+ *
* @param bytes {@code non-null;} bytes of the original class file
* @param out {@code non-null;} where to dump to
* @param filePath the file path for the class, excluding any base
sb.append('\n');
ArrayList<SsaBasicBlock> blocks = ssaMeth.getBlocks();
- ArrayList<SsaBasicBlock> sortedBlocks =
+ ArrayList<SsaBasicBlock> sortedBlocks =
(ArrayList<SsaBasicBlock>) blocks.clone();
Collections.sort(sortedBlocks, SsaBasicBlock.LABEL_COMPARATOR);
-
+
for (SsaBasicBlock block : sortedBlocks) {
sb.append("block ")
.append(Hex.u2(block.getRopLabel())).append('\n');
sb.append(Hex.u2(succLabelList.get(i)));
if (szSuccLabels != 1 && primary == succLabelList.get(i)) {
- sb.append(" *");
+ sb.append(" *");
}
sb.append('\n');
}
* combines both visible and invisible annotations into a single
* result set and also adds in a system annotation for the
* {@code Signature} attribute if present.
- *
+ *
* @param attribs {@code non-null;} the attributes list to search in
* @return {@code non-null;} the set of annotations, which may be empty
*/
* class is an annotation class, then this also includes a
* representation of all the {@code AnnotationDefault}
* values.
- *
+ *
* @param cf {@code non-null;} the class in question
* @param args {@code non-null;} the high-level options
* @return {@code non-null;} the set of annotations, which may be empty
* Gets the annotations out of a given method, similar to {@link
* #getAnnotations}, also including an annotation for the translation
* of the method-specific attribute {@code Exceptions}.
- *
+ *
* @param method {@code non-null;} the method in question
* @return {@code non-null;} the set of annotations, which may be empty
*/
TypeList exceptions = getExceptions(method);
if (exceptions.size() != 0) {
- Annotation throwsAnnotation =
+ Annotation throwsAnnotation =
AnnotationUtils.makeThrows(exceptions);
result = Annotations.combine(result, throwsAnnotation);
}
return result;
}
-
+
/**
* Helper method for {@link #getAnnotations} which just gets the
* existing annotations, per se.
- *
+ *
* @param attribs {@code non-null;} the attributes list to search in
* @return {@code non-null;} the set of annotations, which may be empty
*/
/**
* Gets the {@code Signature} attribute out of a given
* {@link AttributeList}, if any, translating it to an annotation.
- *
+ *
* @param attribs {@code non-null;} the attributes list to search in
* @return {@code null-ok;} the converted {@code Signature} annotation,
* if there was an attribute to translate
* If the class really has an enclosing method, this returns an
* {@code EnclosingMethod} annotation; if not, this returns
* an {@code EnclosingClass} annotation.
- *
+ *
* @param attribs {@code non-null;} the attributes list to search in
* @return {@code null-ok;} the converted {@code EnclosingMethod} or
* {@code EnclosingClass} annotation, if there was an
* {@link AttributeList}, if any, translating it to one or more of an
* {@code InnerClass}, {@code EnclosingClass}, or
* {@code MemberClasses} annotation.
- *
+ *
* @param thisClass {@code non-null;} type representing the class being processed
* @param attribs {@code non-null;} the attributes list to search in
* @param needEnclosingClass whether to include an
}
int membersSize = membersList.size();
-
+
if ((foundThisClass == null) && (membersSize == 0)) {
return null;
}
* Gets the parameter annotations out of a given method. This
* combines both visible and invisible annotations into a single
* result set.
- *
+ *
* @param method {@code non-null;} the method in question
* @return {@code non-null;} the list of annotation sets, which may be empty
*/
* Gets the {@code AnnotationDefault} attributes out of a
* given class, if any, reforming them as an
* {@code AnnotationDefault} annotation.
- *
+ *
* @param cf {@code non-null;} the class in question
* @return {@code null-ok;} an appropriately-constructed
* {@code AnnotationDefault} annotation, if there were any
/** whether strict file-name-vs-class-name checking should be done */
public boolean strictNameCheck = true;
-
+
/** whether to do SSA/register optimization */
public boolean optimize = false;
if (classAnnotations.size() != 0) {
out.setClassAnnotations(classAnnotations);
}
-
+
processFields(cf, out);
processMethods(cf, args, out);
out.addInstanceField(fi);
}
- Annotations annotations =
+ Annotations annotations =
AttributeTranslator.getAnnotations(one.getAttributes());
if (annotations.size() != 0) {
out.addFieldAnnotations(field, annotations);
/**
* Helper for {@link #processFields}, which translates constants into
* more specific types if necessary.
- *
+ *
* @param constant {@code non-null;} the constant in question
* @param type {@code non-null;} the desired type
*/
int paramSize;
paramSize = meth.getParameterWordCount(isStatic);
-
- String canonicalName
+
+ String canonicalName
= thisClass.getClassType().getDescriptor()
+ "." + one.getName().getString();
accessFlags &= ~AccessFlags.ACC_SYNCHRONIZED;
}
}
-
+
if (isConstructor) {
accessFlags |= AccessFlags.ACC_CONSTRUCTOR;
}
out.addVirtualMethod(mi);
}
- Annotations annotations =
+ Annotations annotations =
AttributeTranslator.getMethodAnnotations(one);
if (annotations.size() != 0) {
out.addMethodAnnotations(meth, annotations);
}
- AnnotationsList list =
+ AnnotationsList list =
AttributeTranslator.getParameterAnnotations(one);
if (list.size() != 0) {
out.addParameterAnnotations(meth, list);
* for the current purpose.
*/
- DalvCode.AssignIndicesCallback callback =
+ DalvCode.AssignIndicesCallback callback =
new DalvCode.AssignIndicesCallback() {
public int getIndex(Constant cst) {
// Everything is at index 0!
/**
* Updates the number of original bytecode bytes processed.
- *
+ *
* @param count {@code >= 0;} the number of bytes to add
*/
public static void updateOriginalByteCount(int count) {
/**
* Updates the dex statistics.
- *
+ *
* @param nonOptCode non-optimized code block
* @param code optimized code block
*/
/**
* Prints out the collected statistics.
- *
+ *
* @param out {@code non-null;} where to output to
*/
public static void dumpStatistics(PrintStream out) {
/**
* Loads the optimize/don't optimize lists from files.
- *
+ *
* @param optimizeListFile Pathname
* @param dontOptimizeListFile Pathname
*/
/**
* Loads a list of newline-separated strings into a new HashSet and returns
* the HashSet.
- *
+ *
* @param filename filename to process
* @return set of all unique lines in the file
*/
import java.util.ArrayList;
/**
- * Pseudo-instruction which holds fill array data.
+ * Pseudo-instruction which holds fill array data.
*/
public final class ArrayData extends VariableSizeInsn {
/**
* {@code non-null;} address representing the instruction that uses this
- * instance
+ * instance
*/
private final CodeAddress user;
/**
* Constructs an instance. The output address of this instance is initially
* unknown ({@code -1}).
- *
+ *
* @param position {@code non-null;} source position
* @param user {@code non-null;} address representing the instruction that
* uses this instance
/**
* Gets the instance for the start of the given block.
- *
+ *
* @param block {@code non-null;} the block in question
* @return {@code non-null;} the appropriate instance
*/
/**
* Gets the instance for the start of the block with the given label.
- *
+ *
* @param label {@code non-null;} the label of the block in question
* @return {@code non-null;} the appropriate instance
*/
/**
* Gets the instance for the final instruction of the given block.
- *
+ *
* @param block {@code non-null;} the block in question
* @return {@code non-null;} the appropriate instance
*/
/**
* Gets the instance for the final instruction of the block with
* the given label.
- *
+ *
* @param label {@code non-null;} the label of the block in question
* @return {@code non-null;} the appropriate instance
*/
/**
* Gets the instance for the end (address after the final instruction)
* of the given block.
- *
+ *
* @param block {@code non-null;} the block in question
* @return {@code non-null;} the appropriate instance
*/
/**
* Gets the instance for the end (address after the final instruction)
* of the block with the given label.
- *
+ *
* @param label {@code non-null;} the label of the block in question
* @return {@code non-null;} the appropriate instance
*/
public interface CatchBuilder {
/**
* Builds and returns the catch table for this instance.
- *
+ *
* @return {@code non-null;} the constructed table
*/
public CatchTable build();
/**
* Gets whether this instance has any catches at all (either typed
* or catch-all).
- *
+ *
* @return whether this instance has any catches at all
*/
public boolean hasAnyCatches();
-
+
/**
* Gets the set of catch types associated with this instance.
- *
+ *
* @return {@code non-null;} the set of catch types
*/
public HashSet<Type> getCatchTypes();
/**
* Get the human form of this instance, prefixed on each line
* with the string.
- *
+ *
* @param prefix {@code non-null;} the prefix for every line
* @param header {@code non-null;} the header for the first line (after the
* first prefix)
} else {
sb.append(entry.getExceptionType().toHuman());
}
-
+
sb.append(" -> ");
sb.append(Hex.u2or4(entry.getHandler()));
}
/**
* Returns whether or not this instance ends with a "catch-all"
* handler.
- *
+ *
* @return {@code true} if this instance ends with a "catch-all"
* handler or {@code false} if not
*/
return false;
}
-
+
/** {@inheritDoc} */
public int compareTo(Entry other) {
if (handler < other.handler) {
return exceptionType.compareTo(other.exceptionType);
}
-
+
/**
* Gets the exception type handled.
- *
+ *
* @return {@code non-null;} the exception type
*/
public CstType getExceptionType() {
/**
* Gets the handler address.
- *
+ *
* @return {@code >= 0;} the handler address
*/
public int getHandler() {
/**
* Constructs an instance.
*
- * @param start {@code >= 0;} start address
+ * @param start {@code >= 0;} start address
* @param end {@code > start;} end address (exclusive)
* @param handlers {@code non-null;} list of catch handlers
*/
return false;
}
-
+
/** {@inheritDoc} */
public int compareTo(Entry other) {
if (start < other.start) {
} else if (start > other.start) {
return 1;
}
-
+
if (end < other.end) {
return -1;
} else if (end > other.end) {
return handlers.compareTo(other.handlers);
}
-
+
/**
* Gets the start address.
- *
+ *
* @return {@code >= 0;} the start address
*/
public int getStart() {
/**
* Gets the end address (exclusive).
- *
+ *
* @return {@code > start;} the end address (exclusive)
*/
public int getEnd() {
/**
* Gets the handlers.
- *
+ *
* @return {@code non-null;} the handlers
*/
public CatchHandlerList getHandlers() {
/**
* Constructs an instance. The output address of this instance is initially
* unknown ({@code -1}).
- *
+ *
* @param position {@code non-null;} source position
*/
public CodeAddress(SourcePosition position) {
/**
* {@code >= -1;} the constant pool index for {@link #constant}, or
- * {@code -1} if not yet set
+ * {@code -1} if not yet set
*/
private int index;
/**
* {@code >= -1;} the constant pool index for the class reference in
- * {@link #constant} if any, or {@code -1} if not yet set
+ * {@link #constant} if any, or {@code -1} if not yet set
*/
private int classIndex;
/**
* Constructs an instance. The output address of this instance is
* initially unknown ({@code -1}) as is the constant pool index.
- *
+ *
* @param opcode the opcode; one of the constants from {@link Dops}
* @param position {@code non-null;} source position
* @param registers {@code non-null;} register list, including a
/** {@inheritDoc} */
@Override
public DalvInsn withOpcode(Dop opcode) {
- CstInsn result =
+ CstInsn result =
new CstInsn(opcode, getPosition(), getRegisters(), constant);
if (index >= 0) {
result.setIndex(index);
}
-
+
if (classIndex >= 0) {
result.setClassIndex(classIndex);
}
if (index >= 0) {
result.setIndex(index);
}
-
+
if (classIndex >= 0) {
result.setClassIndex(classIndex);
}
/**
* Gets the constant argument.
- *
+ *
* @return {@code non-null;} the constant argument
*/
public Constant getConstant() {
/**
* Gets the constant's index. It is only valid to call this after
* {@link #setIndex} has been called.
- *
+ *
* @return {@code >= 0;} the constant pool index
*/
public int getIndex() {
/**
* Returns whether the constant's index has been set for this instance.
- *
+ *
* @see #setIndex
- *
+ *
* @return {@code true} iff the index has been set
*/
public boolean hasIndex() {
/**
* Sets the constant's index. It is only valid to call this method once
* per instance.
- *
+ *
* @param index {@code >= 0;} the constant pool index
*/
public void setIndex(int index) {
/**
* Gets the constant's class index. It is only valid to call this after
* {@link #setClassIndex} has been called.
- *
+ *
* @return {@code >= 0;} the constant's class's constant pool index
*/
public int getClassIndex() {
/**
* Returns whether the constant's class index has been set for this
* instance.
- *
+ *
* @see #setClassIndex
- *
+ *
* @return {@code true} iff the index has been set
*/
public boolean hasClassIndex() {
* reference constants have a class, so it is only on instances
* with reference constants that this method should ever be
* called. It is only valid to call this method once per instance.
- *
+ *
* @param index {@code >= 0;} the constant's class's constant pool index
*/
public void setClassIndex(int index) {
public final class DalvCode {
/**
* how much position info to preserve; one of the static
- * constants in {@link PositionList}
+ * constants in {@link PositionList}
*/
private final int positionInfo;
/**
* {@code null-ok;} catch table; set in
- * {@link #finishProcessingIfNecessary}
+ * {@link #finishProcessingIfNecessary}
*/
private CatchTable catches;
/**
* {@code null-ok;} source positions list; set in
- * {@link #finishProcessingIfNecessary}
+ * {@link #finishProcessingIfNecessary}
*/
private PositionList positions;
* Assign indices in all instructions that need them, using the
* given callback to perform lookups. This must be called before
* {@link #getInsns}.
- *
+ *
* @param callback {@code non-null;} callback object
*/
public void assignIndices(AssignIndicesCallback callback) {
unprocessedInsns.assignIndices(callback);
}
-
+
/**
* Gets whether this instance has any position data to represent.
- *
+ *
* @return {@code true} iff this instance has any position
* data to represent
*/
return (positionInfo != PositionList.NONE)
&& unprocessedInsns.hasAnyPositionInfo();
}
-
+
/**
* Gets whether this instance has any local variable data to represent.
- *
+ *
* @return {@code true} iff this instance has any local variable
* data to represent
*/
/**
* Gets whether this instance has any catches at all (either typed
* or catch-all).
- *
+ *
* @return whether this instance has any catches at all
*/
public boolean hasAnyCatches() {
return unprocessedCatches.hasAnyCatches();
}
-
+
/**
* Gets the set of catch types handled anywhere in the code.
- *
+ *
* @return {@code non-null;} the set of catch types
*/
public HashSet<Type> getCatchTypes() {
/**
* Gets the set of all constants referred to by instructions in
* the code.
- *
+ *
* @return {@code non-null;} the set of constants
*/
public HashSet<Constant> getInsnConstants() {
/**
* Gets the list of instructions.
- *
+ *
* @return {@code non-null;} the instruction list
*/
public DalvInsnList getInsns() {
/**
* Gets the catch (exception handler) table.
- *
+ *
* @return {@code non-null;} the catch table
*/
public CatchTable getCatches() {
/**
* Gets the source positions list.
- *
+ *
* @return {@code non-null;} the source positions list
*/
public PositionList getPositions() {
/**
* Gets the source positions list.
- *
+ *
* @return {@code non-null;} the source positions list
*/
public LocalList getLocals() {
public static interface AssignIndicesCallback {
/**
* Gets the index for the given constant.
- *
+ *
* @param cst {@code non-null;} the constant
* @return {@code >= -1;} the index or {@code -1} if the constant
* shouldn't actually be reified with an index
public abstract class DalvInsn {
/**
* the actual output address of this instance, if known, or
- * {@code -1} if not
+ * {@code -1} if not
*/
private int address;
/**
* Makes a move instruction, appropriate and ideal for the given arguments.
- *
+ *
* @param position {@code non-null;} source position information
* @param dest {@code non-null;} destination register
* @param src {@code non-null;} source register
/**
* Constructs an instance. The output address of this instance is initially
* unknown ({@code -1}).
- *
+ *
* <p><b>Note:</b> In the unlikely event that an instruction takes
* absolutely no registers (e.g., a {@code nop} or a
* no-argument no-result static method call), then the given
* register list may be passed as {@link
* RegisterSpecList#EMPTY}.</p>
- *
+ *
* @param opcode the opcode; one of the constants from {@link Dops}
* @param position {@code non-null;} source position
* @param registers {@code non-null;} register list, including a
/**
* Gets whether the address of this instruction is known.
- *
+ *
* @see #getAddress
* @see #setAddress
*/
/**
* Gets the output address of this instruction, if it is known. This throws
* a {@code RuntimeException} if it has not yet been set.
- *
+ *
* @see #setAddress
- *
+ *
* @return {@code >= 0;} the output address
*/
public final int getAddress() {
/**
* Gets the opcode.
- *
+ *
* @return {@code non-null;} the opcode
*/
public final Dop getOpcode() {
/**
* Gets the source position.
- *
+ *
* @return {@code non-null;} the source position
*/
public final SourcePosition getPosition() {
/**
* Gets the register list for this instruction.
- *
+ *
* @return {@code non-null;} the registers
*/
public final RegisterSpecList getRegisters() {
* Returns whether this instance's opcode uses a result register.
* This method is a convenient shorthand for
* {@code getOpcode().hasResult()}.
- *
+ *
* @return {@code true} iff this opcode uses a result register
*/
public final boolean hasResult() {
* sources (if any), that each source register is unique, and that
* (to be explicit here) category-2 values take up two consecutive
* registers.
- *
+ *
* @return {@code >= 0;} the minimum distinct register requirement
*/
public final int getMinimumRegisterRequirement() {
/**
* Gets the instruction prefix required, if any, to use in a high
* register transformed version of this instance.
- *
+ *
* @see #hrVersion
- *
+ *
* @return {@code null-ok;} the prefix, if any
*/
public DalvInsn hrPrefix() {
/**
* Gets the instruction suffix required, if any, to use in a high
* register transformed version of this instance.
- *
+ *
* @see #hrVersion
- *
+ *
* @return {@code null-ok;} the suffix, if any
*/
public DalvInsn hrSuffix() {
* instance, and it is guaranteed that the number of low registers
* used will be the number returned by {@link
* #getMinimumRegisterRequirement}.
- *
+ *
* @return {@code non-null;} the replacement
*/
public DalvInsn hrVersion() {
- RegisterSpecList regs =
+ RegisterSpecList regs =
registers.withSequentialRegisters(0, hasResult());
return withRegisters(regs);
}
/**
* Gets the short identifier for this instruction. This is its
* address, if assigned, or its identity hashcode if not.
- *
+ *
* @return {@code non-null;} the identifier
*/
public final String identifierString() {
* Returns the string form of this instance suitable for inclusion in
* a human-oriented listing dump. This method will return {@code null}
* if this instance should not appear in a listing.
- *
+ *
* @param prefix {@code non-null;} prefix before the address; each follow-on
* line will be indented to match as well
* @param width {@code >= 0;} the width of the output or {@code 0} for
/**
* Sets the output address.
- *
+ *
* @param address {@code >= 0;} the output address
*/
public final void setAddress(int address) {
* calculable if this instance's address is known, and it is equal
* to the address plus the length of the instruction format of this
* instance's opcode.
- *
+ *
* @return {@code >= 0;} the next address
*/
public final int getNextAddress() {
/**
* Gets the size of this instruction, in 16-bit code units.
- *
+ *
* @return {@code >= 0;} the code size of this instruction
*/
public abstract int codeSize();
/**
* Writes this instance to the given output. This method should
* never annotate the output.
- *
+ *
* @param out {@code non-null;} where to write to
*/
public abstract void writeTo(AnnotatedOutput out);
/**
* Returns an instance that is just like this one, except that its
* opcode is replaced by the one given, and its address is reset.
- *
+ *
* @param opcode {@code non-null;} the new opcode
* @return {@code non-null;} an appropriately-constructed instance
*/
* Returns an instance that is just like this one, except that all
* register references have been offset by the given delta, and its
* address is reset.
- *
+ *
* @param delta the amount to offset register references by
* @return {@code non-null;} an appropriately-constructed instance
*/
* Returns an instance that is just like this one, except that the
* register list is replaced by the given one, and its address is
* reset.
- *
+ *
* @param registers {@code non-null;} new register list
* @return {@code non-null;} an appropriately-constructed instance
*/
/**
* Gets the string form for any arguments to this instance. Subclasses
* must override this.
- *
+ *
* @return {@code null-ok;} the string version of any arguments or
* {@code null} if there are none
*/
* address and without respect for any output formatting. This
* method should return {@code null} if this instance should
* not appear in a listing.
- *
+ *
* @param noteIndices whether to include an explicit notation of
* constant pool indices
* @return {@code null-ok;} the listing string
/**
* Constructs and returns an immutable instance whose elements are
* identical to the ones in the given list, in the same order.
- *
+ *
* @param list {@code non-null;} the list to use for elements
* @param regCount count, in register-units, of the number of registers
* this code block requires.
result.setImmutable();
return result;
}
-
+
/**
* Constructs an instance. All indices initially contain {@code null}.
- *
+ *
* @param size the size of the list
*/
public DalvInsnList(int size, int regCount) {
* Gets the element at the given index. It is an error to call
* this with the index for an element which was never set; if you
* do that, this will throw {@code NullPointerException}.
- *
+ *
* @param n {@code >= 0, < size();} which index
* @return {@code non-null;} element at that index
*/
/**
* Sets the instruction at the given index.
- *
+ *
* @param n {@code >= 0, < size();} which index
* @param insn {@code non-null;} the instruction to set at {@code n}
*/
* Gets the size of this instance, in 16-bit code units. This will only
* return a meaningful result if the instructions in this instance all
* have valid addresses.
- *
+ *
* @return {@code >= 0;} the size
*/
public int codeSize() {
/**
* Writes all the instructions in this instance to the given output
* destination.
- *
+ *
* @param out {@code non-null;} where to write to
*/
public void writeTo(AnnotatedOutput out) {
if (out.annotates()) {
boolean verbose = out.isVerbose();
-
+
for (int i = 0; i < sz; i++) {
DalvInsn insn = (DalvInsn) get0(i);
int codeBytes = insn.codeSize() * 2;
* Gets the size of the outgoing arguments area required by this
* method. This is equal to the largest argument word count of any
* method referred to by this instance.
- *
+ *
* @return {@code >= 0;} the required outgoing arguments size
*/
public int getOutsSize() {
/**
* Does a human-friendly dump of this instance.
- *
+ *
* @param out {@code non-null;} where to dump
* @param prefix {@code non-null;} prefix to attach to each line of output
* @param verbose whether to be verbose; verbose output includes
/**
* Does a human-friendly dump of this instance.
- *
+ *
* @param out {@code non-null;} where to dump
* @param prefix {@code non-null;} prefix to attach to each line of output
* @param verbose whether to be verbose; verbose output includes
/**
* Constructs an instance.
- *
+ *
* @param opcode {@code DalvOps.MIN_VALUE..DalvOps.MAX_VALUE;} the opcode
* value itself
* @param family {@code DalvOps.MIN_VALUE..DalvOps.MAX_VALUE;} the opcode family
/**
* Gets the opcode value.
- *
+ *
* @return {@code DalvOps.MIN_VALUE..DalvOps.MAX_VALUE;} the opcode value
*/
public int getOpcode() {
/**
* Gets the opcode family. The opcode family is the unmarked (no
* "/...") opcode that has equivalent semantics to this one.
- *
+ *
* @return {@code DalvOps.MIN_VALUE..DalvOps.MAX_VALUE;} the opcode family
*/
public int getFamily() {
/**
* Gets the instruction format.
- *
+ *
* @return {@code non-null;} the instruction format
*/
public InsnFormat getFormat() {
/**
* Returns whether this opcode uses a result register.
- *
+ *
* @return {@code true} iff this opcode uses a result register
*/
public boolean hasResult() {
/**
* Gets the opcode name.
- *
+ *
* @return {@code non-null;} the opcode name
*/
public String getName() {
/**
* Gets the opcode for the opposite test of this instance. This is only
* valid for opcodes which are in fact tests.
- *
+ *
* @return {@code non-null;} the opposite test
*/
public Dop getOppositeTest() {
private static final Dop[] DOPS;
/**
- * pseudo-opcode used for nonstandard formatted "instructions"
+ * pseudo-opcode used for nonstandard formatted "instructions"
* (which are mostly not actually instructions, though they do
- * appear in instruction lists)
+ * appear in instruction lists)
*/
public static final Dop SPECIAL_FORMAT =
new Dop(DalvOps.SPECIAL_FORMAT, DalvOps.SPECIAL_FORMAT,
/**
* Gets the {@link Dop} for the given opcode value.
- *
+ *
* @param opcode {@code DalvOps.MIN_VALUE..DalvOps.MAX_VALUE;} the opcode value
* @return {@code non-null;} the associated opcode instance
*/
/**
* Gets the {@link Dop} with the given family/format combination, if
* any.
- *
+ *
* @param family {@code DalvOps.MIN_VALUE..DalvOps.MAX_VALUE;} the opcode family
* @param format {@code non-null;} the opcode's instruction format
* @return {@code null-ok;} the corresponding opcode, or {@code null} if
/**
* Puts the given opcode into the table of all ops.
- *
+ *
* @param opcode {@code non-null;} the opcode
*/
private static void set(Dop opcode) {
/**
* Constructs an instance. The output address of this instance is initially
* unknown ({@code -1}).
- *
+ *
* <p><b>Note:</b> In the unlikely event that an instruction takes
* absolutely no registers (e.g., a {@code nop} or a
* no-argument no-result * static method call), then the given
* register list may be passed as {@link
* RegisterSpecList#EMPTY}.</p>
- *
+ *
* @param opcode the opcode; one of the constants from {@link Dops}
* @param position {@code non-null;} source position
* @param registers {@code non-null;} register list, including a
public final class HighRegisterPrefix extends VariableSizeInsn {
/** {@code null-ok;} cached instructions, if constructed */
private SimpleInsn[] insns;
-
+
/**
* Constructs an instance. The output address of this instance is initially
* unknown ({@code -1}).
- *
+ *
* @param position {@code non-null;} source position
* @param registers {@code non-null;} source registers
*/
if (insns != null) {
return;
}
-
+
RegisterSpecList registers = getRegisters();
int sz = registers.size();
insns = new SimpleInsn[sz];
-
+
for (int i = 0, outAt = 0; i < sz; i++) {
RegisterSpec src = registers.get(i);
insns[i] = moveInsnFor(src, outAt);
if (i != 0) {
sb.append('\n');
}
-
+
sb.append(insn.listingString0(noteIndices));
outAt += src.getCategory();
if (! ci.hasIndex()) {
return "";
}
-
+
StringBuilder sb = new StringBuilder(20);
int index = ci.getIndex();
} else {
sb.append(Hex.u4(index));
}
-
+
return sb.toString();
}
/**
* Writes one code unit to the given output destination.
- *
+ *
* @param out {@code non-null;} where to write to
* @param c0 code unit to write
*/
/**
* Writes two code units to the given output destination.
- *
+ *
* @param out {@code non-null;} where to write to
* @param c0 code unit to write
* @param c1 code unit to write
/**
* Writes three code units to the given output destination.
- *
+ *
* @param out {@code non-null;} where to write to
* @param c0 code unit to write
* @param c1 code unit to write
/**
* Writes four code units to the given output destination.
- *
+ *
* @param out {@code non-null;} where to write to
* @param c0 code unit to write
* @param c1 code unit to write
/**
* Writes five code units to the given output destination.
- *
+ *
* @param out {@code non-null;} where to write to
* @param c0 code unit to write
* @param c1 code unit to write
/**
* Writes six code units to the given output destination.
- *
+ *
* @param out {@code non-null;} where to write to
* @param c0 code unit to write
* @param c1 code unit to write
/**
* Constructs an instance. The output address of this instance is initially
* unknown ({@code -1}).
- *
+ *
* @param position {@code non-null;} source position
* @param local {@code non-null;} register spec representing the local
* variable introduced by this instance
/**
* Gets the register spec representing the local variable ended
* by this instance.
- *
+ *
* @return {@code non-null;} the register spec
*/
public RegisterSpec getLocal() {
/**
* Constructs an instance. The output address of this instance is initially
* unknown ({@code -1}).
- *
+ *
* @param position {@code non-null;} source position
* @param locals {@code non-null;} associated local variable state
*/
/**
* Gets the local state associated with this instance.
- *
+ *
* @return {@code non-null;} the state
*/
public RegisterSpecSet getLocals() {
public final class LocalStart extends ZeroSizeInsn {
/**
* {@code non-null;} register spec representing the local variable introduced
- * by this instance
+ * by this instance
*/
private final RegisterSpec local;
/**
* Returns the local variable listing string for a single register spec.
- *
+ *
* @param spec {@code non-null;} the spec to convert
* @return {@code non-null;} the string form
*/
/**
* Constructs an instance. The output address of this instance is initially
* unknown ({@code -1}).
- *
+ *
* @param position {@code non-null;} source position
* @param local {@code non-null;} register spec representing the local
* variable introduced by this instance
/**
* Gets the register spec representing the local variable introduced
* by this instance.
- *
+ *
* @return {@code non-null;} the register spec
*/
public RegisterSpec getLocal() {
/**
* Constructs an instance. The output address of this instance is initially
* unknown ({@code -1}).
- *
+ *
* @param position {@code non-null;} source position
*/
public OddSpacer(SourcePosition position) {
/**
* Constructs an instance.
- *
+ *
* @param initialCapacity {@code >= 0;} initial capacity of the output list
* @param suffixInitialCapacity {@code >= 0;} initial capacity of the output
* suffix
/**
* Adds an instruction to the output.
- *
- * @param insn {@code non-null;} the instruction to add
+ *
+ * @param insn {@code non-null;} the instruction to add
*/
public void add(DalvInsn insn) {
finisher.add(insn);
* Reverses a branch which is buried a given number of instructions
* backward in the output. It is illegal to call this unless the
* indicated instruction really is a reversible branch.
- *
+ *
* @param which how many instructions back to find the branch;
* {@code 0} is the most recently added instruction,
* {@code 1} is the instruction before that, etc.
/**
* Adds an instruction to the output suffix.
- *
- * @param insn {@code non-null;} the instruction to add
+ *
+ * @param insn {@code non-null;} the instruction to add
*/
public void addSuffix(DalvInsn insn) {
suffix.add(insn);
if (suffix == null) {
throw new UnsupportedOperationException("already processed");
}
-
+
appendSuffixToOutput();
return finisher;
}
/**
* Constructs an instance. It initially contains no instructions.
- *
+ *
* @param regCount {@code >= 0;} register count for the method
* @param initialCapacity {@code >= 0;} initial capacity of the instructions
* list
/**
* Returns whether any of the instructions added to this instance
* come with position info.
- *
+ *
* @return whether any of the instructions added to this instance
* come with position info
*/
public boolean hasAnyPositionInfo() {
return hasAnyPositionInfo;
}
-
+
/**
* Returns whether this instance has any local variable information.
- *
+ *
* @return whether this instance has any local variable information
*/
public boolean hasAnyLocalInfo() {
/**
* Helper for {@link #add} which scrutinizes a single
* instruction for local variable information.
- *
+ *
* @param insn {@code non-null;} instruction to scrutinize
* @return {@code true} iff the instruction refers to any
* named locals
/**
* Helper for {@link #hasAnyLocalInfo} which scrutinizes a single
* register spec.
- *
+ *
* @param spec {@code non-null;} spec to scrutinize
* @return {@code true} iff the spec refers to any
* named locals
/**
* Returns the set of all constants referred to by instructions added
* to this instance.
- *
+ *
* @return {@code non-null;} the set of constants
*/
public HashSet<Constant> getAllConstants() {
/**
* Helper for {@link #getAllConstants} which adds all the info for
* a single instruction.
- *
+ *
* @param result {@code non-null;} result set to add to
* @param insn {@code non-null;} instruction to scrutinize
*/
if (spec == null) {
return;
}
-
+
LocalItem local = spec.getLocalItem();
CstUtf8 name = local.getName();
CstUtf8 signature = local.getSignature();
/**
* Adds an instruction to the output.
- *
- * @param insn {@code non-null;} the instruction to add
+ *
+ * @param insn {@code non-null;} the instruction to add
*/
public void add(DalvInsn insn) {
insns.add(insn);
/**
* Inserts an instruction in the output at the given offset.
- *
+ *
* @param at {@code >= 0;} what index to insert at
* @param insn {@code non-null;} the instruction to insert
*/
/**
* Helper for {@link #add} and {@link #insert},
* which updates the position and local info flags.
- *
+ *
* @param insn {@code non-null;} an instruction that was just introduced
*/
private void updateInfo(DalvInsn insn) {
* Reverses a branch which is buried a given number of instructions
* backward in the output. It is illegal to call this unless the
* indicated instruction really is a reversible branch.
- *
+ *
* @param which how many instructions back to find the branch;
* {@code 0} is the most recently added instruction,
* {@code 1} is the instruction before that, etc.
* Assigns indices in all instructions that need them, using the
* given callback to perform lookups. This should be called before
* calling {@link #finishProcessingAndGetList}.
- *
+ *
* @param callback {@code non-null;} callback object
*/
public void assignIndices(DalvCode.AssignIndicesCallback callback) {
/**
* Helper for {@link #assignIndices} which does assignment for one
* instruction.
- *
+ *
* @param insn {@code non-null;} the instruction
* @param callback {@code non-null;} the callback
*/
/**
* Does final processing on this instance and gets the output as
* a {@link DalvInsnList}. Final processing consists of:
- *
+ *
* <ul>
* <li>optionally renumbering registers (to make room as needed for
* expanded instructions)</li>
* constant pool index, or branch target size issues</li>
* <li>assigning final addresses</li>
* </ul>
- *
+ *
* <p><b>Note:</b> This method may only be called once per instance
* of this class.</p>
*
* Helper for {@link #finishProcessingAndGetList}, which extracts
* the format out of each instruction into a separate array, to be
* further manipulated as things progress.
- *
+ *
* @return {@code non-null;} the array of formats
*/
private InsnFormat[] makeFormatsArray() {
* them. It also updates the given {@code formats} array so
* as to avoid extra work when constructing the massaged
* instruction list.
- *
+ *
* @param formats {@code non-null;} array of per-instruction format selections
*/
private void reserveRegisters(InsnFormat[] formats) {
int oldReservedCount = (reservedCount < 0) ? 0 : reservedCount;
-
+
/*
* Call calculateReservedCount() and then perform register
* reservation, repeatedly until no new reservations happen.
/*
* No need to call this.set() since the format and
* other info are the same.
- */
+ */
insns.set(i, insn.withRegisterOffset(reservedDifference));
}
}
* registers that need to be reserved. It also updates the
* {@code formats} list to help avoid extra work in future
* register reservation passes.
- *
+ *
* @param formats {@code non-null;} array of per-instruction format selections
* @return {@code >= 0;} the count of reserved registers
*/
if (originalFormat == newFormat) {
continue;
}
-
+
if (newFormat == null) {
/*
* The instruction will need to be expanded, so reserve
for (;;) {
format = format.nextUp();
if ((format == null) ||
- (format.isCompatible(insn) &&
+ (format.isCompatible(insn) &&
(Dops.getOrNull(family, format) != null))) {
break;
}
return format;
}
-
+
/**
* Helper for {@link #finishProcessingAndGetList}, which goes
* through each instruction in the output, making sure its opcode
* can accomodate its arguments. In cases where the opcode is
* unable to do so, this replaces the instruction with a larger
* instruction with identical semantics that <i>will</i> work.
- *
+ *
* <p>This method may also reserve a number of low-numbered
* registers, renumbering the instructions' original registers, in
* order to have register space available in which to move
* multi-instruction sequences. This expansion is done when no
* simple instruction format can be found for a given instruction that
* is able to accomodate that instruction's registers.</p>
- *
+ *
* <p>This method ignores issues of branch target size, since
* final addresses aren't known at the point that this method is
* called.</p>
- *
+ *
* @param formats {@code non-null;} array of per-instruction format selections
*/
private void massageInstructions(InsnFormat[] formats) {
* couldn't be represented simply (due to register representation
* problems) is expanded into a series of instances that together
* perform the proper function.
- *
+ *
* @param formats {@code non-null;} array of per-instruction format selections
* @return {@code non-null;} the replacement list
*/
if (prefix != null) {
result.add(prefix);
}
-
+
if (currentFormat != originalFormat) {
dop = Dops.getOrNull(dop.getFamily(), currentFormat);
insn = insn.withOpcode(dop);
result.add(suffix);
}
}
-
+
return result;
}
* case of a conditional branch that doesn't fit, the sense of the
* test is reversed in order to branch around a {@code goto}
* to the original target.
- *
+ *
* @return whether any branches had to be fixed
*/
private boolean fixBranches() {
* It is a conditional: Reverse its sense, and arrange for
* it to branch around an absolute goto to the original
* branch target.
- *
+ *
* Note: An invariant of the list being processed is
* that every TargetInsn is followed by a CodeAddress.
* Hence, it is always safe to get the next element
* after a TargetInsn and cast it to CodeAddress, as
* is happening a few lines down.
- *
+ *
* Also note: Size gets incremented by one here, as we
* have -- in the net -- added one additional element
* to the list, so we increment i to match. The added
/**
* constant for {@link #make} to indicate that no actual position
- * information should be returned
+ * information should be returned
*/
public static final int NONE = 1;
/**
* constant for {@link #make} to indicate that only line number
- * transitions should be returned
+ * transitions should be returned
*/
public static final int LINES = 2;
/**
* constant for {@link #make} to indicate that only "important" position
* information should be returned. This includes block starts and
- * instructions that might throw.
+ * instructions that might throw.
*/
public static final int IMPORTANT = 3;
/**
* Extracts and returns the source position information out of an
* instruction list.
- *
+ *
* @param insns {@code non-null;} instructions to convert
* @param howMuch how much information should be included; one of the
* static constants defined by this class
/**
* Constructs an instance. All indices initially contain {@code null}.
- *
+ *
* @param size {@code >= 0;} the size of the list
*/
public PositionList(int size) {
* Gets the element at the given index. It is an error to call
* this with the index for an element which was never set; if you
* do that, this will throw {@code NullPointerException}.
- *
+ *
* @param n {@code >= 0, < size();} which index
* @return {@code non-null;} element at that index
*/
/**
* Sets the entry at the given index.
- *
+ *
* @param n {@code >= 0, < size();} which index
* @param entry {@code non-null;} the entry to set at {@code n}
*/
/**
* Constructs an instance.
- *
+ *
* @param address {@code >= 0;} address of this entry
* @param position {@code non-null;} corresponding source position information
*/
/**
* Gets the address.
- *
+ *
* @return {@code >= 0;} the address
*/
public int getAddress() {
/**
* Gets the source position information.
- *
+ *
* @return {@code non-null;} the position information
*/
public SourcePosition getPosition() {
/**
* Returns the dalvik opcode appropriate for the given register-based
* instruction.
- *
+ *
* @param insn {@code non-null;} the original instruction
* @return the corresponding dalvik opcode; one of the constants in
* {@link Dops}
/*
* There was no easy case for the rop, so look up the opcode, and
* do something special for each:
- *
+ *
* The move_exception, new_array, filled_new_array, and
* invoke* opcodes won't be found in MAP, since they'll each
* have different source and/or result register types / lists.
- *
+ *
* The get* and put* opcodes for (non-long) integral types
* aren't in the map, since the type signatures aren't
* sufficient to distinguish between the types (the salient
* source or result will always be just "int").
- *
+ *
* And const instruction need to distinguish between strings and
* classes.
*/
case RegOps.INVOKE_INTERFACE: return Dops.INVOKE_INTERFACE;
case RegOps.NEW_ARRAY: return Dops.NEW_ARRAY;
case RegOps.FILLED_NEW_ARRAY: return Dops.FILLED_NEW_ARRAY;
- case RegOps.FILL_ARRAY_DATA: return Dops.FILL_ARRAY_DATA;
+ case RegOps.FILL_ARRAY_DATA: return Dops.FILL_ARRAY_DATA;
case RegOps.MOVE_RESULT: {
RegisterSpec resultReg = insn.getResult();
/**
* how much position info to preserve; one of the static
- * constants in {@link PositionList}
+ * constants in {@link PositionList}
*/
private final int positionInfo;
/**
* Translates a {@link RopMethod}. This may modify the given
* input.
- *
+ *
* @param method {@code non-null;} the original method
* @param positionInfo how much position info to preserve; one of the
* static constants in {@link PositionList}
/**
* Constructs an instance. This method is private. Use {@link #translate}.
- *
+ *
* @param method {@code non-null;} the original method
* @param positionInfo how much position info to preserve; one of the
* static constants in {@link PositionList}
* stack frame that matches dalvik's calling conventions. This will
* alway result in "true" for methods that have run through the
* SSA optimizer.
- *
+ *
* @param paramSize size, in register units, of all the parameters
* to this method
*/
/**
* Does the translation and returns the result.
- *
+ *
* @return {@code non-null;} the result
*/
private DalvCode translateAndGetResult() {
/**
* Helper for {@link #outputInstructions}, which does the processing
* and output of one block.
- *
+ *
* @param block {@code non-null;} the block to process and output
* @param nextLabel {@code >= -1;} the next block that will be processed, or
* {@code -1} if there is no next block
// Insert the block end code address.
output.add(addresses.getEnd(block));
- // Set up for end-of-block activities.
+ // Set up for end-of-block activities.
int succ = block.getPrimarySuccessor();
Insn lastInsn = block.getLastInsn();
if (preferredBlock == null) {
break;
}
-
+
int preferred = preferredBlock.getLabel();
int primary = one.getPrimarySuccessor();
}
}
}
- }
+ }
if (at != sz) {
// There was a duplicate block label.
/**
* {@code null-ok;} code address for the salient last instruction of the
- * block (used before switches and throwing instructions)
+ * block (used before switches and throwing instructions)
*/
private CodeAddress lastAddress;
/**
* Constructs an instance.
- *
+ *
* @param output {@code non-null;} destination for instruction output
*/
public TranslationVisitor(OutputCollector output) {
/**
* Sets the block currently being worked on.
- *
+ *
* @param block {@code non-null;} the block
* @param lastAddress {@code non-null;} code address for the salient
* last instruction of the block
return null;
} else {
return insn.getResult();
- }
+ }
}
/** {@inheritDoc} */
"Insn with result/move-result-pseudo mismatch " +
insn);
}
-
+
if ((rop.getOpcode() == RegOps.NEW_ARRAY) &&
(opcode.getOpcode() != DalvOps.NEW_ARRAY)) {
/*
throw new RuntimeException(
"Insn with result/move-result-pseudo mismatch" + insn);
}
-
+
addOutput(lastAddress);
DalvInsn di = new SimpleInsn(opcode, pos,
CodeAddress dataAddress = new CodeAddress(pos);
ArrayData dataInsn =
new ArrayData(pos, lastAddress, values, cst);
-
+
TargetInsn fillArrayDataInsn =
new TargetInsn(Dops.FILL_ARRAY_DATA, pos, getRegs(insn),
dataAddress);
addOutputSuffix(dataAddress);
addOutputSuffix(dataInsn);
}
-
+
/**
* Adds to the output.
- *
+ *
* @param insn {@code non-null;} instruction to add
*/
protected void addOutput(DalvInsn insn) {
/**
* Adds to the output suffix.
- *
+ *
* @param insn {@code non-null;} instruction to add
*/
protected void addOutputSuffix(DalvInsn insn) {
/**
* Constructs an instance.
- *
+ *
* @param output {@code non-null;} destination for instruction output
* @param locals {@code non-null;} the local variable info
*/
/**
* Adds a {@link LocalStart} to the output if the given
* instruction in fact introduces a local variable.
- *
+ *
* @param insn {@code non-null;} instruction in question
*/
public void addIntroductionIfNecessary(Insn insn) {
addOutput(new LocalStart(insn.getPosition(), spec));
}
}
- }
+ }
}
/**
* Constructs an instance. The output address of this instance is initially
* unknown ({@code -1}).
- *
+ *
* @param opcode the opcode; one of the constants from {@link Dops}
* @param position {@code non-null;} source position
* @param registers {@code non-null;} register list, including a
public final class StdCatchBuilder implements CatchBuilder {
/** the maximum range of a single catch handler, in code units */
private static final int MAX_CATCH_RANGE = 65535;
-
+
/** {@code non-null;} method to build the list for */
private final RopMethod method;
/** {@code non-null;} address objects for each block */
private final BlockAddresses addresses;
-
+
/**
* Constructs an instance. It merely holds onto its parameters for
* a subsequent call to {@link #build}.
- *
+ *
* @param method {@code non-null;} method to build the list for
* @param order {@code non-null;} block output order
* @param addresses {@code non-null;} address objects for each block
public boolean hasAnyCatches() {
BasicBlockList blocks = method.getBlocks();
int size = blocks.size();
-
+
for (int i = 0; i < size; i++) {
BasicBlock block = blocks.get(i);
TypeList catches = block.getLastInsn().getCatches();
return false;
}
-
+
/** {@inheritDoc} */
public HashSet<Type> getCatchTypes() {
HashSet<Type> result = new HashSet<Type>(20);
BasicBlockList blocks = method.getBlocks();
int size = blocks.size();
-
+
for (int i = 0; i < size; i++) {
BasicBlock block = blocks.get(i);
TypeList catches = block.getLastInsn().getCatches();
/**
* Builds and returns the catch table for a given method.
- *
+ *
* @param method {@code non-null;} method to build the list for
* @param order {@code non-null;} block output order
* @param addresses {@code non-null;} address objects for each block
CatchHandlerList currentHandlers = CatchHandlerList.EMPTY;
BasicBlock currentStartBlock = null;
BasicBlock currentEndBlock = null;
-
+
for (int i = 0; i < len; i++) {
BasicBlock block = blocks.labelToBlock(order[i]);
currentHandlers, addresses);
resultList.add(entry);
}
-
+
// Construct the final result.
int resultSz = resultList.size();
-
+
if (resultSz == 0) {
return CatchTable.EMPTY;
}
/**
* Makes the {@link CatchHandlerList} for the given basic block.
- *
+ *
* @param block {@code non-null;} block to get entries for
* @param addresses {@code non-null;} address objects for each block
* @return {@code non-null;} array of entries
break;
}
}
-
+
CatchHandlerList result = new CatchHandlerList(catchSize);
for (int i = 0; i < catchSize; i++) {
* Gets whether the address range for the given two blocks is valid
* for a catch handler. This is true as long as the covered range is
* under 65536 code units.
- *
+ *
* @param start {@code non-null;} the start block for the range (inclusive)
* @param end {@code non-null;} the start block for the range (also inclusive)
* @param addresses {@code non-null;} address objects for each block
if (end == null) {
throw new NullPointerException("end == null");
}
-
+
// See above about selection of instructions.
int startAddress = addresses.getLast(start).getAddress();
int endAddress = addresses.getEnd(end).getAddress();
public final class SwitchData extends VariableSizeInsn {
/**
* {@code non-null;} address representing the instruction that uses this
- * instance
+ * instance
*/
private final CodeAddress user;
/**
* {@code non-null;} corresponding list of code addresses; the branch
- * target for each case
+ * target for each case
*/
private final CodeAddress[] targets;
/**
* Constructs an instance. The output address of this instance is initially
* unknown ({@code -1}).
- *
+ *
* @param position {@code non-null;} source position
* @param user {@code non-null;} address representing the instruction that
* uses this instance
/**
* Returns whether or not this instance's data will be output as packed.
- *
+ *
* @return {@code true} iff the data is to be packed
*/
public boolean isPacked() {
/**
* Gets the size of a packed table for the given cases, in 16-bit code
* units.
- *
+ *
* @param cases {@code non-null;} sorted list of cases
* @return {@code >= -1;} the packed table size or {@code -1} if the
* cases couldn't possibly be represented as a packed table
/**
* Gets the size of a sparse table for the given cases, in 16-bit code
* units.
- *
+ *
* @param cases {@code non-null;} sorted list of cases
* @return {@code > 0;} the sparse table size
*/
/**
* Determines whether the given list of cases warrant being packed.
- *
+ *
* @param cases {@code non-null;} sorted list of cases
* @return {@code true} iff the table encoding the cases
* should be packed
* Constructs an instance. The output address of this instance is initially
* unknown ({@code -1}), and the target is initially
* {@code null}.
- *
+ *
* @param opcode the opcode; one of the constants from {@link Dops}
* @param position {@code non-null;} source position
* @param registers {@code non-null;} register list, including a
* {@code lt} test becomes a {@code ge}), and its branch
* target is replaced by the one given, and all set-once values
* associated with the class (such as its address) are reset.
- *
+ *
* @param target {@code non-null;} the new branch target
* @return {@code non-null;} an appropriately-constructed instance
*/
/**
* Gets the unique branch target of this instruction.
- *
+ *
* @return {@code non-null;} the branch target
*/
public CodeAddress getTarget() {
* to call if the target instruction has been assigned an address,
* and it is merely a convenient shorthand for
* {@code getTarget().getAddress()}.
- *
+ *
* @return {@code >= 0;} the target address
*/
public int getTargetAddress() {
* call if both this and the target instruction each has been assigned
* an address, and it is merely a convenient shorthand for
* {@code getTargetAddress() - getAddress()}.
- *
+ *
* @return the branch offset
*/
public int getTargetOffset() {
/**
* Returns whether the target offset is known.
- *
+ *
* @return {@code true} if the target offset is known or
* {@code false} if not
*/
/**
* Constructs an instance. The output address of this instance is initially
* unknown ({@code -1}).
- *
+ *
* @param position {@code non-null;} source position
* @param registers {@code non-null;} source registers
*/
/**
* Constructs an instance. The output address of this instance is initially
* unknown ({@code -1}).
- *
+ *
* @param position {@code non-null;} source position
*/
public ZeroSizeInsn(SourcePosition position) {
if (! unsignedFitsInShort(cpi)) {
return false;
}
-
+
Constant cst = ci.getConstant();
return (cst instanceof CstType) ||
(cst instanceof CstFieldRef);
int r4 = (sz > 4) ? regs.get(4).getReg() : 0;
write(out,
- opcodeUnit(insn,
+ opcodeUnit(insn,
makeByte(r4, sz)), // encode the fifth operand here
(short) cpi,
codeUnit(r0, r1, r2, r3));
* category-2 values count as two words. Return {@code -1} if the
* list requires more than five words or contains registers that need
* more than a nibble to identify them.
- *
+ *
* @param regs {@code non-null;} the register list in question
- * @return {@code >= -1;} the number of words required, or {@code -1}
+ * @return {@code >= -1;} the number of words required, or {@code -1}
* if the list couldn't possibly fit in this format
*/
private static int wordCount(RegisterSpecList regs) {
* except that it splits category-2 registers into two explicit
* entries. This returns the original list if no modification is
* required
- *
+ *
* @param orig {@code non-null;} the original list
* @return {@code non-null;} the list with the described transformation
*/
*/
lastReg = lastReg.withOffset(1);
}
-
+
sb.append(regs.get(0).regString());
sb.append("..");
sb.append(lastReg.regString());
sb.append("}, ");
sb.append(cstString(insn));
-
+
return sb.toString();
}
public final class AnnotationItem extends OffsettedItem {
/** annotation visibility constant: visible at build time only */
private static final int VISIBILITY_BUILD = 0;
-
+
/** annotation visibility constant: visible at runtime */
private static final int VISIBILITY_RUNTIME = 1;
/** annotation visibility constant: visible at runtime only to system */
private static final int VISIBILITY_SYSTEM = 2;
-
+
/** the required alignment for instances of this class */
private static final int ALIGNMENT = 1;
/** {@code non-null;} unique instance of {@link #TypeIdSorter} */
private static final TypeIdSorter TYPE_ID_SORTER = new TypeIdSorter();
-
+
/** {@code non-null;} the annotation to represent */
private final Annotation annotation;
* Sorts an array of instances, in place, by type id index,
* ignoring all other aspects of the elements. This is only valid
* to use after type id indices are known.
- *
+ *
* @param array {@code non-null;} array to sort
*/
public static void sortByTypeIdIndex(AnnotationItem[] array) {
/**
* Constructs an instance.
- *
+ *
* @param annotation {@code non-null;} annotation to represent
*/
public AnnotationItem(Annotation annotation) {
* Write a (listing file) annotation for this instance to the given
* output, that consumes no bytes of output. This is for annotating
* a reference to this instance at the point of the reference.
- *
+ *
* @param out {@code non-null;} where to output to
* @param prefix {@code non-null;} prefix for each line of output
*/
throw new RuntimeException("shouldn't happen");
}
}
-
+
if (annotates) {
/*
* The output is to be annotated, so redo the work previously
/** {@code non-null;} the set of annotations */
private final Annotations annotations;
-
+
/**
* {@code non-null;} set of annotations as individual items in an array.
* <b>Note:</b> The contents have to get sorted by type id before
/**
* Constructs an instance.
- *
+ *
* @param annotations {@code non-null;} set of annotations
*/
public AnnotationSetItem(Annotations annotations) {
/**
* Gets the write size for the given set.
- *
+ *
* @param annotations {@code non-null;} the set
* @return {@code > 0;} the write size
*/
/**
* Gets the underlying annotations of this instance
- *
+ *
* @return {@code non-null;} the annotations
*/
public Annotations getAnnotations() {
return annotations;
}
-
+
/** {@inheritDoc} */
@Override
public int hashCode() {
}
out.writeInt(size);
-
+
for (int i = 0; i < size; i++) {
AnnotationItem item = items[i];
int offset = item.getAbsoluteOffset();
-
+
if (annotates) {
out.annotate(4, " entries[" + Integer.toHexString(i) + "]: " +
Hex.u4(offset));
/**
* Constructs an instance.
- *
+ *
* @param annotations {@code non-null;} the annotation set to refer to
*/
public AnnotationSetRefItem(AnnotationSetItem annotations) {
*/
public final class AnnotationUtils {
/** {@code non-null;} type for {@code AnnotationDefault} annotations */
- private static final CstType ANNOTATION_DEFAULT_TYPE =
+ private static final CstType ANNOTATION_DEFAULT_TYPE =
CstType.intern(Type.intern("Ldalvik/annotation/AnnotationDefault;"));
/** {@code non-null;} type for {@code EnclosingClass} annotations */
- private static final CstType ENCLOSING_CLASS_TYPE =
+ private static final CstType ENCLOSING_CLASS_TYPE =
CstType.intern(Type.intern("Ldalvik/annotation/EnclosingClass;"));
/** {@code non-null;} type for {@code EnclosingMethod} annotations */
- private static final CstType ENCLOSING_METHOD_TYPE =
+ private static final CstType ENCLOSING_METHOD_TYPE =
CstType.intern(Type.intern("Ldalvik/annotation/EnclosingMethod;"));
/** {@code non-null;} type for {@code InnerClass} annotations */
- private static final CstType INNER_CLASS_TYPE =
+ private static final CstType INNER_CLASS_TYPE =
CstType.intern(Type.intern("Ldalvik/annotation/InnerClass;"));
/** {@code non-null;} type for {@code MemberClasses} annotations */
- private static final CstType MEMBER_CLASSES_TYPE =
+ private static final CstType MEMBER_CLASSES_TYPE =
CstType.intern(Type.intern("Ldalvik/annotation/MemberClasses;"));
/** {@code non-null;} type for {@code Signature} annotations */
- private static final CstType SIGNATURE_TYPE =
+ private static final CstType SIGNATURE_TYPE =
CstType.intern(Type.intern("Ldalvik/annotation/Signature;"));
/** {@code non-null;} type for {@code Throws} annotations */
- private static final CstType THROWS_TYPE =
+ private static final CstType THROWS_TYPE =
CstType.intern(Type.intern("Ldalvik/annotation/Throws;"));
/** {@code non-null;} the UTF-8 constant {@code "accessFlags"} */
/**
* Constructs a standard {@code AnnotationDefault} annotation.
- *
+ *
* @param defaults {@code non-null;} the defaults, itself as an annotation
* @return {@code non-null;} the constructed annotation
*/
/**
* Constructs a standard {@code EnclosingClass} annotation.
- *
+ *
* @param clazz {@code non-null;} the enclosing class
* @return {@code non-null;} the annotation
*/
/**
* Constructs a standard {@code EnclosingMethod} annotation.
- *
+ *
* @param method {@code non-null;} the enclosing method
* @return {@code non-null;} the annotation
*/
/**
* Constructs a standard {@code InnerClass} annotation.
- *
+ *
* @param name {@code null-ok;} the original name of the class, or
* {@code null} to represent an anonymous class
* @param accessFlags the original access flags
/**
* Constructs a standard {@code MemberClasses} annotation.
- *
+ *
* @param types {@code non-null;} the list of (the types of) the member classes
* @return {@code non-null;} the annotation
*/
/**
* Constructs a standard {@code Signature} annotation.
- *
+ *
* @param signature {@code non-null;} the signature string
* @return {@code non-null;} the annotation
*/
* Split the string into pieces that are likely to be common
* across many signatures and the rest of the file.
*/
-
+
String raw = signature.getString();
int rawLength = raw.length();
ArrayList<String> pieces = new ArrayList<String>(20);
}
list.setImmutable();
-
+
result.put(new NameValuePair(VALUE_UTF, new CstArray(list)));
result.setImmutable();
return result;
/**
* Constructs a standard {@code Throws} annotation.
- *
+ *
* @param types {@code non-null;} the list of thrown types
* @return {@code non-null;} the annotation
*/
/**
* Converts a {@link TypeList} to a {@link CstArray}.
- *
+ *
* @param types {@code non-null;} the type list
* @return {@code non-null;} the corresponding array constant
*/
/** {@code null-ok;} the class-level annotations, if any */
private AnnotationSetItem classAnnotations;
-
+
/** {@code null-ok;} the annotated fields, if any */
private ArrayList<FieldAnnotationStruct> fieldAnnotations;
methodAnnotations = null;
parameterAnnotations = null;
}
-
+
/** {@inheritDoc} */
@Override
public ItemType itemType() {
/**
* Returns whether this item is empty (has no contents).
- *
+ *
* @return {@code true} if this item is empty, or {@code false}
* if not
*/
if (classAnnotations == null) {
return 0;
}
-
+
return classAnnotations.hashCode();
}
-
+
/**
* {@inheritDoc}
- *
+ *
* <p><b>Note:</b>: This throws an exception if this item is not
* internable.</p>
- *
+ *
* @see #isInternable
*/
@Override
* Sets the direct annotations on this instance. These are annotations
* made on the class, per se, as opposed to on one of its members.
* It is only valid to call this method at most once per instance.
- *
+ *
* @param annotations {@code non-null;} annotations to set for this class
*/
public void setClassAnnotations(Annotations annotations) {
if (annotations == null) {
throw new NullPointerException("annotations == null");
}
-
+
if (classAnnotations != null) {
throw new UnsupportedOperationException(
"class annotations already set");
/**
* Adds a field annotations item to this instance.
- *
+ *
* @param field {@code non-null;} field in question
* @param annotations {@code non-null;} associated annotations to add
*/
if (fieldAnnotations == null) {
fieldAnnotations = new ArrayList<FieldAnnotationStruct>();
}
-
+
fieldAnnotations.add(new FieldAnnotationStruct(field,
new AnnotationSetItem(annotations)));
}
/**
* Adds a method annotations item to this instance.
- *
+ *
* @param method {@code non-null;} method in question
* @param annotations {@code non-null;} associated annotations to add
*/
/**
* Adds a parameter annotations item to this instance.
- *
+ *
* @param method {@code non-null;} method in question
* @param list {@code non-null;} associated list of annotation sets to add
*/
/**
* Gets the method annotations for a given method, if any. This is
* meant for use by debugging / dumping code.
- *
+ *
* @param method {@code non-null;} the method
* @return {@code null-ok;} the method annotations, if any
*/
if (methodAnnotations == null) {
return null;
}
-
+
for (MethodAnnotationStruct item : methodAnnotations) {
if (item.getMethod().equals(method)) {
return item.getAnnotations();
/**
* Gets the parameter annotations for a given method, if any. This is
* meant for use by debugging / dumping code.
- *
+ *
* @param method {@code non-null;} the method
* @return {@code null-ok;} the parameter annotations, if any
*/
return null;
}
-
+
/** {@inheritDoc} */
public void addContents(DexFile file) {
MixedItemSection wordData = file.getWordData();
item.addContents(file);
}
}
-
+
if (parameterAnnotations != null) {
for (ParameterAnnotationStruct item : parameterAnnotations) {
item.addContents(file);
/**
* Gets the list size of the given list, or {@code 0} if given
* {@code null}.
- *
+ *
* @param list {@code null-ok;} the list in question
* @return {@code >= 0;} its size
*/
/**
* Prints out the contents of this instance, in a debugging-friendly
* way. This is meant to be called from {@link ClassDefItem#debugPrint}.
- *
+ *
* @param out {@code non-null;} where to output to
*/
/*package*/ void debugPrint(PrintWriter out) {
out.println(" " + item.toHuman());
}
}
-
+
if (parameterAnnotations != null) {
out.println(" parameter annotations:");
for (ParameterAnnotationStruct item : parameterAnnotations) {
out.println(" " + item.toHuman());
}
}
- }
+ }
}
public final class CatchStructs {
/**
* the size of a {@code try_item}: a {@code uint}
- * and two {@code ushort}s
+ * and two {@code ushort}s
*/
private static final int TRY_ITEM_WRITE_SIZE = 4 + (2 * 2);
/** {@code non-null;} code that contains the catches */
private final DalvCode code;
-
+
/**
* {@code null-ok;} the underlying table; set in
* {@link #finishProcessingIfNecessary}
/**
* Constructs an instance.
- *
+ *
* @param code {@code non-null;} code that contains the catches
*/
public CatchStructs(DalvCode code) {
/**
* Gets the size of the tries list, in entries.
- *
+ *
* @return {@code >= 0;} the tries list size
*/
public int triesSize() {
/**
* Does a human-friendly dump of this instance.
- *
+ *
* @param out {@code non-null;} where to dump
* @param prefix {@code non-null;} prefix to attach to each line of output
*/
/**
* Encodes the handler lists.
- *
+ *
* @param file {@code non-null;} file this instance is part of
*/
public void encode(DexFile file) {
throw new UnsupportedOperationException(
"too many catch handlers");
}
-
+
ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput();
// Write out the handlers "header" consisting of its size in entries.
encodedHandlerHeaderSize =
out.writeUnsignedLeb128(handlerOffsets.size());
-
+
// Now write the lists out in order, noting the offset of each.
for (Map.Entry<CatchHandlerList, Integer> mapping :
handlerOffsets.entrySet()) {
/**
* Gets the write size of this instance, in bytes.
- *
+ *
* @return {@code >= 0;} the write size
*/
public int writeSize() {
return (triesSize() * TRY_ITEM_WRITE_SIZE) +
+ encodedHandlers.length;
}
-
+
/**
* Writes this instance to the given stream.
- *
+ *
* @param file {@code non-null;} file this instance is part of
* @param out {@code non-null;} where to write to
*/
out.writeShort(insnCount);
out.writeShort(handlerOffsets.get(one.getHandlers()));
}
-
+
out.write(encodedHandlers);
}
* Helper method to annotate or simply print the exception handlers.
* Only one of {@code printTo} or {@code annotateTo} should
* be non-null.
- *
+ *
* @param prefix {@code non-null;} prefix for each line
* @param printTo {@code null-ok;} where to print to
* @param annotateTo {@code null-ok;} where to consume bytes and annotate to
int lastOffset = 0;
CatchHandlerList lastList = null;
-
+
for (Map.Entry<CatchHandlerList, Integer> mapping :
handlerOffsets.entrySet()) {
CatchHandlerList list = mapping.getKey();
/**
* Helper for {@link #annotateEntries} to annotate a catch handler list
* while consuming it.
- *
+ *
* @param handlers {@code non-null;} handlers to annotate
* @param offset {@code >= 0;} the offset of this handler
* @param size {@code >= 1;} the number of bytes the handlers consume
public final class ClassDataItem extends OffsettedItem {
/** {@code non-null;} what class this data is for, just for listing generation */
private final CstType thisClass;
-
+
/** {@code non-null;} list of static fields */
private final ArrayList<EncodedField> staticFields;
/**
* Constructs an instance. Its sets of members are initially
* empty.
- *
+ *
* @param thisClass {@code non-null;} what class this data is for, just
* for listing generation
*/
/**
* Returns whether this instance is empty.
- *
+ *
* @return {@code true} if this instance is empty or
* {@code false} if at least one element has been added to it
*/
/**
* Adds a static field.
- *
+ *
* @param field {@code non-null;} the field to add
* @param value {@code null-ok;} initial value for the field, if any
*/
/**
* Adds an instance field.
- *
+ *
* @param field {@code non-null;} the field to add
*/
public void addInstanceField(EncodedField field) {
/**
* Adds a direct ({@code static} and/or {@code private}) method.
- *
+ *
* @param method {@code non-null;} the method to add
*/
public void addDirectMethod(EncodedMethod method) {
/**
* Adds a virtual method.
- *
+ *
* @param method {@code non-null;} the method to add
*/
public void addVirtualMethod(EncodedMethod method) {
* Gets all the methods in this class. The returned list is not linked
* in any way to the underlying lists contained in this instance, but
* the objects contained in the list are shared.
- *
+ *
* @return {@code non-null;} list of all methods
*/
public ArrayList<EncodedMethod> getMethods() {
/**
* Prints out the contents of this instance, in a debugging-friendly
* way.
- *
+ *
* @param out {@code non-null;} where to output to
* @param verbose whether to be verbose with the output
*/
/**
* Gets a {@link CstArray} corresponding to {@link #staticValues} if
* it contains any non-zero non-{@code null} values.
- *
+ *
* @return {@code null-ok;} the corresponding constant or {@code null} if
* there are no values to encode
*/
/**
* Gets a {@link CstArray} corresponding to {@link #staticValues} if
* it contains any non-zero non-{@code null} values.
- *
+ *
* @return {@code null-ok;} the corresponding constant or {@code null} if
* there are no values to encode
*/
private CstArray makeStaticValuesConstant() {
// First sort the statics into their final order.
Collections.sort(staticFields);
-
+
/*
* Get the size of staticValues minus any trailing zeros/nulls (both
* nulls per se as well as instances of CstKnownNull).
if (size == 0) {
return null;
}
-
+
// There is something worth encoding, so build up a result.
-
+
CstArray.List list = new CstArray.List(size);
for (int i = 0; i < size; i++) {
EncodedField field = staticFields.get(i);
/**
* Writes out the encoded form of this instance.
- *
+ *
* @param file {@code non-null;} file this instance is part of
* @param out {@code non-null;} where to write to
*/
out.endAnnotation();
}
}
-
+
/**
* Helper for {@link #encodeOutput}, which writes out the given
* size value, annotating it as well (if annotations are enabled).
- *
+ *
* @param file {@code non-null;} file this instance is part of
* @param out {@code non-null;} where to write to
* @param label {@code non-null;} the label for the purposes of annotation
* Helper for {@link #encodeOutput}, which writes out the given
* list. It also annotates the items (if any and if annotations
* are enabled).
- *
+ *
* @param file {@code non-null;} file this instance is part of
* @param out {@code non-null;} where to write to
* @param label {@code non-null;} the label for the purposes of annotation
if (size == 0) {
return;
}
-
+
if (out.annotates()) {
out.annotate(0, " " + label + ":");
}
/**
* {@code null-ok;} superclass or {@code null} if this class is a/the
- * root class
+ * root class
*/
private final CstType superclass;
/**
* Constructs an instance. Its sets of members and annotations are
* initially empty.
- *
+ *
* @param thisClass {@code non-null;} type constant for this class
* @param accessFlags access flags
* @param superclass {@code null-ok;} superclass or {@code null} if
this.thisClass = thisClass;
this.accessFlags = accessFlags;
this.superclass = superclass;
- this.interfaces =
+ this.interfaces =
(interfaces.size() == 0) ? null : new TypeListItem(interfaces);
this.sourceFile = sourceFile;
this.classData = new ClassDataItem(thisClass);
if (annotates) {
out.annotate(0, indexString() + ' ' + thisClass.toHuman());
out.annotate(4, " class_idx: " + Hex.u4(classIdx));
- out.annotate(4, " access_flags: " +
+ out.annotate(4, " access_flags: " +
AccessFlags.classString(accessFlags));
out.annotate(4, " superclass_idx: " + Hex.u4(superIdx) +
" // " + ((superclass == null) ? "<none>" :
/**
* Gets the constant corresponding to this class.
- *
+ *
* @return {@code non-null;} the constant
*/
public CstType getThisClass() {
/**
* Gets the access flags.
- *
+ *
* @return the access flags
*/
public int getAccessFlags() {
/**
* Gets the superclass.
- *
+ *
* @return {@code null-ok;} the superclass or {@code null} if
* this class is a/the root class
*/
/**
* Gets the list of interfaces implemented.
- *
+ *
* @return {@code non-null;} the interfaces list
*/
public TypeList getInterfaces() {
/**
* Gets the source file name.
- *
+ *
* @return {@code null-ok;} the source file name or {@code null} if unknown
*/
public CstUtf8 getSourceFile() {
/**
* Adds a static field.
- *
+ *
* @param field {@code non-null;} the field to add
* @param value {@code null-ok;} initial value for the field, if any
*/
/**
* Adds an instance field.
- *
+ *
* @param field {@code non-null;} the field to add
*/
public void addInstanceField(EncodedField field) {
/**
* Adds a direct ({@code static} and/or {@code private}) method.
- *
+ *
* @param method {@code non-null;} the method to add
*/
public void addDirectMethod(EncodedMethod method) {
/**
* Adds a virtual method.
- *
+ *
* @param method {@code non-null;} the method to add
*/
public void addVirtualMethod(EncodedMethod method) {
* Gets all the methods in this class. The returned list is not linked
* in any way to the underlying lists contained in this instance, but
* the objects contained in the list are shared.
- *
+ *
* @return {@code non-null;} list of all methods
*/
public ArrayList<EncodedMethod> getMethods() {
* Sets the direct annotations on this class. These are annotations
* made on the class, per se, as opposed to on one of its members.
* It is only valid to call this method at most once per instance.
- *
+ *
* @param annotations {@code non-null;} annotations to set for this class
*/
public void setClassAnnotations(Annotations annotations) {
/**
* Adds a field annotations item to this class.
- *
+ *
* @param field {@code non-null;} field in question
* @param annotations {@code non-null;} associated annotations to add
*/
/**
* Adds a method annotations item to this class.
- *
+ *
* @param method {@code non-null;} method in question
* @param annotations {@code non-null;} associated annotations to add
*/
/**
* Adds a parameter annotations item to this class.
- *
+ *
* @param method {@code non-null;} method in question
* @param list {@code non-null;} associated list of annotation sets to add
*/
/**
* Gets the method annotations for a given method, if any. This is
* meant for use by debugging / dumping code.
- *
+ *
* @param method {@code non-null;} the method
* @return {@code null-ok;} the method annotations, if any
*/
/**
* Gets the parameter annotations for a given method, if any. This is
* meant for use by debugging / dumping code.
- *
+ *
* @param method {@code non-null;} the method
* @return {@code null-ok;} the parameter annotations, if any
*/
public AnnotationsList getParameterAnnotations(CstMethodRef method) {
return annotationsDirectory.getParameterAnnotations(method);
}
-
+
/**
* Prints out the contents of this instance, in a debugging-friendly
* way.
- *
+ *
* @param out {@code non-null;} where to output to
* @param verbose whether to be verbose with the output
*/
classData.debugPrint(out, verbose);
annotationsDirectory.debugPrint(pw);
-
+
pw.println("}");
}
}
/**
* Constructs an instance. The file offset is initially unknown.
- *
+ *
* @param file {@code non-null;} file that this instance is part of
*/
public ClassDefsSection(DexFile file) {
if (orderedDefs != null) {
return orderedDefs;
}
-
+
return classDefs.values();
}
/**
* Writes the portion of the file header that refers to this instance.
- *
+ *
* @param out {@code non-null;} where to write
*/
public void writeHeaderPart(AnnotatedOutput out) {
/**
* Adds an element to this instance. It is illegal to attempt to add more
* than one class with the same name.
- *
+ *
* @param clazz {@code non-null;} the class def to add
*/
public void add(ClassDefItem clazz) {
/**
* Helper for {@link #orderItems}, which recursively assigns indices
* to classes.
- *
+ *
* @param type {@code null-ok;} type ref to assign, if any
* @param idx {@code >= 0;} the next index to assign
* @param maxDepth maximum recursion depth; if negative, this will
/**
* {@code non-null;} list of possibly-thrown exceptions; just used in
- * generating debugging output (listings)
+ * generating debugging output (listings)
*/
private final TypeList throwsList;
/**
* Constructs an instance.
- *
+ *
* @param ref {@code non-null;} method that this code implements
* @param code {@code non-null;} the underlying code
* @param isStatic whether this instance is for a {@code static}
/**
* Gets the reference to the method this instance implements.
- *
+ *
* @return {@code non-null;} the method reference
*/
public CstMethodRef getRef() {
/**
* Does a human-friendly dump of this instance.
- *
+ *
* @param out {@code non-null;} where to dump
* @param prefix {@code non-null;} per-line prefix to use
* @param verbose whether to be verbose with the output
protected void place0(Section addedTo, int offset) {
final DexFile file = addedTo.getFile();
int catchesSize;
-
+
/*
* In order to get the catches and insns, all the code's
* constants need to be assigned indices.
/**
* Get the in registers count.
- *
+ *
* @return the count
*/
private int getInsSize() {
/**
* Get the out registers count.
- *
+ *
* @return the count
*/
private int getOutsSize() {
/**
* Get the total registers count.
- *
+ *
* @return the count
*/
private int getRegistersSize() {
/** current decoding state: line number */
private int line = 1;
-
+
/** current decoding state: bytecode address */
private int address = 0;
this.desc = ref.getPrototype();
this.file = file;
this.regSize = regSize;
-
+
positions = new ArrayList<PositionEntry>();
locals = new ArrayList<LocalEntry>();
this.codesize = codesize;
throw new RuntimeException(
"Mismatch between parameters_size and prototype");
}
-
+
if (!isStatic) {
// Start off with implicit 'this' entry
LocalEntry thisEntry =
throw new RuntimeException("nonsensical "
+ "END_LOCAL on dead register v" + reg);
}
-
+
le = new LocalEntry(address, false, reg,
prevle.nameIndex, prevle.typeIndex,
prevle.signatureIndex);
DalvInsnList insns = code.getInsns();
int codeSize = insns.codeSize();
int countRegisters = insns.getRegistersSize();
-
+
try {
validateEncode0(info, codeSize, countRegisters,
isStatic, ref, file, pl, ll);
"while processing " + ref.toHuman());
}
}
-
+
private static void validateEncode0(byte[] info, int codeSize,
int countRegisters, boolean isStatic, CstMethodRef ref,
DexFile file, PositionList pl, LocalList ll) {
}
}
}
-
+
int origSz = ll.size();
int decodeAt = 0;
boolean problem = false;
problem = true;
break;
}
-
+
if (decodedEntry.isStart != origEntry.isStart()) {
System.err.println("local start/end mismatch at orig " + i +
" / decoded " + decodeAt);
* parameter might not be marked as starting at 0 in the
* original list.
*/
- if ((decodedAddress != origEntry.getAddress())
+ if ((decodedAddress != origEntry.getAddress())
&& !((decodedAddress == 0)
&& (decodedEntry.reg >= paramBase))) {
System.err.println("local address mismatch at orig " + i +
/** {@code non-null;} the code this item represents */
private final DalvCode code;
-
+
private byte[] encoded;
private final boolean isStatic;
"...while placing debug info for " + ref.toHuman());
}
}
-
+
/** {@inheritDoc} */
@Override
public String toHuman() {
*/
public void annotateTo(DexFile file, AnnotatedOutput out, String prefix) {
encode(file, prefix, null, out, false);
- }
+ }
/**
* Does a human-friendly dump of this instance.
/** {@code non-null;} word data section */
private final MixedItemSection wordData;
- /**
+ /**
* {@code non-null;} type lists section. This is word data, but separating
* it from {@link #wordData} helps break what would otherwise be a
* circular dependency between the that and {@link #protoIds}.
classDefs = new ClassDefsSection(this);
map = new MixedItemSection("map", this, 4, SortType.NONE);
- /*
+ /*
* This is the list of sections in the order they appear in
* the final output.
*/
sections = new Section[] {
header, stringIds, typeIds, protoIds, fieldIds, methodIds,
- classDefs, wordData, typeLists, stringData, byteData,
+ classDefs, wordData, typeLists, stringData, byteData,
classData, map };
-
+
fileSize = -1;
dumpWidth = 79;
}
/**
* Adds a class to this instance. It is illegal to attempt to add more
* than one class with the same name.
- *
+ *
* @param clazz {@code non-null;} the class to add
*/
public void add(ClassDefItem clazz) {
/**
* Gets the class definition with the given name, if any.
- *
+ *
* @param name {@code non-null;} the class name to look for
* @return {@code null-ok;} the class with the given name, or {@code null}
* if there is no such class
/**
* Writes the contents of this instance as either a binary or a
* human-readable form, or both.
- *
+ *
* @param out {@code null-ok;} where to write to
* @param humanOut {@code null-ok;} where to write human-oriented output to
* @param verbose whether to be verbose when writing human-oriented output
/**
* Returns the contents of this instance as a {@code .dex} file,
* in {@code byte[]} form.
- *
+ *
* @param humanOut {@code null-ok;} where to write human-oriented output to
* @param verbose whether to be verbose when writing human-oriented output
* @return {@code non-null;} a {@code .dex} file for this instance
*/
- public byte[] toDex(Writer humanOut, boolean verbose)
+ public byte[] toDex(Writer humanOut, boolean verbose)
throws IOException {
boolean annotate = (humanOut != null);
ByteArrayAnnotatedOutput result = toDex0(annotate, verbose);
/**
* Sets the maximum width of the human-oriented dump of the instance.
- *
+ *
* @param dumpWidth {@code >= 40;} the width
*/
public void setDumpWidth(int dumpWidth) {
/**
* Gets the total file size, if known.
- *
+ *
* <p>This is package-scope in order to allow
* the {@link HeaderSection} to set itself up properly.</p>
- *
+ *
* @return {@code >= 0;} the total file size
* @throws RuntimeException thrown if the file size is not yet known
*/
/**
* Gets the string data section.
- *
+ *
* <p>This is package-scope in order to allow
* the various {@link Item} instances to add items to the
* instance.</p>
- *
+ *
* @return {@code non-null;} the string data section
*/
/*package*/ MixedItemSection getStringData() {
/**
* Gets the word data section.
- *
+ *
* <p>This is package-scope in order to allow
* the various {@link Item} instances to add items to the
* instance.</p>
- *
+ *
* @return {@code non-null;} the word data section
*/
/*package*/ MixedItemSection getWordData() {
/**
* Gets the type lists section.
- *
+ *
* <p>This is package-scope in order to allow
* the various {@link Item} instances to add items to the
* instance.</p>
- *
+ *
* @return {@code non-null;} the word data section
*/
/*package*/ MixedItemSection getTypeLists() {
/**
* Gets the map section.
- *
+ *
* <p>This is package-scope in order to allow the header section
* to query it.</p>
- *
+ *
* @return {@code non-null;} the map section
*/
/*package*/ MixedItemSection getMap() {
/**
* Gets the string identifiers section.
- *
+ *
* <p>This is package-scope in order to allow
* the various {@link Item} instances to add items to the
* instance.</p>
- *
+ *
* @return {@code non-null;} the string identifiers section
*/
/*package*/ StringIdsSection getStringIds() {
/**
* Gets the class definitions section.
- *
+ *
* <p>This is package-scope in order to allow
* the various {@link Item} instances to add items to the
* instance.</p>
- *
+ *
* @return {@code non-null;} the class definitions section
*/
/*package*/ ClassDefsSection getClassDefs() {
/**
* Gets the class data section.
- *
+ *
* <p>This is package-scope in order to allow
* the various {@link Item} instances to add items to the
* instance.</p>
- *
+ *
* @return {@code non-null;} the class data section
*/
/*package*/ MixedItemSection getClassData() {
/**
* Gets the type identifiers section.
- *
+ *
* <p>This is package-scope in order to allow
* the various {@link Item} instances to add items to the
* instance.</p>
- *
+ *
* @return {@code non-null;} the class identifiers section
*/
/*package*/ TypeIdsSection getTypeIds() {
/**
* Gets the prototype identifiers section.
- *
+ *
* <p>This is package-scope in order to allow
* the various {@link Item} instances to add items to the
* instance.</p>
- *
+ *
* @return {@code non-null;} the prototype identifiers section
*/
/*package*/ ProtoIdsSection getProtoIds() {
/**
* Gets the field identifiers section.
- *
+ *
* <p>This is package-scope in order to allow
* the various {@link Item} instances to add items to the
* instance.</p>
- *
+ *
* @return {@code non-null;} the field identifiers section
*/
/*package*/ FieldIdsSection getFieldIds() {
/**
* Gets the method identifiers section.
- *
+ *
* <p>This is package-scope in order to allow
* the various {@link Item} instances to add items to the
* instance.</p>
- *
+ *
* @return {@code non-null;} the method identifiers section
*/
/*package*/ MethodIdsSection getMethodIds() {
/**
* Gets the first section of the file that is to be considered
* part of the data section.
- *
+ *
* <p>This is package-scope in order to allow the header section
* to query it.</p>
- *
+ *
* @return {@code non-null;} the section
*/
/*package*/ Section getFirstDataSection() {
/**
* Gets the last section of the file that is to be considered
* part of the data section.
- *
+ *
* <p>This is package-scope in order to allow the header section
* to query it.</p>
- *
+ *
* @return {@code non-null;} the section
*/
/*package*/ Section getLastDataSection() {
return map;
}
-
+
/**
* Interns the given constant in the appropriate section of this
* instance, or do nothing if the given constant isn't the sort
* that should be interned.
- *
+ *
* @param cst {@code non-null;} constant to possibly intern
*/
/*package*/ void internIfAppropriate(Constant cst) {
* {@code null} if it isn't such a constant. This will throw
* an exception if the given constant <i>should</i> have been found
* but wasn't.
- *
+ *
* @param cst {@code non-null;} the constant to look up
* @return {@code null-ok;} its corresponding item, if it has a corresponding
* item, or {@code null} if it's not that sort of constant
/**
* Returns the contents of this instance as a {@code .dex} file,
* in a {@link ByteArrayAnnotatedOutput} instance.
- *
+ *
* @param annotate whether or not to keep annotations
* @param verbose if annotating, whether to be verbose
* @return {@code non-null;} a {@code .dex} file for this instance
*/
((MixedItemSection) one).placeItems();
}
-
+
offset = placedAt + one.writeSize();
} catch (RuntimeException ex) {
throw ExceptionWithContext.withContext(ex,
}
// Perform final bookkeeping.
-
+
calcSignature(barr);
calcChecksum(barr);
/**
* Generates and returns statistics for all the items in the file.
- *
+ *
* @return {@code non-null;} the statistics
*/
public Statistics getStatistics() {
/**
* Calculates the signature for the {@code .dex} file in the
* given array, and modify the array to contain it.
- *
+ *
* @param bytes {@code non-null;} the bytes of the file
*/
private static void calcSignature(byte[] bytes) {
/**
* Calculates the checksum for the {@code .dex} file in the
* given array, and modify the array to contain it.
- *
+ *
* @param bytes {@code non-null;} the bytes of the file
*/
private static void calcChecksum(byte[] bytes) {
/**
* Constructs an instance.
- *
+ *
* @param array {@code non-null;} array to represent
*/
public EncodedArrayItem(CstArray array) {
/**
* Constructs an instance.
- *
+ *
* @param field {@code non-null;} constant for the field
* @param accessFlags access flags
*/
/**
* {@inheritDoc}
- *
+ *
* <p><b>Note:</b> This compares the method constants only,
* ignoring any associated code, because it should never be the
* case that two different items with the same method constant
/**
* Gets the constant for the field.
- *
+ *
* @return {@code non-null;} the constant
*/
public CstFieldRef getRef() {
/** {@inheritDoc} */
@Override
- public int encode(DexFile file, AnnotatedOutput out,
+ public int encode(DexFile file, AnnotatedOutput out,
int lastIndex, int dumpSeq) {
int fieldIdx = file.getFieldIds().indexOf(field);
int diff = fieldIdx - lastIndex;
/**
* Populates a {@link DexFile} with items from within this instance.
- *
+ *
* @param file {@code non-null;} the file to populate
*/
public abstract void addContents(DexFile file);
/**
* Encodes this instance to the given output.
- *
+ *
* @param file {@code non-null;} file this instance is part of
* @param out {@code non-null;} where to write to
* @param lastIndex {@code >= 0;} the previous member index value encoded, or
* annotation purposes
* @return {@code >= 0;} the member index value that was encoded
*/
- public abstract int encode(DexFile file, AnnotatedOutput out,
+ public abstract int encode(DexFile file, AnnotatedOutput out,
int lastIndex, int dumpSeq);
}
/**
* Class that representats a method of a class.
*/
-public final class EncodedMethod extends EncodedMember
+public final class EncodedMethod extends EncodedMember
implements Comparable<EncodedMethod> {
/** {@code non-null;} constant for the method */
private final CstMethodRef method;
/**
* {@code null-ok;} code for the method, if the method is neither
- * {@code abstract} nor {@code native}
+ * {@code abstract} nor {@code native}
*/
private final CodeItem code;
/**
* Constructs an instance.
- *
+ *
* @param method {@code non-null;} constant for the method
* @param accessFlags access flags
* @param code {@code null-ok;} code for the method, if it is neither
/**
* {@inheritDoc}
- *
+ *
* <p><b>Note:</b> This compares the method constants only,
* ignoring any associated code, because it should never be the
* case that two different items with the same method constant
/**
* Gets the constant for the method.
- *
+ *
* @return {@code non-null;} the constant
*/
public final CstMethodRef getRef() {
/** {@inheritDoc} */
@Override
- public int encode(DexFile file, AnnotatedOutput out,
+ public int encode(DexFile file, AnnotatedOutput out,
int lastIndex, int dumpSeq) {
int methodIdx = file.getMethodIds().indexOf(method);
int diff = methodIdx - lastIndex;
int accessFlags = getAccessFlags();
int codeOff = OffsettedItem.getAbsoluteOffsetOr0(code);
boolean hasCode = (codeOff != 0);
- boolean shouldHaveCode = (accessFlags &
+ boolean shouldHaveCode = (accessFlags &
(AccessFlags.ACC_ABSTRACT | AccessFlags.ACC_NATIVE)) == 0;
/*
/**
* Constructs an instance.
- *
+ *
* @param field {@code non-null;} the field in question
* @param annotations {@code non-null;} the associated annotations
*/
public int hashCode() {
return field.hashCode();
}
-
+
/** {@inheritDoc} */
public boolean equals(Object other) {
if (! (other instanceof FieldAnnotationStruct)) {
return false;
}
-
+
return field.equals(((FieldAnnotationStruct) other).field);
}
/**
* Gets the field this item is for.
- *
+ *
* @return {@code non-null;} the field
*/
public CstFieldRef getField() {
/**
* Gets the associated annotations.
- *
+ *
* @return {@code non-null;} the annotations
*/
public Annotations getAnnotations() {
public final class FieldIdItem extends MemberIdItem {
/**
* Constructs an instance.
- *
+ *
* @param field {@code non-null;} the constant for the field
*/
public FieldIdItem(CstFieldRef field) {
/**
* Gets the field constant.
- *
+ *
* @return {@code non-null;} the constant
*/
public CstFieldRef getFieldRef() {
TypeIdsSection typeIds = file.getTypeIds();
return typeIds.indexOf(getFieldRef().getType());
}
-
+
/** {@inheritDoc} */
@Override
protected String getTypoidName() {
return "type_idx";
- }
+ }
}
public final class FieldIdsSection extends MemberIdsSection {
/**
* {@code non-null;} map from field constants to {@link
- * FieldIdItem} instances
+ * FieldIdItem} instances
*/
private final TreeMap<CstFieldRef, FieldIdItem> fieldIds;
/**
* Constructs an instance. The file offset is initially unknown.
- *
+ *
* @param file {@code non-null;} file that this instance is part of
*/
public FieldIdsSection(DexFile file) {
/**
* Writes the portion of the file header that refers to this instance.
- *
+ *
* @param out {@code non-null;} where to write
*/
public void writeHeaderPart(AnnotatedOutput out) {
/**
* Interns an element into this instance.
- *
+ *
* @param field {@code non-null;} the reference to intern
* @return {@code non-null;} the interned reference
*/
/**
* Gets the index of the given reference, which must have been added
* to this instance.
- *
+ *
* @param ref {@code non-null;} the reference to look up
* @return {@code >= 0;} the reference's index
*/
public ItemType itemType() {
return ItemType.TYPE_HEADER_ITEM;
}
-
+
/** {@inheritDoc} */
@Override
public int writeSize() {
int dataOff = firstDataSection.getFileOffset();
int dataSize = lastDataSection.getFileOffset() +
lastDataSection.writeSize() - dataOff;
-
+
if (out.annotates()) {
out.annotate(8, "magic: " + new CstUtf8(MAGIC).toQuoted());
out.annotate(4, "checksum");
out.writeZeroes(8);
out.writeInt(mapOff);
-
+
// Write out each section's respective header part.
file.getStringIds().writeHeaderPart(out);
file.getTypeIds().writeHeaderPart(out);
public final class HeaderSection extends UniformItemSection {
/** {@code non-null;} the list of the one item in the section */
private final List<HeaderItem> list;
-
+
/**
* Constructs an instance. The file offset is initially unknown.
- *
+ *
* @param file {@code non-null;} file that this instance is part of
*/
public HeaderSection(DexFile file) {
public abstract class IdItem extends IndexedItem {
/**
* {@code non-null;} the type constant for the defining class of
- * the reference
+ * the reference
*/
private final CstType type;
/**
* Constructs an instance.
- *
+ *
* @param type {@code non-null;} the type constant for the defining
* class of the reference
*/
/**
* Gets the type constant for the defining class of the
* reference.
- *
+ *
* @return {@code non-null;} the type constant
*/
public final CstType getDefiningClass() {
/**
* Gets whether or not this instance has been assigned an index.
- *
+ *
* @return {@code true} iff this instance has been assigned an index
*/
public final boolean hasIndex() {
/**
* Gets the index of this item as a string, suitable for including in
* annotations.
- *
+ *
* @return {@code non-null;} the index string
*/
public final String indexString() {
/**
* Returns the item type for this instance.
- *
+ *
* @return {@code non-null;} the item type
*/
public abstract ItemType itemType();
-
+
/**
* Returns the human name for the particular type of item this
* instance is.
- *
+ *
* @return {@code non-null;} the name
*/
public final String typeName() {
/**
* Gets the size of this instance when written, in bytes.
- *
+ *
* @return {@code >= 0;} the write size
*/
public abstract int writeSize();
* Populates a {@link DexFile} with items from within this instance.
* This will <i>not</i> add an item to the file for this instance itself
* (which should have been done by whatever refers to this instance).
- *
+ *
* <p><b>Note:</b> Subclasses must override this to do something
* appropriate.</p>
- *
+ *
* @param file {@code non-null;} the file to populate
*/
public abstract void addContents(DexFile file);
* If this instance keeps track of its offset, then this method will
* note the written offset and will also throw an exception if this
* instance has already been written.
- *
+ *
* @param file {@code non-null;} the file to use for reference
* @param out {@code non-null;} where to write to
*/
TYPE_TYPE_ITEM( -1, "type_item"),
TYPE_EXCEPTION_HANDLER_ITEM( -1, "exception_handler_item"),
TYPE_ANNOTATION_SET_REF_ITEM( -1, "annotation_set_ref_item");
-
+
/** value when represented in a {@link MapItem} */
private final int mapValue;
/** {@code non-null;} the short human name */
private final String humanName;
-
+
/**
* Constructs an instance.
- *
+ *
* @param mapValue value when represented in a {@link MapItem}
* @param typeName {@code non-null;} name of the type
*/
/**
* Gets the map value.
- *
+ *
* @return the map value
*/
public int getMapValue() {
return mapValue;
}
-
+
/**
* Gets the type name.
- *
+ *
* @return {@code non-null;} the type name
*/
public String getTypeName() {
throw new IllegalArgumentException(
"mapSection.items().size() != 0");
}
-
+
ArrayList<MapItem> items = new ArrayList<MapItem>(50);
for (Section section : sections) {
mapSection.add(
new UniformListItem<MapItem>(ItemType.TYPE_MAP_LIST, items));
}
-
+
/**
* Constructs an instance.
- *
+ *
* @param type {@code non-null;} item type this instance covers
* @param section {@code non-null;} section this instance covers
* @param firstItem {@code non-null;} first item covered
/**
* Constructs a self-referential instance. This instance is meant to
* represent the section containing the {@code map_list}.
- *
+ *
* @param section {@code non-null;} section this instance covers
*/
private MapItem(Section section) {
out.writeShort(0); // unused
out.writeInt(itemCount);
out.writeInt(offset);
- }
+ }
}
/**
* Constructs an instance.
- *
+ *
* @param cst {@code non-null;} the constant for the member
*/
public MemberIdItem(CstMemberRef cst) {
out.annotate(2, String.format(" %-10s %s", getTypoidName() + ':',
Hex.u2(typoidIdx)));
out.annotate(4, " name_idx: " + Hex.u4(nameIdx));
- }
+ }
out.writeShort(classIdx);
out.writeShort(typoidIdx);
* Returns the index of the type-like thing associated with
* this item, in order that it may be written out. Subclasses must
* override this to get whatever it is they need to store.
- *
+ *
* @param file {@code non-null;} the file being written
* @return the index in question
*/
protected abstract int getTypoidIdx(DexFile file);
-
+
/**
* Returns the field name of the type-like thing associated with
* this item, for listing-generating purposes. Subclasses must override
* this.
- *
+ *
* @return {@code non-null;} the name in question
*/
protected abstract String getTypoidName();
/**
* Gets the member constant.
- *
+ *
* @return {@code non-null;} the constant
*/
public final CstMemberRef getRef() {
public abstract class MemberIdsSection extends UniformItemSection {
/**
* Constructs an instance. The file offset is initially unknown.
- *
+ *
* @param name {@code null-ok;} the name of this instance, for annotation
* purposes
* @param file {@code non-null;} file that this instance is part of
/**
* Constructs an instance.
- *
+ *
* @param method {@code non-null;} the method in question
* @param annotations {@code non-null;} the associated annotations
*/
public int hashCode() {
return method.hashCode();
}
-
+
/** {@inheritDoc} */
public boolean equals(Object other) {
if (! (other instanceof MethodAnnotationStruct)) {
return false;
}
-
+
return method.equals(((MethodAnnotationStruct) other).method);
}
/**
* Gets the method this item is for.
- *
+ *
* @return {@code non-null;} the method
*/
public CstMethodRef getMethod() {
/**
* Gets the associated annotations.
- *
+ *
* @return {@code non-null;} the annotations
*/
public Annotations getAnnotations() {
public final class MethodIdItem extends MemberIdItem {
/**
* Constructs an instance.
- *
+ *
* @param method {@code non-null;} the constant for the method
*/
public MethodIdItem(CstBaseMethodRef method) {
/**
* Gets the method constant.
- *
+ *
* @return {@code non-null;} the constant
*/
public CstBaseMethodRef getMethodRef() {
ProtoIdsSection protoIds = file.getProtoIds();
return protoIds.indexOf(getMethodRef().getPrototype());
}
-
+
/** {@inheritDoc} */
@Override
protected String getTypoidName() {
return "proto_idx";
- }
+ }
}
public final class MethodIdsSection extends MemberIdsSection {
/**
* {@code non-null;} map from method constants to {@link
- * MethodIdItem} instances
+ * MethodIdItem} instances
*/
private final TreeMap<CstBaseMethodRef, MethodIdItem> methodIds;
/**
* Constructs an instance. The file offset is initially unknown.
- *
+ *
* @param file {@code non-null;} file that this instance is part of
*/
public MethodIdsSection(DexFile file) {
/**
* Writes the portion of the file header that refers to this instance.
- *
+ *
* @param out {@code non-null;} where to write
*/
public void writeHeaderPart(AnnotatedOutput out) {
/**
* Interns an element into this instance.
- *
+ *
* @param method {@code non-null;} the reference to intern
* @return {@code non-null;} the interned reference
*/
/**
* Gets the index of the given reference, which must have been added
* to this instance.
- *
+ *
* @param ref {@code non-null;} the reference to look up
* @return {@code >= 0;} the reference's index
*/
* A section of a {@code .dex} file which consists of a sequence of
* {@link OffsettedItem} objects, which may each be of a different concrete
* class and/or size.
- *
+ *
* <b>Note:</b> It is invalid for an item in an instance of this class to
* have a larger alignment requirement than the alignment of this instance.
*/
return type1.compareTo(type2);
}
};
-
+
/** {@code non-null;} the items in this part */
private final ArrayList<OffsettedItem> items;
/**
* Constructs an instance. The file offset is initially unknown.
- *
+ *
* @param name {@code null-ok;} the name of this instance, for annotation
* purposes
* @param file {@code non-null;} file that this instance is part of
/**
* Gets the size of this instance, in items.
- *
+ *
* @return {@code >= 0;} the size
*/
public int size() {
throwIfNotPrepared();
if (writeSize == -1) {
- throw new RuntimeException("write size not yet set");
+ throw new RuntimeException("write size not yet set");
}
int sz = writeSize;
* that it has been added to this instance. It is invalid to add the
* same item to more than one instance, nor to add the same items
* multiple times to a single instance.
- *
+ *
* @param item {@code non-null;} the item to add
*/
public void add(OffsettedItem item) {
* Interns an item in this instance, returning the interned instance
* (which may not be the one passed in). This will add the item if no
* equal item has been added.
- *
+ *
* @param item {@code non-null;} the item to intern
* @return {@code non-null;} the equivalent interned instance
*/
throwIfPrepared();
OffsettedItem result = interns.get(item);
-
+
if (result != null) {
return (T) result;
}
/**
* Gets an item which was previously interned.
- *
+ *
* @param item {@code non-null;} the item to look for
* @return {@code non-null;} the equivalent already-interned instance
*/
throwIfNotPrepared();
OffsettedItem result = interns.get(item);
-
+
if (result != null) {
return (T) result;
}
* Writes an index of contents of the items in this instance of the
* given type. If there are none, this writes nothing. If there are any,
* then the index is preceded by the given intro string.
- *
+ *
* @param out {@code non-null;} where to write to
* @param itemType {@code non-null;} the item type of interest
* @param intro {@code non-null;} the introductory string for non-empty indices
}
out.annotate(0, intro);
-
+
for (Map.Entry<String, OffsettedItem> entry : index.entrySet()) {
String label = entry.getKey();
OffsettedItem item = entry.getValue();
/**
* {@code null-ok;} section the item was added to, or {@code null} if
- * not yet added
+ * not yet added
*/
private Section addedTo;
/**
* {@code >= -1;} assigned offset of the item from the start of its section,
- * or {@code -1} if not yet assigned
+ * or {@code -1} if not yet assigned
*/
private int offset;
/**
* Gets the absolute offset of the given item, returning {@code 0}
* if handed {@code null}.
- *
+ *
* @param item {@code null-ok;} the item in question
* @return {@code >= 0;} the item's absolute offset, or {@code 0}
* if {@code item == null}
/**
* Constructs an instance. The offset is initially unassigned.
- *
+ *
* @param alignment {@code > 0;} output alignment requirement; must be a
* power of 2
* @param writeSize {@code >= -1;} the size of this instance when written,
/**
* {@inheritDoc}
- *
+ *
* Comparisons for this class are defined to be type-major (if the
* types don't match then the objects are not equal), with
* {@link #compareTo0} deciding same-type comparisons.
/**
* {@inheritDoc}
- *
+ *
* Comparisons for this class are defined to be class-major (if the
* classes don't match then the objects are not equal), with
* {@link #compareTo0} deciding same-class comparisons.
* Sets the write size of this item. This may only be called once
* per instance, and only if the size was unknown upon instance
* creation.
- *
+ *
* @param writeSize {@code > 0;} the write size, in bytes
*/
public final void setWriteSize(int writeSize) {
this.writeSize = writeSize;
}
-
- /** {@inheritDoc}
- *
+
+ /** {@inheritDoc}
+ *
* @throws UnsupportedOperationException thrown if the write size
* is not yet known
*/
if (writeSize < 0) {
throw new UnsupportedOperationException("writeSize is unknown");
}
-
+
return writeSize;
}
/**
* Gets the relative item offset. The offset is from the start of
* the section which the instance was written to.
- *
+ *
* @return {@code >= 0;} the offset
* @throws RuntimeException thrown if the offset is not yet known
*/
/**
* Gets the absolute item offset. The offset is from the start of
* the file which the instance was written to.
- *
+ *
* @return {@code >= 0;} the offset
* @throws RuntimeException thrown if the offset is not yet known
*/
* Indicates that this item has been added to the given section at
* the given offset. It is only valid to call this method once per
* instance.
- *
+ *
* @param addedTo {@code non-null;} the section this instance has
* been added to
* @param offset {@code >= 0;} the desired offset from the start of the
/**
* Gets the alignment requirement of this instance. An instance should
* only be written when so aligned.
- *
+ *
* @return {@code > 0;} the alignment requirement; must be a power of 2
*/
public final int getAlignment() {
/**
* Gets the absolute offset of this item as a string, suitable for
* including in annotations.
- *
+ *
* @return {@code non-null;} the offset string
*/
public final String offsetString() {
/**
* Gets a short human-readable string representing this instance.
- *
+ *
* @return {@code non-null;} the human form
*/
public abstract String toHuman();
* throw an exception (unsupported operation). If a particular
* class needs to actually sort, then it should override this
* method.
- *
+ *
* @param other {@code non-null;} instance to compare to
* @return {@code -1}, {@code 0}, or {@code 1}, depending
* on the sort order of this instance and the other
* override this method. In particular, if this instance did not
* know its write size up-front, then this method is responsible
* for setting it.
- *
+ *
* @param addedTo {@code non-null;} the section this instance has been added to
* @param offset {@code >= 0;} the offset from the start of the
* section where this instance was placed
* Performs the actual write of the contents of this instance to
* the given data section. This is called by {@link #writeTo},
* which will have taken care of ensuring alignment.
- *
+ *
* @param file {@code non-null;} the file to use for reference
* @param out {@code non-null;} where to write to
*/
/**
* Constructs an instance.
- *
+ *
* @param method {@code non-null;} the method in question
* @param annotationsList {@code non-null;} the associated annotations list
*/
AnnotationSetItem item = new AnnotationSetItem(annotations);
arrayList.add(new AnnotationSetRefItem(item));
}
-
+
this.annotationsItem = new UniformListItem<AnnotationSetRefItem>(
ItemType.TYPE_ANNOTATION_SET_REF_LIST, arrayList);
}
public int hashCode() {
return method.hashCode();
}
-
+
/** {@inheritDoc} */
public boolean equals(Object other) {
if (! (other instanceof ParameterAnnotationStruct)) {
return false;
}
-
+
return method.equals(((ParameterAnnotationStruct) other).method);
}
/**
* Gets the method this item is for.
- *
+ *
* @return {@code non-null;} the method
*/
public CstMethodRef getMethod() {
/**
* Gets the associated annotations list.
- *
+ *
* @return {@code non-null;} the annotations list
*/
public AnnotationsList getAnnotationsList() {
/**
* Constructs an instance.
- *
+ *
* @param prototype {@code non-null;} the constant for the prototype
*/
public ProtoIdItem(Prototype prototype) {
this.shortForm = makeShortForm(prototype);
StdTypeList parameters = prototype.getParameterTypes();
- this.parameterTypes = (parameters.size() == 0) ? null
+ this.parameterTypes = (parameters.size() == 0) ? null
: new TypeListItem(parameters);
}
/**
* Creates the short-form of the given prototype.
- *
+ *
* @param prototype {@code non-null;} the prototype
* @return {@code non-null;} the short form
*/
/**
* Gets the short-form character for the given type.
- *
+ *
* @param type {@code non-null;} the type
* @return the corresponding short-form character
*/
int shortyIdx = file.getStringIds().indexOf(shortForm);
int returnIdx = file.getTypeIds().indexOf(prototype.getReturnType());
int paramsOff = OffsettedItem.getAbsoluteOffsetOr0(parameterTypes);
-
+
if (out.annotates()) {
StringBuilder sb = new StringBuilder();
sb.append(prototype.getReturnType().toHuman());
}
sb.append(params.getType(i).toHuman());
}
-
+
sb.append(")");
out.annotate(0, indexString() + ' ' + sb.toString());
out.annotate(4, " shorty_idx: " + Hex.u4(shortyIdx) +
/**
* Constructs an instance. The file offset is initially unknown.
- *
+ *
* @param file {@code non-null;} file that this instance is part of
*/
public ProtoIdsSection(DexFile file) {
/**
* Writes the portion of the file header that refers to this instance.
- *
+ *
* @param out {@code non-null;} where to write
*/
public void writeHeaderPart(AnnotatedOutput out) {
/**
* Interns an element into this instance.
- *
+ *
* @param prototype {@code non-null;} the prototype to intern
* @return {@code non-null;} the interned reference
*/
/**
* Gets the index of the given prototype, which must have
* been added to this instance.
- *
+ *
* @param prototype {@code non-null;} the prototype to look up
* @return {@code >= 0;} the reference's index
*/
/**
* Validates an alignment.
- *
+ *
* @param alignment the alignment
* @throws IllegalArgumentException thrown if {@code alignment}
* isn't a positive power of 2
return file;
}
- /**
+ /**
* Gets the alignment for this instance's final output.
- *
+ *
* @return {@code > 0;} the alignment
*/
public final int getAlignment() {
* @param out {@code non-null;} where to write to
*/
public final void writeTo(AnnotatedOutput out) {
- throwIfNotPrepared();
+ throwIfNotPrepared();
align(out);
int cursor = out.getCursor();
* start of this instance's output. This is only valid to call
* once this instance has been assigned a file offset (via {@link
* #setFileOffset}).
- *
+ *
* @param relative {@code >= 0;} the relative offset
* @return {@code >= 0;} the corresponding absolute file offset
*/
* be contained in this section. This is only valid to call
* once this instance has been assigned a file offset (via {@link
* #setFileOffset}).
- *
+ *
* <p><b>Note:</b> Subclasses must implement this as appropriate for
* their contents.</p>
- *
+ *
* @param item {@code non-null;} the item in question
* @return {@code >= 0;} the item's absolute file offset
*/
/**
* Aligns the output of the given data to the alignment of this instance.
- *
+ *
* @param out {@code non-null;} the output to align
*/
protected final void align(AnnotatedOutput out) {
* offset matches the actual cursor {@code out} or that the
* file offset was not previously assigned, in which case it gets
* assigned to {@code out}'s cursor.
- *
+ *
* @param out {@code non-null;} where to write to
*/
protected abstract void writeTo0(AnnotatedOutput out);
/**
* Returns the name of this section, for annotation purposes.
- *
+ *
* @return {@code null-ok;} name of this part, for annotation purposes
*/
protected final String getName() {
/**
* Adds the given item to the statistics.
- *
+ *
* @param item {@code non-null;} the item to add
*/
public void add(Item item) {
/**
* Adds the given list of items to the statistics.
- *
+ *
* @param list {@code non-null;} the list of items to add
*/
public void addAll(Section list) {
/**
* Writes the statistics as an annotation.
- *
+ *
* @param out {@code non-null;} where to write to
*/
public final void writeAnnotation(AnnotatedOutput out) {
/**
* Constructs an instance for the given item.
- *
+ *
* @param item {@code non-null;} item in question
* @param name {@code non-null;} type name to use
*/
/**
* Incorporates a new item. This assumes the type name matches.
- *
+ *
* @param item {@code non-null;} item to incorporate
*/
public void add(Item item) {
/**
* Writes this instance as an annotation.
- *
+ *
* @param out {@code non-null;} where to write to
*/
public void writeAnnotation(AnnotatedOutput out) {
/**
* Constructs an instance.
- *
+ *
* @param value {@code non-null;} the string value
*/
public StringDataItem(CstUtf8 value) {
/**
* Gets the write size for a given value.
- *
+ *
* @param value {@code non-null;} the string value
* @return {@code >= 2}; the write size, in bytes
*/
private static int writeSize(CstUtf8 value) {
int utf16Size = value.getUtf16Size();
-
+
// The +1 is for the '\0' termination byte.
return Leb128Utils.unsignedLeb128Size(utf16Size)
+ value.getUtf8Size() + 1;
int utf16Size = value.getUtf16Size();
if (out.annotates()) {
- out.annotate(Leb128Utils.unsignedLeb128Size(utf16Size),
+ out.annotate(Leb128Utils.unsignedLeb128Size(utf16Size),
"utf16_size: " + Hex.u4(utf16Size));
out.annotate(bytes.size() + 1, value.toQuoted());
}
/**
* Constructs an instance.
- *
+ *
* @param value {@code non-null;} the string value
*/
public StringIdItem(CstUtf8 value) {
/**
* Gets the string value.
- *
+ *
* @return {@code non-null;} the value
*/
public CstUtf8 getValue() {
/**
* Gets the associated data object for this instance, if known.
- *
+ *
* @return {@code null-ok;} the associated data object or {@code null}
* if not yet known
*/
extends UniformItemSection {
/**
* {@code non-null;} map from string constants to {@link
- * StringIdItem} instances
+ * StringIdItem} instances
*/
private final TreeMap<CstUtf8, StringIdItem> strings;
/**
* Constructs an instance. The file offset is initially unknown.
- *
+ *
* @param file {@code non-null;} file that this instance is part of
*/
public StringIdsSection(DexFile file) {
/**
* Writes the portion of the file header that refers to this instance.
- *
+ *
* @param out {@code non-null;} where to write
*/
public void writeHeaderPart(AnnotatedOutput out) {
/**
* Interns an element into this instance.
- *
+ *
* @param string {@code non-null;} the string to intern, as a regular Java
* {@code String}
* @return {@code non-null;} the interned string
/**
* Interns an element into this instance.
- *
+ *
* @param string {@code non-null;} the string to intern, as a {@link CstString}
* @return {@code non-null;} the interned string
*/
/**
* Interns an element into this instance.
- *
+ *
* @param string {@code non-null;} the string to intern, as a constant
* @return {@code non-null;} the interned string
*/
/**
* Interns an element into this instance.
- *
+ *
* @param string {@code non-null;} the string to intern
* @return {@code non-null;} the interned string
*/
/**
* Interns the components of a name-and-type into this instance.
- *
+ *
* @param nat {@code non-null;} the name-and-type
*/
public void intern(CstNat nat) {
/**
* Gets the index of the given string, which must have been added
* to this instance.
- *
+ *
* @param string {@code non-null;} the string to look up
* @return {@code >= 0;} the string's index
*/
/**
* Gets the index of the given string, which must have been added
* to this instance.
- *
+ *
* @param string {@code non-null;} the string to look up
* @return {@code >= 0;} the string's index
*/
/**
* Constructs an instance.
- *
+ *
* @param type {@code non-null;} the constant for the type
*/
public TypeIdItem(CstType type) {
/**
* Constructs an instance. The file offset is initially unknown.
- *
+ *
* @param file {@code non-null;} file that this instance is part of
*/
public TypeIdsSection(DexFile file) {
/**
* Writes the portion of the file header that refers to this instance.
- *
+ *
* @param out {@code non-null;} where to write
*/
public void writeHeaderPart(AnnotatedOutput out) {
/**
* Interns an element into this instance.
- *
+ *
* @param type {@code non-null;} the type to intern
* @return {@code non-null;} the interned reference
*/
/**
* Interns an element into this instance.
- *
+ *
* @param type {@code non-null;} the type to intern
* @return {@code non-null;} the interned reference
*/
/**
* Gets the index of the given type, which must have
* been added to this instance.
- *
+ *
* @param type {@code non-null;} the type to look up
* @return {@code >= 0;} the reference's index
*/
/**
* Gets the index of the given type, which must have
* been added to this instance.
- *
+ *
* @param type {@code non-null;} the type to look up
* @return {@code >= 0;} the reference's index
*/
/**
* Constructs an instance.
- *
+ *
* @param list {@code non-null;} the actual list
*/
public TypeListItem(TypeList list) {
/**
* Gets the underlying list.
- *
+ *
* @return {@code non-null;} the list
*/
public TypeList getList() {
for (int i = 0; i < sz; i++) {
out.writeShort(typeIds.indexOf(list.getType(i)));
}
- }
+ }
/** {@inheritDoc} */
@Override
public abstract class UniformItemSection extends Section {
/**
* Constructs an instance. The file offset is initially unknown.
- *
+ *
* @param name {@code null-ok;} the name of this instance, for annotation
* purposes
* @param file {@code non-null;} file that this instance is part of
* will throw an exception if the constant is not found, including
* if this instance isn't the sort that maps constants to {@link
* IndexedItem} instances.
- *
+ *
* @param cst {@code non-null;} constant to look for
* @return {@code non-null;} the corresponding item found in this instance
*/
* Class that represents a contiguous list of uniform items. Each
* item in the list, in particular, must have the same write size and
* alignment.
- *
+ *
* <p>This class inherits its alignment from its items, bumped up to
* {@code 4} if the items have a looser alignment requirement. If
* it is more than {@code 4}, then there will be a gap after the
* output list size (which is four bytes) and before the first item.</p>
- *
+ *
* @param <T> type of element contained in an instance
*/
public final class UniformListItem<T extends OffsettedItem>
/** {@code non-null;} the item type */
private final ItemType itemType;
-
+
/** {@code non-null;} the contents */
private final List<T> items;
/**
* Constructs an instance. It is illegal to modify the given list once
* it is used to construct an instance of this class.
- *
+ *
* @param itemType {@code non-null;} the type of the item
* @param items {@code non-null and non-empty;} list of items to represent
*/
* Helper for {@link #UniformListItem}, which returns the alignment
* requirement implied by the given list. See the header comment for
* more details.
- *
+ *
* @param items {@code non-null;} list of items being represented
* @return {@code >= 4;} the alignment requirement
*/
} catch (NullPointerException ex) {
// Translate the exception.
throw new NullPointerException("items == null");
- }
+ }
}
/**
* Calculates the write size for the given list.
- *
+ *
* @param items {@code non-null;} the list in question
* @return {@code >= 0;} the write size
*/
/**
* Gets the underlying list of items.
- *
+ *
* @return {@code non-null;} the list
*/
public final List<T> getItems() {
"item alignment mismatch");
}
}
-
+
offset = i.place(addedTo, offset) + size;
}
}
/**
* Get the size of the header of this list.
- *
+ *
* @return {@code >= 0;} the header size
*/
private int headerSize() {
/** {@code non-null;} output stream to write to */
private final AnnotatedOutput out;
-
+
/**
* Construct an instance.
- *
+ *
* @param file {@code non-null;} file being written
* @param out {@code non-null;} output stream to write to
*/
/**
* Writes out the encoded form of the given constant.
- *
+ *
* @param cst {@code non-null;} the constant to write
*/
public void writeConstant(Constant cst) {
/**
* Gets the value type for the given constant.
- *
+ *
* @param cst {@code non-null;} the constant
* @return the value type; one of the {@code VALUE_*} constants
* defined by this class
if (annotates) {
out.annotate(" size: " + Hex.u4(size));
}
-
+
out.writeUnsignedLeb128(size);
for (int i = 0; i < size; i++) {
* (debugging) annotations and {@code topLevel} is
* {@code true}, then this method will write (debugging)
* annotations.
- *
+ *
* @param annotation {@code non-null;} annotation instance to write
* @param topLevel {@code true} iff the given annotation is the
* top-level annotation or {@code false} if it is a sub-annotation
out.annotate(" type_idx: " + Hex.u4(typeIdx) + " // " +
type.toHuman());
}
-
+
out.writeUnsignedLeb128(typeIds.indexOf(annotation.getType()));
Collection<NameValuePair> pairs = annotation.getNameValuePairs();
CstUtf8 name = pair.getName();
int nameIdx = stringIds.indexOf(name);
Constant value = pair.getValue();
-
+
if (annotates) {
out.annotate(0, " elements[" + at + "]:");
at++;
out.endAnnotation();
}
}
-
+
/**
* Gets the colloquial type name and human form of the type of the
* given constant, when used as an encoded value.
- *
+ *
* @param cst {@code non-null;} the constant
* @return {@code non-null;} its type name and human form
*/
/**
* Helper for {@link #writeConstant}, which writes out the value
* for any signed integral type.
- *
+ *
* @param type the type constant
* @param value {@code long} bits of the value
*/
/**
* Helper for {@link #writeConstant}, which writes out the value
* for any unsigned integral type.
- *
+ *
* @param type the type constant
* @param value {@code long} bits of the value
*/
if (requiredBits == 0) {
requiredBits = 1;
}
-
+
// Round up the requiredBits to a number of bytes.
int requiredBytes = (requiredBits + 0x07) >> 3;
/**
* Helper for {@link #writeConstant}, which writes out a
* right-zero-extended value.
- *
+ *
* @param type the type constant
* @param value {@code long} bits of the value
*/
if (requiredBits == 0) {
requiredBits = 1;
}
-
+
// Round up the requiredBits to a number of bytes.
int requiredBytes = (requiredBits + 0x07) >> 3;
* contents for a particular {@link Annotation}, calling itself
* recursively should it encounter a nested annotation.
*
- * @param file {@code non-null;} the file to add to
+ * @param file {@code non-null;} the file to add to
* @param annotation {@code non-null;} the annotation to add contents for
*/
public static void addContents(DexFile file, Annotation annotation) {
StringIdsSection stringIds = file.getStringIds();
typeIds.intern(annotation.getType());
-
+
for (NameValuePair pair : annotation.getNameValuePairs()) {
stringIds.intern(pair.getName());
addContents(file, pair.getValue());
* should it encounter a {@link CstArray} and calling {@link
* #addContents(DexFile,Annotation)} recursively should it
* encounter a {@link CstAnnotation}.
- *
- * @param file {@code non-null;} the file to add to
+ *
+ * @param file {@code non-null;} the file to add to
* @param cst {@code non-null;} the constant to add contents for
*/
public static void addContents(DexFile file, Constant cst) {
* associated type and additionally consist of a set of (name, value)
* pairs, where the names are unique.
*/
-public final class Annotation extends MutabilityControl
+public final class Annotation extends MutabilityControl
implements Comparable<Annotation>, ToHuman {
/** {@code non-null;} type of the annotation */
private final CstType type;
/** {@code non-null;} map from names to {@link NameValuePair} instances */
private final TreeMap<CstUtf8, NameValuePair> elements;
-
+
/**
* Construct an instance. It initially contains no elements.
- *
+ *
* @param type {@code non-null;} type of the annotation
* @param visibility {@code non-null;} the visibility of the annotation
*/
public String toString() {
return toHuman();
}
-
+
/** {@inheritDoc} */
public String toHuman() {
StringBuilder sb = new StringBuilder();
/**
* Gets the type of this instance.
- *
+ *
* @return {@code non-null;} the type
*/
public CstType getType() {
/**
* Gets the visibility of this instance.
- *
+ *
* @return {@code non-null;} the visibility
*/
public AnnotationVisibility getVisibility() {
* Put an element into the set of (name, value) pairs for this instance.
* If there is a preexisting element with the same name, it will be
* replaced by this method.
- *
+ *
* @param pair {@code non-null;} the (name, value) pair to place into this instance
*/
public void put(NameValuePair pair) {
throwIfImmutable();
-
+
if (pair == null) {
throw new NullPointerException("pair == null");
}
* Add an element to the set of (name, value) pairs for this instance.
* It is an error to call this method if there is a preexisting element
* with the same name.
- *
+ *
* @param pair {@code non-null;} the (name, value) pair to add to this instance
*/
public void add(NameValuePair pair) {
throwIfImmutable();
-
+
if (pair == null) {
throw new NullPointerException("pair == null");
}
if (elements.get(name) != null) {
throw new IllegalArgumentException("name already added: " + name);
}
-
+
elements.put(name, pair);
}
/**
* Gets the set of name-value pairs contained in this instance. The
* result is always unmodifiable.
- *
+ *
* @return {@code non-null;} the set of name-value pairs
*/
public Collection<NameValuePair> getNameValuePairs() {
/**
* Constructs an instance.
- *
+ *
* @param human {@code non-null;} the human-oriented string representation
*/
private AnnotationVisibility(String human) {
/**
* List of {@link Annotation} instances.
*/
-public final class Annotations extends MutabilityControl
+public final class Annotations extends MutabilityControl
implements Comparable<Annotations> {
/** {@code non-null;} immutable empty instance */
public static final Annotations EMPTY = new Annotations();
static {
EMPTY.setImmutable();
}
-
+
/** {@code non-null;} map from types to annotations */
private final TreeMap<CstType, Annotation> annotations;
* Constructs an immutable instance which is the combination of the
* two given instances. The two instances must contain disjoint sets
* of types.
- *
+ *
* @param a1 {@code non-null;} an instance
* @param a2 {@code non-null;} the other instance
* @return {@code non-null;} the combination
return result;
}
-
+
/**
* Constructs an immutable instance which is the combination of the
* given instance with the given additional annotation. The latter's
* type must not already appear in the former.
- *
+ *
* @param annotations {@code non-null;} the instance to augment
* @param annotation {@code non-null;} the additional annotation
* @return {@code non-null;} the combination
return result;
}
-
+
/**
* Constructs an empty instance.
*/
sb.append("}");
return sb.toString();
}
-
+
/**
* Gets the number of elements in this instance.
- *
+ *
* @return {@code >= 0;} the size
*/
public int size() {
/**
* Adds an element to this instance. There must not already be an
* element of the same type.
- *
+ *
* @param annotation {@code non-null;} the element to add
* @throws IllegalArgumentException thrown if there is a duplicate type
*/
}
CstType type = annotation.getType();
-
+
if (annotations.containsKey(type)) {
throw new IllegalArgumentException("duplicate type: " +
type.toHuman());
/**
* Adds all of the elements of the given instance to this one. The
* instances must not have any duplicate types.
- *
+ *
* @param toAdd {@code non-null;} the annotations to add
* @throws IllegalArgumentException thrown if there is a duplicate type
*/
/**
* Gets the set of annotations contained in this instance. The
* result is always unmodifiable.
- *
+ *
* @return {@code non-null;} the set of annotations
*/
public Collection<Annotation> getAnnotations() {
extends FixedSizeList {
/** {@code non-null;} immutable empty instance */
public static final AnnotationsList EMPTY = new AnnotationsList(0);
-
+
/**
* Constructs an immutable instance which is the combination of
* the two given instances. The two instances must each have the
* same number of elements, and each pair of elements must contain
* disjoint sets of types.
- *
+ *
* @param list1 {@code non-null;} an instance
* @param list2 {@code non-null;} the other instance
* @return {@code non-null;} the combination
/**
* Constructs an instance. All indices initially contain {@code null}.
- *
+ *
* @param size the size of the list
*/
public AnnotationsList(int size) {
* Gets the element at the given index. It is an error to call
* this with the index for an element which was never set; if you
* do that, this will throw {@code NullPointerException}.
- *
+ *
* @param n {@code >= 0, < size();} which index
* @return {@code non-null;} element at that index
*/
/**
* Sets the element at the given index. The given element must be
* immutable.
- *
+ *
* @param n {@code >= 0, < size();} which index
* @param a {@code null-ok;} the element to set at {@code n}
*/
/** {@code non-null;} the value */
private final Constant value;
-
+
/**
* Construct an instance.
- *
+ *
* @param name {@code non-null;} the name
* @param value {@code non-null;} the value
*/
if (value instanceof CstUtf8) {
throw new IllegalArgumentException("bad value: " + value);
}
-
+
this.name = name;
this.value = value;
}
public int hashCode() {
return name.hashCode() * 31 + value.hashCode();
}
-
+
/** {@inheritDoc} */
public boolean equals(Object other) {
if (! (other instanceof NameValuePair)) {
/**
* {@inheritDoc}
- *
+ *
* <p>Instances of this class compare in name-major and value-minor
* order.</p>
*/
}
return value.compareTo(other.value);
- }
+ }
/**
* Gets the name.
- *
+ *
* @return {@code non-null;} the name
*/
public CstUtf8 getName() {
return name;
}
-
+
/**
* Gets the value.
- *
+ *
* @return {@code non-null;} the value
*/
public Constant getValue() {
/**
* class with new-style {@code invokespecial} for superclass
- * method access
+ * method access
*/
public static final int ACC_SUPER = 0x0020;
/**
* method with strict floating point ({@code strictfp})
- * behavior
+ * behavior
*/
public static final int ACC_STRICT = 0x0800;
/**
* class is an enumerated type; field is an element of an enumerated
- * type
+ * type
*/
public static final int ACC_ENUM = 0x4000;
/**
* Returns a human-oriented string representing the given access flags,
* as defined on classes (not fields or methods).
- *
+ *
* @param flags the flags
* @return {@code non-null;} human-oriented string
*/
/**
* Returns a human-oriented string representing the given access flags,
* as defined on inner classes.
- *
+ *
* @param flags the flags
* @return {@code non-null;} human-oriented string
*/
/**
* Returns a human-oriented string representing the given access flags,
* as defined on fields (not classes or methods).
- *
+ *
* @param flags the flags
* @return {@code non-null;} human-oriented string
*/
/**
* Returns a human-oriented string representing the given access flags,
* as defined on methods (not classes or fields).
- *
+ *
* @param flags the flags
* @return {@code non-null;} human-oriented string
*/
/**
* Returns whether the flag {@code ACC_PUBLIC} is on in the given
* flags.
- *
+ *
* @param flags the flags to check
* @return the value of the {@code ACC_PUBLIC} flag
*/
/**
* Returns whether the flag {@code ACC_PROTECTED} is on in the given
* flags.
- *
+ *
* @param flags the flags to check
* @return the value of the {@code ACC_PROTECTED} flag
*/
/**
* Returns whether the flag {@code ACC_PRIVATE} is on in the given
* flags.
- *
+ *
* @param flags the flags to check
* @return the value of the {@code ACC_PRIVATE} flag
*/
/**
* Returns whether the flag {@code ACC_STATIC} is on in the given
* flags.
- *
+ *
* @param flags the flags to check
* @return the value of the {@code ACC_STATIC} flag
*/
public static boolean isStatic(int flags) {
return (flags & ACC_STATIC) != 0;
}
-
+
/**
* Returns whether the flag {@code ACC_SYNCHRONIZED} is on in
* the given flags.
- *
+ *
* @param flags the flags to check
* @return the value of the {@code ACC_SYNCHRONIZED} flag
*/
/**
* Returns whether the flag {@code ACC_ABSTRACT} is on in the given
* flags.
- *
+ *
* @param flags the flags to check
* @return the value of the {@code ACC_ABSTRACT} flag
*/
/**
* Returns whether the flag {@code ACC_NATIVE} is on in the given
* flags.
- *
+ *
* @param flags the flags to check
* @return the value of the {@code ACC_NATIVE} flag
*/
/**
* Returns whether the flag {@code ACC_ANNOTATION} is on in the given
* flags.
- *
+ *
* @param flags the flags to check
* @return the value of the {@code ACC_ANNOTATION} flag
*/
/**
* Returns whether the flag {@code ACC_DECLARED_SYNCHRONIZED} is
* on in the given flags.
- *
+ *
* @param flags the flags to check
* @return the value of the {@code ACC_DECLARED_SYNCHRONIZED} flag
*/
/**
* Helper to return a human-oriented string representing the given
* access flags.
- *
+ *
* @param flags the defined flags
* @param mask mask for the "defined" bits
* @param what what the flags represent (one of {@code CONV_*})
/**
* {@code non-null;} full list of successors that this block may
- * branch to
+ * branch to
*/
private final IntList successors;
/**
* {@code >= -1;} the primary / standard-flow / "default" successor, or
* {@code -1} if this block has no successors (that is, it
- * exits the function/method)
+ * exits the function/method)
*/
private final int primarySuccessor;
/**
* Constructs an instance. The predecessor set is set to {@code null}.
- *
+ *
* @param label {@code >= 0;} target label for this block
* @param insns {@code non-null;} list of instructions in this block
* @param successors {@code non-null;} full list of successors that this
/**
* {@inheritDoc}
- *
+ *
* Instances of this class compare by identity. That is,
* {@code x.equals(y)} is only true if {@code x == y}.
*/
/**
* {@inheritDoc}
- *
+ *
* Return the identity hashcode of this instance. This is proper,
* since instances of this class compare by identity (see {@link #equals}).
*/
/**
* Gets the target label of this block.
- *
+ *
* @return {@code >= 0;} the label
*/
public int getLabel() {
/**
* Gets the list of instructions inside this block.
- *
+ *
* @return {@code non-null;} the instruction list
*/
public InsnList getInsns() {
/**
* Gets the list of successors that this block may branch to.
- *
+ *
* @return {@code non-null;} the successors list
*/
public IntList getSuccessors() {
/**
* Gets the primary successor of this block.
- *
+ *
* @return {@code >= -1;} the primary successor, or {@code -1} if this
* block has no successors at all
*/
/**
* Gets the secondary successor of this block. It is only valid to call
* this method on blocks that have exactly two successors.
- *
+ *
* @return {@code >= 0;} the secondary successor
*/
public int getSecondarySuccessor() {
/**
* Gets the first instruction of this block. This is just a
* convenient shorthand for {@code getInsns().get(0)}.
- *
+ *
* @return {@code non-null;} the first instruction
*/
public Insn getFirstInsn() {
/**
* Gets the last instruction of this block. This is just a
* convenient shorthand for {@code getInsns().getLast()}.
- *
+ *
* @return {@code non-null;} the last instruction
*/
public Insn getLastInsn() {
/**
* Returns whether this block might throw an exception. This is
* just a convenient shorthand for {@code getLastInsn().canThrow()}.
- *
+ *
* @return {@code true} iff this block might throw an
* exception
*/
* This is just a shorthand for inspecting the last instruction in
* the block to see if it could throw, and if so, whether it in fact
* has any associated handlers.
- *
+ *
* @return {@code true} iff this block has any associated
* exception handlers
*/
* Returns an instance that is identical to this one, except that
* the registers in each instruction are offset by the given
* amount.
- *
+ *
* @param delta the amount to offset register numbers by
* @return {@code non-null;} an appropriately-constructed instance
*/
public final class BasicBlockList extends LabeledList {
/**
* {@code >= -1;} the count of registers required by this method or
- * {@code -1} if not yet calculated
+ * {@code -1} if not yet calculated
*/
private int regCount;
/**
* Constructs an instance. All indices initially contain {@code null},
* and the first-block label is initially {@code -1}.
- *
+ *
* @param size the size of the list
*/
public BasicBlockList(int size) {
/**
* Constructs a mutable copy for {@code getMutableCopy()}.
- *
+ *
* @param old block to copy
*/
private BasicBlockList (BasicBlockList old) {
* Gets the element at the given index. It is an error to call
* this with the index for an element which was never set; if you
* do that, this will throw {@code NullPointerException}.
- *
+ *
* @param n {@code >= 0, < size();} which index
* @return {@code non-null;} element at that index
*/
/**
* Sets the basic block at the given index.
- *
+ *
* @param n {@code >= 0, < size();} which index
* @param bb {@code null-ok;} the element to set at {@code n}
*/
public void set(int n, BasicBlock bb) {
super.set(n, bb);
-
+
// Reset regCount, since it will need to be recalculated.
regCount = -1;
}
* the maximum of register-number-plus-category referred to by this
* instance's instructions (indirectly through {@link BasicBlock}
* instances).
- *
+ *
* @return {@code >= 0;} the register count
*/
public int getRegCount() {
/**
* Gets the total instruction count for this instance. This is the
* sum of the instruction counts of each block.
- *
+ *
* @return {@code >= 0;} the total instruction count
*/
public int getInstructionCount() {
/**
* Visits each instruction of each block in the list, in order.
- *
+ *
* @param visitor {@code non-null;} visitor to use
*/
public void forEachInsn(Insn.Visitor visitor) {
* the registers in each instruction are offset by the given
* amount. Mutability of the result is inherited from the
* original.
- *
+ *
* @param delta the amount to offset register numbers by
* @return {@code non-null;} an appropriately-constructed instance
*/
* Otherwise, if the block has a primay successor, then that is
* the preferred successor. If the block has no successors, then
* this returns {@code null}.
- *
+ *
* @param block {@code non-null;} the block in question
* @return {@code null-ok;} the preferred successor, if any
*/
/**
* Compares the catches of two blocks for equality. This includes
* both the catch types and target labels.
- *
+ *
* @param block1 {@code non-null;} one block to compare
* @param block2 {@code non-null;} the other block to compare
* @return {@code true} if the two blocks' non-primary successors
*/
return false;
}
-
+
for (int i = 0; i < size; i++) {
int label1 = succ1.get(i);
int label2 = succ2.get(i);
/**
* Gets the register count.
- *
+ *
* @return {@code >= 0;} the count
*/
public int getRegCount() {
/**
* Helper for all the {@code visit*} methods.
- *
+ *
* @param insn {@code non-null;} instruction being visited
*/
private void visit(Insn insn) {
/**
* Processes the given register spec.
- *
+ *
* @param spec {@code non-null;} the register spec
*/
private void processReg(RegisterSpec spec) {
regCount = reg;
}
}
- }
+ }
}
private ConservativeTranslationAdvice() {
// This space intentionally left blank.
}
-
+
/** {@inheritDoc} */
public boolean hasConstantOperation(Rop opcode,
RegisterSpec sourceA, RegisterSpec sourceB) {
/**
* Constructs an instance.
- *
+ *
* @param opcode {@code non-null;} the opcode
* @param position {@code non-null;} source position
* @param result {@code null-ok;} spec for the result, if any
/**
* Gets the constant.
- *
+ *
* @return {@code non-null;} the constant
*/
public Constant getConstant() {
/**
* {@code non-null;} the type
- * {@code java.lang.ArrayIndexOutOfBoundsException}
+ * {@code java.lang.ArrayIndexOutOfBoundsException}
*/
public static final Type TYPE_ArrayIndexOutOfBoundsException =
Type.intern("Ljava/lang/ArrayIndexOutOfBoundsException;");
/**
* {@code non-null;} the type
- * {@code java.lang.IllegalMonitorStateException}
+ * {@code java.lang.IllegalMonitorStateException}
*/
public static final Type TYPE_IllegalMonitorStateException =
Type.intern("Ljava/lang/IllegalMonitorStateException;");
/**
* {@code non-null;} the list {@code [java.lang.Error,
- * java.lang.NegativeArraySizeException]}
+ * java.lang.NegativeArraySizeException]}
*/
public static final StdTypeList LIST_Error_NegativeArraySizeException =
StdTypeList.make(TYPE_Error, TYPE_NegativeArraySizeException);
/**
* Constructs an instance.
- *
+ *
* @param opcode {@code non-null;} the opcode
* @param position {@code non-null;} source position
* @param sources {@code non-null;} specs for all the sources
/**
* Constructs an instance.
- *
+ *
* @param opcode {@code non-null;} the opcode
* @param position {@code non-null;} source position
* @param result {@code null-ok;} spec for the result, if any
/**
* {@inheritDoc}
- *
+ *
* Instances of this class compare by identity. That is,
* {@code x.equals(y)} is only true if {@code x == y}.
*/
/**
* {@inheritDoc}
- *
+ *
* This implementation returns the identity hashcode of this
* instance. This is proper, since instances of this class compare
* by identity (see {@link #equals}).
/**
* Gets a human-oriented (and slightly lossy) string for this instance.
- *
+ *
* @return {@code non-null;} the human string form
*/
public String toHuman() {
/**
* Gets an "inline" string portion for toHuman(), if available. This
* is the portion that appears after the Rop opcode
- *
+ *
* @return {@code null-ok;} if non-null, the inline text for toHuman()
*/
public String getInlineString() {
/**
* Gets the opcode.
- *
+ *
* @return {@code non-null;} the opcode
*/
public final Rop getOpcode() {
/**
* Gets the source position.
- *
+ *
* @return {@code non-null;} the source position
*/
public final SourcePosition getPosition() {
/**
* Gets the result spec, if any. A return value of {@code null}
* means this instruction returns nothing.
- *
+ *
* @return {@code null-ok;} the result spec, if any
*/
public final RegisterSpec getResult() {
* instruction, or null if no local variable assignment occurs. This
* may be the result register, or for {@code mark-local} insns
* it may be the source.
- *
+ *
* @return {@code null-ok;} a named register spec or null
*/
public final RegisterSpec getLocalAssignment() {
/**
* Gets the source specs.
- *
+ *
* @return {@code non-null;} the source specs
*/
public final RegisterSpecList getSources() {
/**
* Gets whether this instruction can possibly throw an exception. This
* is just a convenient wrapper for {@code getOpcode().canThrow()}.
- *
+ *
* @return {@code true} iff this instruction can possibly throw
*/
public final boolean canThrow() {
* throw or if it merely doesn't handle any of its possible
* exceptions. To determine whether this instruction can throw,
* use {@link #canThrow}.
- *
+ *
* @return {@code non-null;} the catches list
*/
public abstract TypeList getCatches();
/**
* Calls the appropriate method on the given visitor, depending on the
* class of this instance. Subclasses must override this.
- *
+ *
* @param visitor {@code non-null;} the visitor to call on
*/
public abstract void accept(Visitor visitor);
* method throws an exception if this instance can't possibly
* throw. To determine whether this instruction can throw, use
* {@link #canThrow}.
- *
+ *
* @param type {@code non-null;} type to append to the catch list
* @return {@code non-null;} an appropriately-constructed instance
*/
/**
* Returns an instance that is just like this one, except that all
* register references have been offset by the given delta.
- *
+ *
* @param delta the amount to offset register references by
* @return {@code non-null;} an appropriately-constructed instance
*/
* source (if it is a constant) is represented directly rather than
* as a register reference. {@code this} is returned in cases where
* the translation is not possible.
- *
+ *
* @return {@code non-null;} an appropriately-constructed instance
*/
public Insn withLastSourceLiteral() {
* to be an identity compare. Insn's are {@code contentEquals()}
* if they have the same opcode, registers, source position, and other
* metadata.
- *
+ *
* @return true in the case described above
*/
public boolean contentEquals(Insn b) {
/**
* Returns the string form of this instance, with the given bit added in
* the standard location for an inline argument.
- *
+ *
* @param extra {@code null-ok;} the inline argument string
* @return {@code non-null;} the string form
*/
/**
* Returns the human string form of this instance, with the given
* bit added in the standard location for an inline argument.
- *
+ *
* @param extra {@code null-ok;} the inline argument string
* @return {@code non-null;} the human string form
*/
public static interface Visitor {
/**
* Visits a {@link PlainInsn}.
- *
+ *
* @param insn {@code non-null;} the instruction to visit
*/
public void visitPlainInsn(PlainInsn insn);
/**
* Visits a {@link PlainCstInsn}.
- *
+ *
* @param insn {@code non-null;} the instruction to visit
*/
public void visitPlainCstInsn(PlainCstInsn insn);
/**
* Visits a {@link SwitchInsn}.
- *
+ *
* @param insn {@code non-null;} the instruction to visit
*/
public void visitSwitchInsn(SwitchInsn insn);
/**
* Visits a {@link ThrowingCstInsn}.
- *
+ *
* @param insn {@code non-null;} the instruction to visit
*/
public void visitThrowingCstInsn(ThrowingCstInsn insn);
/**
* Visits a {@link ThrowingInsn}.
- *
+ *
* @param insn {@code non-null;} the instruction to visit
*/
public void visitThrowingInsn(ThrowingInsn insn);
/**
* Gets the last instruction. This is just a convenient shorthand for
* {@code get(size() - 1)}.
- *
+ *
* @return {@code non-null;} the last instruction
*/
public Insn getLast() {
int sz = size();
if (sz != b.size()) return false;
-
+
for (int i = 0; i < sz; i++) {
if (!get(i).contentEquals(b.get(i))) {
return false;
* the registers in each instruction are offset by the given
* amount. Mutability of the result is inherited from the
* original.
- *
+ *
* @param delta the amount to offset register numbers by
* @return {@code non-null;} an appropriately-constructed instance
*/
return 0 == compareTo(local);
}
- /**
+ /**
* Compares two strings like String.compareTo(), excepts treats a null
* as the least-possible string value.
*
/**
* Extracts out all the local variable information from the given method.
- *
+ *
* @param method {@code non-null;} the method to extract from
* @return {@code non-null;} the extracted information
*/
/**
* Constructs an instance. This method is private. Use {@link #extract}.
- *
+ *
* @param method {@code non-null;} the method to extract from
*/
private LocalVariableExtractor(RopMethod method) {
/**
* Does the extraction.
- *
+ *
* @return {@code non-null;} the extracted information
*/
private LocalVariableInfo doit() {
Bits.clear(workSet, label);
processBlock(label);
}
-
+
resultInfo.setImmutable();
return resultInfo;
}
/**
* Processes a single block.
- *
+ *
* @param label {@code >= 0;} label of the block to process
*/
private void processBlock(int label) {
if (previous != null
&& (previous.getReg() != result.getReg())) {
- primaryState.remove(previous);
+ primaryState.remove(previous);
}
resultInfo.addAssignment(insn, result);
/**
* {@code non-null;} {@link RegisterSpecSet} to use when indicating a block
* that has no locals; it is empty and immutable but has an appropriate
- * max size for the method
+ * max size for the method
*/
private final RegisterSpecSet emptySet;
/**
* {@code non-null;} array consisting of register sets representing the
* sets of variables already assigned upon entry to each block,
- * where array indices correspond to block labels
+ * where array indices correspond to block labels
*/
private final RegisterSpecSet[] blockStarts;
/**
* Constructs an instance.
- *
+ *
* @param method {@code non-null;} the method being represented by this instance
*/
public LocalVariableInfo(RopMethod method) {
/**
* Sets the register set associated with the start of the block with
* the given label.
- *
+ *
* @param label {@code >= 0;} the block label
* @param specs {@code non-null;} the register set to associate with the block
*/
* is the same as calling {@link #setStarts}. Otherwise, this will
* merge the two sets and call {@link #setStarts} on the result of the
* merge.
- *
+ *
* @param label {@code >= 0;} the block label
* @param specs {@code non-null;} the register set to merge into the start set
* for the block
* Gets the register set associated with the start of the block
* with the given label. This returns an empty set with the appropriate
* max size if no set was associated with the block in question.
- *
+ *
* @param label {@code >= 0;} the block label
* @return {@code non-null;} the associated register set
*/
* Gets the register set associated with the start of the given
* block. This is just convenient shorthand for
* {@code getStarts(block.getLabel())}.
- *
+ *
* @param block {@code non-null;} the block in question
* @return {@code non-null;} the associated register set
*/
* start of the block with the given label. This returns a
* newly-allocated empty {@link RegisterSpecSet} of appropriate
* max size if there is not yet any set associated with the block.
- *
+ *
* @param label {@code >= 0;} the block label
* @return {@code non-null;} the associated register set
*/
* Adds an assignment association for the given instruction and
* register spec. This throws an exception if the instruction
* doesn't actually perform a named variable assignment.
- *
+ *
* <b>Note:</b> Although the instruction contains its own spec for
* the result, it still needs to be passed in explicitly to this
* method, since the spec that is stored here should always have a
* simple type and the one in the instruction can be an arbitrary
* {@link TypeBearer} (such as a constant value).
- *
+ *
* @param insn {@code non-null;} the instruction in question
* @param spec {@code non-null;} the associated register spec
*/
/**
* Gets the named register being assigned by the given instruction, if
* previously stored in this instance.
- *
+ *
* @param insn {@code non-null;} instruction in question
* @return {@code null-ok;} the named register being assigned, if any
*/
/**
* Gets the number of assignments recorded by this instance.
- *
+ *
* @return {@code >= 0;} the number of assignments
*/
public int getAssignmentCount() {
/**
* Helper method, to get the starts for a label, throwing the
* right exception for range problems.
- *
+ *
* @param label {@code >= 0;} the block label
* @return {@code null-ok;} associated register set or {@code null} if there
* is none
extends CstInsn {
/**
* Constructs an instance.
- *
+ *
* @param opcode {@code non-null;} the opcode
* @param position {@code non-null;} source position
* @param result {@code null-ok;} spec for the result, if any
extends Insn {
/**
* Constructs an instance.
- *
+ *
* @param opcode {@code non-null;} the opcode
* @param position {@code non-null;} source position
* @param result {@code null-ok;} spec for the result, if any
if (result != null && opcode.getBranchingness() != Rop.BRANCH_NONE) {
// move-result-pseudo is required here
throw new IllegalArgumentException
- ("can't mix branchingness with result");
+ ("can't mix branchingness with result");
}
}
/**
* Constructs a single-source instance.
- *
+ *
* @param opcode {@code non-null;} the opcode
* @param position {@code non-null;} source position
* @param result {@code null-ok;} spec for the result, if any
/**
* All the register-based opcodes, and related utilities.
- *
+ *
* <p><b>Note:</b> Opcode descriptions use a rough pseudocode. {@code r}
* is the result register, {@code x} is the first argument,
* {@code y} is the second argument, and {@code z} is the
/**
* {@code T: any numeric type; r,x,y: T :: r = x % y}
- * (Java-style remainder)
+ * (Java-style remainder)
*/
public static final int REM = 18;
/**
* {@code T: any integral type; r,x: T; y: int :: r = x >> y}
- * (signed right-shift)
+ * (signed right-shift)
*/
public static final int SHR = 24;
/**
* {@code T: any integral type; r,x: T; y: int :: r = x >>> y}
- * (unsigned right-shift)
+ * (unsigned right-shift)
*/
public static final int USHR = 25;
* {@code T: any numeric type; r: int; x,y: T :: r = (x == y) ? 0
* : (x > y) ? 1 : -1} (Java-style "cmpl" where a NaN is
* considered "less than" all other values; also used for integral
- * comparisons)
+ * comparisons)
*/
public static final int CMPL = 27;
/**
* {@code T: any floating point type; r: int; x,y: T :: r = (x == y) ? 0
* : (x < y) ? -1 : 1} (Java-style "cmpg" where a NaN is
- * considered "greater than" all other values)
+ * considered "greater than" all other values)
*/
public static final int CMPG = 28;
/**
* {@code T: any numeric type; U: any numeric type; r: T; x: U ::
* r = (T) x} (numeric type conversion between the four
- * "real" numeric types)
+ * "real" numeric types)
*/
public static final int CONV = 29;
/**
* {@code r,x: int :: r = (x << 24) >> 24} (Java-style
- * convert int to byte)
+ * convert int to byte)
*/
public static final int TO_BYTE = 30;
/**
- * {@code r,x: int :: r = x & 0xffff} (Java-style convert int to char)
+ * {@code r,x: int :: r = x & 0xffff} (Java-style convert int to char)
*/
public static final int TO_CHAR = 31;
/**
* {@code r,x: int :: r = (x << 16) >> 16} (Java-style
- * convert int to short)
+ * convert int to short)
*/
public static final int TO_SHORT = 32;
/**
* {@code T: any non-array object type :: r =
- * alloc(T)} (allocate heap space for an object)
+ * alloc(T)} (allocate heap space for an object)
*/
public static final int NEW_INSTANCE = 40;
/**
* {@code T: any object type; x: Object :: (T) x} (can
- * throw {@code ClassCastException})
+ * throw {@code ClassCastException})
*/
public static final int CHECK_CAST = 43;
/**
* {@code T: any type; r: T; f: static field spec of type T :: r =
- * f}
+ * f}
*/
public static final int GET_STATIC = 46;
/**
* {@code T: any type; x: T; y: Object; f: instance field spec of type
- * T :: y.f = x}
+ * T :: y.f = x}
*/
public static final int PUT_FIELD = 47;
/**
* {@code Tr, T0, T1...: any types; r: Tr; m: static method spec;
* y0: T0; y1: T1 ... :: r = m(y0, y1, ...)} (call static
- * method)
+ * method)
*/
public static final int INVOKE_STATIC = 49;
/**
* {@code Tr, T0, T1...: any types; r: Tr; x: Object; m: instance method
* spec; y0: T0; y1: T1 ... :: r = x.m(y0, y1, ...)} (call normal
- * virtual method)
+ * virtual method)
*/
public static final int INVOKE_VIRTUAL = 50;
/**
* {@code Tr, T0, T1...: any types; r: Tr; x: Object; m: instance method
* spec; y0: T0; y1: T1 ... :: r = x.m(y0, y1, ...)} (call
- * superclass virtual method)
+ * superclass virtual method)
*/
public static final int INVOKE_SUPER = 51;
/**
* {@code Tr, T0, T1...: any types; r: Tr; x: Object; m: instance method
* spec; y0: T0; y1: T1 ... :: r = x.m(y0, y1, ...)} (call
- * direct/special method)
+ * direct/special method)
*/
public static final int INVOKE_DIRECT = 52;
/**
* {@code Tr, T0, T1...: any types; r: Tr; x: Object; m: interface
* (instance) method spec; y0: T0; y1: T1 ... :: r = x.m(y0, y1,
- * ...)} (call interface method)
+ * ...)} (call interface method)
*/
public static final int INVOKE_INTERFACE = 53;
/**
* Gets the name of the given opcode.
- *
+ *
* @param opcode {@code >= 0, <= 255;} the opcode
* @return {@code non-null;} its name
*/
* Returns an instance for the given register number and type, with
* no variable info. This method is allowed to return shared
* instances (but doesn't necessarily do so).
- *
+ *
* @param reg {@code >= 0;} the register number
* @param type {@code non-null;} the type (or possibly actual value) which
* is loaded from or stored to the indicated register
/**
* Gets the string form for the given register number.
- *
+ *
* @param reg {@code >= 0;} the register number
* @return {@code non-null;} the string form
*/
/**
* Constructs an instance. This constructor is private. Use
* {@link #make}.
- *
+ *
* @param reg {@code >= 0;} the register number
* @param type {@code non-null;} the type (or possibly actual value) which
* is loaded from or stored to the indicated register
* registers. That is, this compares {@code getType()} on the types
* to ignore whatever arbitrary extra stuff might be carried around
* by an outer {@link TypeBearer}.
- *
+ *
* @param other {@code null-ok;} spec to compare to
* @return {@code true} iff {@code this} and {@code other} are equal
* in the stated way
* Like {@link #equalsUsingSimpleType} but ignoring the register number.
* This is useful to determine if two instances refer to the "same"
* local variable.
- *
+ *
* @param other {@code null-ok;} spec to compare to
* @return {@code true} iff {@code this} and {@code other} are equal
* in the stated way
/**
* Helper for {@link #equals} and {@link #ForComparison.equals},
* which actually does the test.
- *
+ *
* @param reg value of the instance variable, for another instance
* @param type value of the instance variable, for another instance
* @param local value of the instance variable, for another instance
/**
* Compares by (in priority order) register number, unwrapped type
* (that is types not {@link TypeBearer}s, and local info.
- *
+ *
* @param other {@code non-null;} spec to compare to
* @return {@code -1..1;} standard result of comparison
*/
}
return this.local.compareTo(other.local);
- }
+ }
/** {@inheritDoc} */
@Override
/**
* Helper for {@link #hashCode} and {@link #ForComparison.hashCode},
* which actually does the calculation.
- *
+ *
* @param reg value of the instance variable
* @param type value of the instance variable
* @param local value of the instance variable
/**
* Gets the register number.
- *
+ *
* @return {@code >= 0;} the register number
*/
public int getReg() {
/**
* Gets the type (or actual value) which is loaded from or stored
* to the register associated with this instance.
- *
+ *
* @return {@code non-null;} the type
*/
public TypeBearer getTypeBearer() {
* (category) of the type used. Among other things, this may also
* be used to determine the minimum required register count
* implied by this instance.
- *
+ *
* @return {@code >= 0;} the required registers size
*/
public int getNextReg() {
/**
* Gets the category of this instance's type. This is just a convenient
* shorthand for {@code getType().getCategory()}.
- *
+ *
* @see #isCategory1
* @see #isCategory2
* @return {@code 1..2;} the category of this instance's type
/**
* Gets whether this instance's type is category 1. This is just a
* convenient shorthand for {@code getType().isCategory1()}.
- *
+ *
* @see #getCategory
* @see #isCategory2
* @return whether or not this instance's type is of category 1
/**
* Gets whether this instance's type is category 2. This is just a
* convenient shorthand for {@code getType().isCategory2()}.
- *
+ *
* @see #getCategory
* @see #isCategory1
* @return whether or not this instance's type is of category 2
/**
* Gets the string form for just the register number of this instance.
- *
+ *
* @return {@code non-null;} the register string form
*/
public String regString() {
/**
* Returns an instance that is the intersection between this instance
* and the given one, if any. The intersection is defined as follows:
- *
+ *
* <ul>
* <li>If {@code other} is {@code null}, then the result
* is {@code null}.
* of the intersection is the local info of this instance. Otherwise,
* the local info of the intersection is {@code null}.</li>
* </ul>
- *
+ *
* @param other {@code null-ok;} instance to intersect with (or {@code null})
* @param localPrimary whether local variables are primary to the
* intersection; if {@code true}, then the only non-null
/**
* Returns an instance that is identical to this one, except that the
* register number is replaced by the given one.
- *
+ *
* @param newReg {@code >= 0;} the new register number
* @return {@code non-null;} an appropriately-constructed instance
*/
/**
* Returns an instance that is identical to this one, except that the
* register number is offset by the given amount.
- *
+ *
* @param delta the amount to offset the register number by
* @return {@code non-null;} an appropriately-constructed instance
*/
return withReg(reg + delta);
}
-
+
/**
* Returns an instance that is identical to this one, except that
* the type bearer is replaced by the actual underlying type
* (thereby stripping off non-type information) with any
* initialization information stripped away as well.
- *
+ *
* @return {@code non-null;} an appropriately-constructed instance
*/
public RegisterSpec withSimpleType() {
/**
* Helper for {@link #toString} and {@link #toHuman}.
- *
+ *
* @param human whether to be human-oriented
* @return {@code non-null;} the string form
*/
private static class ForComparison {
/** {@code >= 0;} register number */
private int reg;
-
+
/** {@code non-null;} type loaded or stored */
private TypeBearer type;
/**
* Set all the instance variables.
- *
+ *
* @param reg {@code >= 0;} the register number
* @param type {@code non-null;} the type (or possibly actual
* value) which is loaded from or stored to the indicated
/**
* Construct a {@code RegisterSpec} of this instance's
* contents.
- *
+ *
* @return {@code non-null;} an appropriately-constructed instance
*/
public RegisterSpec toRegisterSpec() {
/**
* Makes a single-element instance.
- *
+ *
* @param spec {@code non-null;} the element
* @return {@code non-null;} an appropriately-constructed instance
*/
/**
* Makes a two-element instance.
- *
+ *
* @param spec0 {@code non-null;} the first element
* @param spec1 {@code non-null;} the second element
* @return {@code non-null;} an appropriately-constructed instance
/**
* Makes a three-element instance.
- *
+ *
* @param spec0 {@code non-null;} the first element
* @param spec1 {@code non-null;} the second element
* @param spec2 {@code non-null;} the third element
/**
* Makes a four-element instance.
- *
+ *
* @param spec0 {@code non-null;} the first element
* @param spec1 {@code non-null;} the second element
* @param spec2 {@code non-null;} the third element
/**
* Constructs an instance. All indices initially contain {@code null}.
- *
+ *
* @param size the size of the list
*/
public RegisterSpecList(int size) {
public TypeList withAddedType(Type type) {
throw new UnsupportedOperationException("unsupported");
}
-
+
/**
* Gets the indicated element. It is an error to call this with the
* index for an element which was never set; if you do that, this
* will throw {@code NullPointerException}.
- *
+ *
* @param n {@code >= 0, < size();} which element
* @return {@code non-null;} the indicated element
*/
}
}
- return -1;
+ return -1;
}
-
+
/**
* Sets the element at the given index.
- *
+ *
* @param n {@code >= 0, < size();} which element
* @param spec {@code non-null;} the value to store
*/
* instance. This is equal to the highest register number referred
* to plus the widest width (largest category) of the type used in
* that register.
- *
+ *
* @return {@code >= 0;} the required registers size
*/
public int getRegistersSize() {
* Returns a new instance, which is the same as this instance,
* except that it has an additional element prepended to the original.
* Mutability of the result is inherited from the original.
- *
+ *
* @param spec {@code non-null;} the new first spec (to prepend)
* @return {@code non-null;} an appropriately-constructed instance
*/
* Returns a new instance, which is the same as this instance,
* except that its first element is removed. Mutability of the
* result is inherited from the original.
- *
+ *
* @return {@code non-null;} an appropriately-constructed instance
*/
public RegisterSpecList withoutFirst() {
* Returns a new instance, which is the same as this instance,
* except that its last element is removed. Mutability of the
* result is inherited from the original.
- *
+ *
* @return {@code non-null;} an appropriately-constructed instance
*/
public RegisterSpecList withoutLast() {
* Returns an instance that is identical to this one, except that
* all register numbers are offset by the given amount. Mutability
* of the result is inherited from the original.
- *
+ *
* @param delta the amount to offset the register numbers by
* @return {@code non-null;} an appropriately-constructed instance
*/
/**
* Returns an instance that is identical to this one, except that
* all register numbers are renumbered sequentially from the given
- * base, with the first number duplicated if indicated.
- *
+ * base, with the first number duplicated if indicated.
+ *
* @param base the base register number
* @param duplicateFirst whether to duplicate the first number
* @return {@code non-null;} an appropriately-constructed instance
/**
* {@code non-null;} array of register specs, where each element is
* {@code null} or is an instance whose {@code reg}
- * matches the array index
+ * matches the array index
*/
private final RegisterSpec[] specs;
/**
* Constructs an instance. The instance is initially empty.
- *
+ *
* @param maxSize {@code >= 0;} the maximum register number (exclusive) that
* may be represented in this instance
*/
sb.append('}');
return sb.toString();
- }
+ }
/**
* Gets the maximum number of registers that may be in this instance, which
* is also the maximum-plus-one of register numbers that may be
* represented.
- *
+ *
* @return {@code >= 0;} the maximum size
*/
public int getMaxSize() {
/**
* Gets the current size of this instance.
- *
+ *
* @return {@code >= 0;} the size
*/
public int size() {
/**
* Gets the element with the given register number, if any.
- *
+ *
* @param reg {@code >= 0;} the desired register number
* @return {@code null-ok;} the element with the given register number or
* {@code null} if there is none
* Gets the element with the same register number as the given
* spec, if any. This is just a convenient shorthand for
* {@code get(spec.getReg())}.
- *
+ *
* @param spec {@code non-null;} spec with the desired register number
* @return {@code null-ok;} the element with the matching register number or
* {@code null} if there is none
* given local (type, name, and signature), or {@code null} if there is
* none. This ignores the register number of the given spec but
* matches on everything else.
- *
+ *
* @param spec {@code non-null;} local to look for
* @return {@code null-ok;} first register found that matches, if any
*/
public RegisterSpec findMatchingLocal(RegisterSpec spec) {
int length = specs.length;
-
+
for (int reg = 0; reg < length; reg++) {
RegisterSpec s = specs[reg];
*/
public RegisterSpec localItemToSpec(LocalItem local) {
int length = specs.length;
-
+
for (int reg = 0; reg < length; reg++) {
RegisterSpec spec = specs[reg];
-
+
if ((spec != null) && local.equals(spec.getLocalItem())) {
return spec;
}
* previous element is nullified. Finally, if the given spec is for
* a category-2 register, then the immediately subsequent element
* is nullified.
- *
+ *
* @param spec {@code non-null;} the register spec to put in the instance
*/
public void put(RegisterSpec spec) {
/**
* Put the entire contents of the given set into this one.
- *
+ *
* @param set {@code non-null;} the set to put into this instance
*/
public void putAll(RegisterSpecSet set) {
* instance. The intersection consists of the pairwise
* {@link RegisterSpec#intersect} of corresponding elements from
* this instance and the given one where both are non-null.
- *
+ *
* @param other {@code non-null;} set to intersect with
* @param localPrimary whether local variables are primary to
* the intersection; if {@code true}, then the only non-null
* Returns an instance that is identical to this one, except that
* all register numbers are offset by the given amount. Mutability
* of the result is inherited from the original.
- *
+ *
* @param delta the amount to offset the register numbers by
* @return {@code non-null;} an appropriately-constructed instance
*/
/**
* Makes and return a mutable copy of this instance.
- *
+ *
* @return {@code non-null;} the mutable copy
*/
public RegisterSpecSet mutableCopy() {
/**
* {@code non-null;} result type of this operation; {@link Type#VOID} for
- * no-result operations
+ * no-result operations
*/
private final Type result;
/**
* the branchingness of this op; one of the {@code BRANCH_*}
- * constants in this class
+ * constants in this class
*/
private final int branchingness;
/**
* Constructs an instance. This method is private. Use one of the
* public constructors.
- *
+ *
* @param opcode the opcode; one of the constants in {@link RegOps}
* @param result {@code non-null;} result type of this operation; {@link
* Type#VOID} for no-result operations
}
/**
- * Constructs an instance. The constructed instance is never a
+ * Constructs an instance. The constructed instance is never a
* call-like op (see {@link #isCallLike}).
- *
+ *
* @param opcode the opcode; one of the constants in {@link RegOps}
* @param result {@code non-null;} result type of this operation; {@link
* Type#VOID} for no-result operations
}
/**
- * Constructs a no-exception instance. The constructed instance is never a
+ * Constructs a no-exception instance. The constructed instance is never a
* call-like op (see {@link #isCallLike}).
- *
+ *
* @param opcode the opcode; one of the constants in {@link RegOps}
* @param result {@code non-null;} result type of this operation; {@link
* Type#VOID} for no-result operations
* Constructs a non-branching no-exception instance. The
* {@code branchingness} is always {@code BRANCH_NONE},
* and it is never a call-like op (see {@link #isCallLike}).
- *
+ *
* @param opcode the opcode; one of the constants in {@link RegOps}
* @param result {@code non-null;} result type of this operation; {@link
* Type#VOID} for no-result operations
* Constructs a non-empty exceptions instance. Its
* {@code branchingness} is always {@code BRANCH_THROW},
* but it is never a call-like op (see {@link #isCallLike}).
- *
+ *
* @param opcode the opcode; one of the constants in {@link RegOps}
* @param result {@code non-null;} result type of this operation; {@link
* Type#VOID} for no-result operations
* Constructs a non-nicknamed instance with non-empty exceptions, which
* is always a call-like op (see {@link #isCallLike}). Its
* {@code branchingness} is always {@code BRANCH_THROW}.
- *
+ *
* @param opcode the opcode; one of the constants in {@link RegOps}
* @param sources {@code non-null;} types of all the sources of this operation
* @param exceptions {@code non-null;} list of possible types thrown by this
/**
* Gets the opcode.
- *
+ *
* @return the opcode
*/
public int getOpcode() {
/**
* Gets the result type. A return value of {@link Type#VOID}
* means this operation returns nothing.
- *
+ *
* @return {@code null-ok;} the result spec
*/
public Type getResult() {
/**
* Gets the source types.
- *
+ *
* @return {@code non-null;} the source types
*/
public TypeList getSources() {
/**
* Gets the list of exception types that might be thrown.
- *
+ *
* @return {@code non-null;} the list of exception types
*/
public TypeList getExceptions() {
/**
* Gets the branchingness of this instance.
- *
+ *
* @return the branchingness
*/
public int getBranchingness() {
/**
* Gets whether this opcode is a function/method call or similar.
- *
+ *
* @return {@code true} iff this opcode is call-like
*/
public boolean isCallLike() {
/**
* Gets the nickname. If this instance has no nickname, this returns
* the result of calling {@link #toString}.
- *
+ *
* @return {@code non-null;} the nickname
*/
public String getNickname() {
* Gets whether this operation can possibly throw an exception. This
* is just a convenient wrapper for
* {@code getExceptions().size() != 0}.
- *
+ *
* @return {@code true} iff this operation can possibly throw
*/
public final boolean canThrow() {
/**
* {@code null-ok;} array of predecessors for each block, indexed by block
- * label
+ * label
*/
private IntList[] predecessors;
/**
* {@code null-ok;} the predecessors for the implicit "exit" block, that is
- * the labels for the blocks that return, if calculated
+ * the labels for the blocks that return, if calculated
*/
private IntList exitPredecessors;
/**
* Constructs an instance.
- *
+ *
* @param blocks {@code non-null;} basic block list of the method
* @param firstLabel {@code >= 0;} the label of the first block to execute
*/
/**
* Gets the basic block list for this method.
- *
+ *
* @return {@code non-null;} the list
*/
public BasicBlockList getBlocks() {
/**
* Gets the label for the first block in the method that this list
* represents.
- *
+ *
* @return {@code >= 0;} the first-block label
*/
public int getFirstLabel() {
/**
* Gets the predecessors associated with the given block. This throws
* an exception if there is no block with the given label.
- *
+ *
* @param label {@code >= 0;} the label of the block in question
* @return {@code non-null;} the predecessors of that block
*/
/**
* Gets the exit predecessors for this instance.
- *
+ *
* @return {@code non-null;} the exit predecessors
*/
public IntList getExitPredecessors() {
* Returns an instance that is identical to this one, except that
* the registers in each instruction are offset by the given
* amount.
- *
+ *
* @param delta the amount to offset register numbers by
* @return {@code non-null;} an appropriately-constructed instance
*/
Rop.BRANCH_IF, "if-ne-object");
/** {@code x: int :: goto switchtable[x]} */
- public static final Rop SWITCH =
+ public static final Rop SWITCH =
new Rop(RegOps.SWITCH, Type.VOID, StdTypeList.INT, Rop.BRANCH_SWITCH,
"switch");
/**
* {@code r,x: int :: r = (x << 24) >> 24} (Java-style
- * convert int to byte)
+ * convert int to byte)
*/
- public static final Rop TO_BYTE =
+ public static final Rop TO_BYTE =
new Rop(RegOps.TO_BYTE, Type.INT, StdTypeList.INT, "to-byte");
/**
* {@code r,x: int :: r = x & 0xffff} (Java-style
- * convert int to char)
+ * convert int to char)
*/
public static final Rop TO_CHAR =
new Rop(RegOps.TO_CHAR, Type.INT, StdTypeList.INT, "to-char");
/**
* {@code r,x: int :: r = (x << 16) >> 16} (Java-style
- * convert int to short)
+ * convert int to short)
*/
public static final Rop TO_SHORT =
new Rop(RegOps.TO_SHORT, Type.INT, StdTypeList.INT, "to-short");
"monitor-exit");
/** {@code r,y: int; x: int[] :: r = x[y]} */
- public static final Rop AGET_INT =
+ public static final Rop AGET_INT =
new Rop(RegOps.AGET, Type.INT, StdTypeList.INTARR_INT,
Exceptions.LIST_Error_Null_ArrayIndexOutOfBounds,
"aget-int");
/** {@code r: long; x: long[]; y: int :: r = x[y]} */
- public static final Rop AGET_LONG =
+ public static final Rop AGET_LONG =
new Rop(RegOps.AGET, Type.LONG, StdTypeList.LONGARR_INT,
Exceptions.LIST_Error_Null_ArrayIndexOutOfBounds,
"aget-long");
/** {@code r: float; x: float[]; y: int :: r = x[y]} */
- public static final Rop AGET_FLOAT =
+ public static final Rop AGET_FLOAT =
new Rop(RegOps.AGET, Type.FLOAT, StdTypeList.FLOATARR_INT,
Exceptions.LIST_Error_Null_ArrayIndexOutOfBounds,
"aget-float");
/** {@code r: double; x: double[]; y: int :: r = x[y]} */
- public static final Rop AGET_DOUBLE =
+ public static final Rop AGET_DOUBLE =
new Rop(RegOps.AGET, Type.DOUBLE, StdTypeList.DOUBLEARR_INT,
Exceptions.LIST_Error_Null_ArrayIndexOutOfBounds,
"aget-double");
/** {@code r: Object; x: Object[]; y: int :: r = x[y]} */
- public static final Rop AGET_OBJECT =
+ public static final Rop AGET_OBJECT =
new Rop(RegOps.AGET, Type.OBJECT, StdTypeList.OBJECTARR_INT,
Exceptions.LIST_Error_Null_ArrayIndexOutOfBounds,
"aget-object");
/** {@code r: boolean; x: boolean[]; y: int :: r = x[y]} */
- public static final Rop AGET_BOOLEAN =
+ public static final Rop AGET_BOOLEAN =
new Rop(RegOps.AGET, Type.INT, StdTypeList.BOOLEANARR_INT,
Exceptions.LIST_Error_Null_ArrayIndexOutOfBounds,
"aget-boolean");
/** {@code r: byte; x: byte[]; y: int :: r = x[y]} */
- public static final Rop AGET_BYTE =
+ public static final Rop AGET_BYTE =
new Rop(RegOps.AGET, Type.INT, StdTypeList.BYTEARR_INT,
Exceptions.LIST_Error_Null_ArrayIndexOutOfBounds, "aget-byte");
/** {@code r: char; x: char[]; y: int :: r = x[y]} */
- public static final Rop AGET_CHAR =
+ public static final Rop AGET_CHAR =
new Rop(RegOps.AGET, Type.INT, StdTypeList.CHARARR_INT,
Exceptions.LIST_Error_Null_ArrayIndexOutOfBounds, "aget-char");
/** {@code r: short; x: short[]; y: int :: r = x[y]} */
- public static final Rop AGET_SHORT =
+ public static final Rop AGET_SHORT =
new Rop(RegOps.AGET, Type.INT, StdTypeList.SHORTARR_INT,
Exceptions.LIST_Error_Null_ArrayIndexOutOfBounds,
"aget-short");
/** {@code x,z: int; y: int[] :: y[z] = x} */
- public static final Rop APUT_INT =
+ public static final Rop APUT_INT =
new Rop(RegOps.APUT, Type.VOID, StdTypeList.INT_INTARR_INT,
Exceptions.LIST_Error_Null_ArrayIndexOutOfBounds, "aput-int");
/** {@code x: long; y: long[]; z: int :: y[z] = x} */
- public static final Rop APUT_LONG =
+ public static final Rop APUT_LONG =
new Rop(RegOps.APUT, Type.VOID, StdTypeList.LONG_LONGARR_INT,
Exceptions.LIST_Error_Null_ArrayIndexOutOfBounds, "aput-long");
/** {@code x: float; y: float[]; z: int :: y[z] = x} */
- public static final Rop APUT_FLOAT =
+ public static final Rop APUT_FLOAT =
new Rop(RegOps.APUT, Type.VOID, StdTypeList.FLOAT_FLOATARR_INT,
Exceptions.LIST_Error_Null_ArrayIndexOutOfBounds,
"aput-float");
/** {@code x: double; y: double[]; z: int :: y[z] = x} */
- public static final Rop APUT_DOUBLE =
+ public static final Rop APUT_DOUBLE =
new Rop(RegOps.APUT, Type.VOID, StdTypeList.DOUBLE_DOUBLEARR_INT,
Exceptions.LIST_Error_Null_ArrayIndexOutOfBounds,
"aput-double");
/** {@code x: Object; y: Object[]; z: int :: y[z] = x} */
- public static final Rop APUT_OBJECT =
+ public static final Rop APUT_OBJECT =
new Rop(RegOps.APUT, Type.VOID, StdTypeList.OBJECT_OBJECTARR_INT,
Exceptions.LIST_Error_Null_ArrayIndex_ArrayStore,
"aput-object");
/** {@code x: boolean; y: boolean[]; z: int :: y[z] = x} */
- public static final Rop APUT_BOOLEAN =
+ public static final Rop APUT_BOOLEAN =
new Rop(RegOps.APUT, Type.VOID, StdTypeList.INT_BOOLEANARR_INT,
Exceptions.LIST_Error_Null_ArrayIndex_ArrayStore,
"aput-boolean");
/** {@code x: byte; y: byte[]; z: int :: y[z] = x} */
- public static final Rop APUT_BYTE =
+ public static final Rop APUT_BYTE =
new Rop(RegOps.APUT, Type.VOID, StdTypeList.INT_BYTEARR_INT,
Exceptions.LIST_Error_Null_ArrayIndex_ArrayStore, "aput-byte");
/** {@code x: char; y: char[]; z: int :: y[z] = x} */
- public static final Rop APUT_CHAR =
+ public static final Rop APUT_CHAR =
new Rop(RegOps.APUT, Type.VOID, StdTypeList.INT_CHARARR_INT,
Exceptions.LIST_Error_Null_ArrayIndex_ArrayStore, "aput-char");
/** {@code x: short; y: short[]; z: int :: y[z] = x} */
- public static final Rop APUT_SHORT =
+ public static final Rop APUT_SHORT =
new Rop(RegOps.APUT, Type.VOID, StdTypeList.INT_SHORTARR_INT,
Exceptions.LIST_Error_Null_ArrayIndex_ArrayStore,
"aput-short");
/**
* {@code T: any non-array object type :: r =
- * alloc(T)} (allocate heap space for an object)
+ * alloc(T)} (allocate heap space for an object)
*/
public static final Rop NEW_INSTANCE =
new Rop(RegOps.NEW_INSTANCE, Type.OBJECT, StdTypeList.EMPTY,
/**
* {@code T: any non-array object type; x: Object :: (T) x} (can
- * throw {@code ClassCastException})
+ * throw {@code ClassCastException})
*/
- public static final Rop CHECK_CAST =
+ public static final Rop CHECK_CAST =
new Rop(RegOps.CHECK_CAST, Type.VOID, StdTypeList.OBJECT,
Exceptions.LIST_Error_ClassCastException, "check-cast");
* {@code T: any non-array object type; x: Object :: x instanceof
* T}. Note: This is listed as throwing {@code Error}
* explicitly because the op <i>can</i> throw, but there are no
- * other predefined exceptions for it.
+ * other predefined exceptions for it.
*/
public static final Rop INSTANCE_OF =
new Rop(RegOps.INSTANCE_OF, Type.INT, StdTypeList.OBJECT,
/**
* {@code r: int; x: Object; f: instance field spec of
- * type int :: r = x.f}
+ * type int :: r = x.f}
*/
public static final Rop GET_FIELD_INT =
new Rop(RegOps.GET_FIELD, Type.INT, StdTypeList.OBJECT,
/**
* {@code r: long; x: Object; f: instance field spec of
- * type long :: r = x.f}
+ * type long :: r = x.f}
*/
public static final Rop GET_FIELD_LONG =
new Rop(RegOps.GET_FIELD, Type.LONG, StdTypeList.OBJECT,
/**
* {@code r: float; x: Object; f: instance field spec of
- * type float :: r = x.f}
+ * type float :: r = x.f}
*/
public static final Rop GET_FIELD_FLOAT =
new Rop(RegOps.GET_FIELD, Type.FLOAT, StdTypeList.OBJECT,
/**
* {@code r: double; x: Object; f: instance field spec of
- * type double :: r = x.f}
+ * type double :: r = x.f}
*/
public static final Rop GET_FIELD_DOUBLE =
new Rop(RegOps.GET_FIELD, Type.DOUBLE, StdTypeList.OBJECT,
/**
* {@code r: Object; x: Object; f: instance field spec of
- * type Object :: r = x.f}
+ * type Object :: r = x.f}
*/
public static final Rop GET_FIELD_OBJECT =
new Rop(RegOps.GET_FIELD, Type.OBJECT, StdTypeList.OBJECT,
/**
* {@code r: boolean; x: Object; f: instance field spec of
- * type boolean :: r = x.f}
+ * type boolean :: r = x.f}
*/
public static final Rop GET_FIELD_BOOLEAN =
new Rop(RegOps.GET_FIELD, Type.INT, StdTypeList.OBJECT,
/**
* {@code r: byte; x: Object; f: instance field spec of
- * type byte :: r = x.f}
+ * type byte :: r = x.f}
*/
public static final Rop GET_FIELD_BYTE =
new Rop(RegOps.GET_FIELD, Type.INT, StdTypeList.OBJECT,
/**
* {@code r: char; x: Object; f: instance field spec of
- * type char :: r = x.f}
+ * type char :: r = x.f}
*/
public static final Rop GET_FIELD_CHAR =
new Rop(RegOps.GET_FIELD, Type.INT, StdTypeList.OBJECT,
/**
* {@code r: short; x: Object; f: instance field spec of
- * type short :: r = x.f}
+ * type short :: r = x.f}
*/
public static final Rop GET_FIELD_SHORT =
new Rop(RegOps.GET_FIELD, Type.INT, StdTypeList.OBJECT,
/**
* {@code x: int; y: Object; f: instance field spec of type
- * int :: y.f = x}
+ * int :: y.f = x}
*/
public static final Rop PUT_FIELD_INT =
new Rop(RegOps.PUT_FIELD, Type.VOID, StdTypeList.INT_OBJECT,
/**
* {@code x: long; y: Object; f: instance field spec of type
- * long :: y.f = x}
+ * long :: y.f = x}
*/
public static final Rop PUT_FIELD_LONG =
new Rop(RegOps.PUT_FIELD, Type.VOID, StdTypeList.LONG_OBJECT,
/**
* {@code x: float; y: Object; f: instance field spec of type
- * float :: y.f = x}
+ * float :: y.f = x}
*/
public static final Rop PUT_FIELD_FLOAT =
new Rop(RegOps.PUT_FIELD, Type.VOID, StdTypeList.FLOAT_OBJECT,
/**
* {@code x: double; y: Object; f: instance field spec of type
- * double :: y.f = x}
+ * double :: y.f = x}
*/
public static final Rop PUT_FIELD_DOUBLE =
new Rop(RegOps.PUT_FIELD, Type.VOID, StdTypeList.DOUBLE_OBJECT,
/**
* {@code x: Object; y: Object; f: instance field spec of type
- * Object :: y.f = x}
+ * Object :: y.f = x}
*/
public static final Rop PUT_FIELD_OBJECT =
new Rop(RegOps.PUT_FIELD, Type.VOID, StdTypeList.OBJECT_OBJECT,
/**
* {@code x: int; y: Object; f: instance field spec of type
- * boolean :: y.f = x}
+ * boolean :: y.f = x}
*/
public static final Rop PUT_FIELD_BOOLEAN =
new Rop(RegOps.PUT_FIELD, Type.VOID, StdTypeList.INT_OBJECT,
/**
* {@code x: int; y: Object; f: instance field spec of type
- * byte :: y.f = x}
+ * byte :: y.f = x}
*/
public static final Rop PUT_FIELD_BYTE =
new Rop(RegOps.PUT_FIELD, Type.VOID, StdTypeList.INT_OBJECT,
/**
* {@code x: int; y: Object; f: instance field spec of type
- * char :: y.f = x}
+ * char :: y.f = x}
*/
public static final Rop PUT_FIELD_CHAR =
new Rop(RegOps.PUT_FIELD, Type.VOID, StdTypeList.INT_OBJECT,
/**
* {@code x: int; y: Object; f: instance field spec of type
- * short :: y.f = x}
+ * short :: y.f = x}
*/
public static final Rop PUT_FIELD_SHORT =
new Rop(RegOps.PUT_FIELD, Type.VOID, StdTypeList.INT_OBJECT,
* Returns the appropriate rop for the given opcode, destination,
* and sources. The result is typically, but not necessarily, a
* shared instance.
- *
+ *
* <p><b>Note:</b> This method does not do complete error checking on
* its arguments, and so it may return an instance which seemed "right
* enough" even though in actuality the passed arguments don't quite
* match what is returned. TODO: Revisit this issue.</p>
- *
+ *
* @param opcode the opcode
* @param dest {@code non-null;} destination (result) type, or
* {@link Type#VOID} if none
/**
* Returns the appropriate {@code move} rop for the given type. The
* result is a shared instance.
- *
+ *
* @param type {@code non-null;} type of value being moved
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code move-param} rop for the
* given type. The result is a shared instance.
- *
+ *
* @param type {@code non-null;} type of value being moved
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code move-exception} rop for the
* given type. The result may be a shared instance.
- *
+ *
* @param type {@code non-null;} type of the exception
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code const} rop for the given
* type. The result is a shared instance.
- *
+ *
* @param type {@code non-null;} type of the constant
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code if-eq} rop for the given
* sources. The result is a shared instance.
- *
+ *
* @param types {@code non-null;} source types
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code if-ne} rop for the given
* sources. The result is a shared instance.
- *
+ *
* @param types {@code non-null;} source types
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code if-lt} rop for the given
* sources. The result is a shared instance.
- *
+ *
* @param types {@code non-null;} source types
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code if-ge} rop for the given
* sources. The result is a shared instance.
- *
+ *
* @param types {@code non-null;} source types
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code if-gt} rop for the given
* sources. The result is a shared instance.
- *
+ *
* @param types {@code non-null;} source types
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code if-le} rop for the given
* sources. The result is a shared instance.
- *
+ *
* @param types {@code non-null;} source types
* @return {@code non-null;} an appropriate instance
*/
* Helper for all the {@code if*}-related methods, which
* checks types and picks one of the four variants, throwing if
* there's a problem.
- *
+ *
* @param types {@code non-null;} the types
* @param intZ {@code non-null;} the int-to-0 comparison
* @param objZ {@code null-ok;} the object-to-null comparison
/**
* Returns the appropriate {@code add} rop for the given
* types. The result is a shared instance.
- *
+ *
* @param types {@code non-null;} types of the sources
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code sub} rop for the given
* types. The result is a shared instance.
- *
+ *
* @param types {@code non-null;} types of the sources
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code mul} rop for the given
* types. The result is a shared instance.
- *
+ *
* @param types {@code non-null;} types of the sources
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code div} rop for the given
* types. The result is a shared instance.
- *
+ *
* @param types {@code non-null;} types of the sources
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code rem} rop for the given
* types. The result is a shared instance.
- *
+ *
* @param types {@code non-null;} types of the sources
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code and} rop for the given
* types. The result is a shared instance.
- *
+ *
* @param types {@code non-null;} types of the sources
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code or} rop for the given
* types. The result is a shared instance.
- *
+ *
* @param types {@code non-null;} types of the sources
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code xor} rop for the given
* types. The result is a shared instance.
- *
+ *
* @param types {@code non-null;} types of the sources
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code shl} rop for the given
* types. The result is a shared instance.
- *
+ *
* @param types {@code non-null;} types of the sources
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code shr} rop for the given
* types. The result is a shared instance.
- *
+ *
* @param types {@code non-null;} types of the sources
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code ushr} rop for the given
* types. The result is a shared instance.
- *
+ *
* @param types {@code non-null;} types of the sources
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate binary arithmetic rop for the given type
* and arguments. The result is a shared instance.
- *
+ *
* @param types {@code non-null;} sources of the operation
* @param int1 {@code non-null;} the int-to-constant rop
* @param long1 {@code non-null;} the long-to-constant rop
/**
* Returns the appropriate {@code neg} rop for the given type. The
* result is a shared instance.
- *
+ *
* @param type {@code non-null;} type of value being operated on
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code not} rop for the given type. The
* result is a shared instance.
- *
+ *
* @param type {@code non-null;} type of value being operated on
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code cmpl} rop for the given type. The
* result is a shared instance.
- *
+ *
* @param type {@code non-null;} type of value being compared
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code cmpg} rop for the given type. The
* result is a shared instance.
- *
+ *
* @param type {@code non-null;} type of value being compared
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code conv} rop for the given types. The
* result is a shared instance.
- *
+ *
* @param dest {@code non-null;} target value type
* @param source {@code non-null;} source value type
* @return {@code non-null;} an appropriate instance
/**
* Returns the appropriate {@code return} rop for the given type. The
* result is a shared instance.
- *
+ *
* @param type {@code non-null;} type of value being returned
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code aget} rop for the given type. The
* result is a shared instance.
- *
+ *
* @param type {@code non-null;} element type of array being accessed
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code aput} rop for the given type. The
* result is a shared instance.
- *
+ *
* @param type {@code non-null;} element type of array being accessed
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code new-array} rop for the given
* type. The result is a shared instance.
- *
+ *
* @param arrayType {@code non-null;} array type of array being created
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code filled-new-array} rop for the given
* type. The result may be a shared instance.
- *
+ *
* @param arrayType {@code non-null;} type of array being created
* @param count {@code >= 0;} number of elements that the array should have
* @return {@code non-null;} an appropriate instance
/**
* Returns the appropriate {@code get-field} rop for the given
* type. The result is a shared instance.
- *
+ *
* @param type {@code non-null;} type of the field in question
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code put-field} rop for the given
* type. The result is a shared instance.
- *
+ *
* @param type {@code non-null;} type of the field in question
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code get-static} rop for the given
* type. The result is a shared instance.
- *
+ *
* @param type {@code non-null;} type of the field in question
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code put-static} rop for the given
* type. The result is a shared instance.
- *
+ *
* @param type {@code non-null;} type of the field in question
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code invoke-static} rop for the
* given type. The result is typically a newly-allocated instance.
- *
+ *
* @param meth {@code non-null;} descriptor of the method
* @return {@code non-null;} an appropriate instance
*/
/**
* Returns the appropriate {@code invoke-virtual} rop for the
* given type. The result is typically a newly-allocated instance.
- *
+ *
* @param meth {@code non-null;} descriptor of the method, including the
* {@code this} parameter
* @return {@code non-null;} an appropriate instance
/**
* Returns the appropriate {@code invoke-super} rop for the
* given type. The result is typically a newly-allocated instance.
- *
+ *
* @param meth {@code non-null;} descriptor of the method, including the
* {@code this} parameter
* @return {@code non-null;} an appropriate instance
/**
* Returns the appropriate {@code invoke-direct} rop for the
* given type. The result is typically a newly-allocated instance.
- *
+ *
* @param meth {@code non-null;} descriptor of the method, including the
* {@code this} parameter
* @return {@code non-null;} an appropriate instance
/**
* Returns the appropriate {@code invoke-interface} rop for the
* given type. The result is typically a newly-allocated instance.
- *
+ *
* @param meth {@code non-null;} descriptor of the method, including the
* {@code this} parameter
* @return {@code non-null;} an appropriate instance
meth.getParameterFrameTypes(),
StdTypeList.THROWABLE);
}
-
+
/**
* Returns the appropriate {@code mark-local} rop for the given type.
* The result is a shared instance.
/**
* Throws the right exception to complain about a bogus type.
- *
+ *
* @param type {@code non-null;} the bad type
* @return never
*/
/**
* Throws the right exception to complain about a bogus list of types.
- *
+ *
* @param types {@code non-null;} the bad types
* @return never
*/
/**
* {@code >= -1;} the bytecode address, or {@code -1} if that
- * information is unknown
+ * information is unknown
*/
private final int address;
/**
* {@code >= -1;} the line number, or {@code -1} if that
- * information is unknown
+ * information is unknown
*/
private final int line;
/**
* Constructs an instance.
- *
+ *
* @param sourceFile {@code null-ok;} name of the file of origin or
* {@code null} if unknown
* @param address {@code >= -1;} original bytecode address or {@code -1}
/**
* Returns whether the lines match between this instance and
* the one given.
- *
+ *
* @param other {@code non-null;} the instance to compare to
* @return {@code true} iff the lines match
*/
/**
* Returns whether the lines and files match between this instance and
* the one given.
- *
+ *
* @param other {@code non-null;} the instance to compare to
* @return {@code true} iff the lines and files match
*/
/**
* Gets the source file, if known.
- *
+ *
* @return {@code null-ok;} the source file or {@code null} if unknown
*/
public CstUtf8 getSourceFile() {
/**
* Gets the original bytecode address.
- *
+ *
* @return {@code >= -1;} the address or {@code -1} if unknown
*/
public int getAddress() {
/**
* Gets the original line number.
- *
+ *
* @return {@code >= -1;} the original line number or {@code -1} if
* unknown
*/
/**
* Constructs an instance.
- *
+ *
* @param opcode {@code non-null;} the opcode
* @param position {@code non-null;} source position
* @param result {@code null-ok;} spec for the result, if any
/**
* Gets the list of switch cases.
- *
+ *
* @return {@code non-null;} the case list
*/
public IntList getCases() {
/**
* Constructs an instance.
- *
+ *
* @param opcode {@code non-null;} the opcode
* @param position {@code non-null;} source position
* @param sources {@code non-null;} specs for all the sources
/**
* Gets the string form of a register spec list to be used as a catches
* list.
- *
+ *
* @param catches {@code non-null;} the catches list
* @return {@code non-null;} the string form
*/
/**
* Constructs an instance.
- *
+ *
* @param opcode {@code non-null;} the opcode
* @param position {@code non-null;} source position
* @param sources {@code non-null;} specs for all the sources
/**
* {@inheritDoc}
- *
+ *
* This compares in class-major and value-minor order.
*/
public final int compareTo(Constant other) {
/**
* Compare the values of this and another instance, which are guaranteed
* to be of the same class. Subclasses must implement this.
- *
+ *
* @param other {@code non-null;} the instance to compare to
* @return {@code -1}, {@code 0}, or {@code 1}, as usual
* for a comparison
public final class CstAnnotation extends Constant {
/** {@code non-null;} the actual annotation */
private final Annotation annotation;
-
+
/**
* Constructs an instance.
*
/**
* Get the underlying annotation.
- *
+ *
* @return {@code non-null;} the annotation
*/
public Annotation getAnnotation() {
public final class CstArray extends Constant {
/** {@code non-null;} the actual list of contents */
private final List list;
-
+
/**
* Constructs an instance.
*
/**
* Get the underlying list.
- *
+ *
* @return {@code non-null;} the list
*/
public List getList() {
/**
* Constructs an instance. All indices initially contain
* {@code null}.
- *
+ *
* @param size the size of the list
*/
public List(int size) {
* Gets the element at the given index. It is an error to call
* this with the index for an element which was never set; if you
* do that, this will throw {@code NullPointerException}.
- *
+ *
* @param n {@code >= 0, < size();} which index
* @return {@code non-null;} element at that index
*/
/**
* Sets the element at the given index.
- *
+ *
* @param n {@code >= 0, < size();} which index
* @param a {@code null-ok;} the element to set at {@code n}
*/
/**
* {@inheritDoc}
- *
+ *
* In this case, this method returns the <i>return type</i> of this method.
*
* @return {@code non-null;} the method's return type
* {@code getPrototype().getParameterTypes().getWordCount()},
* plus {@code 1} if the method is to be treated as an
* instance method.
- *
+ *
* @param isStatic whether the method should be considered static
* @return {@code >= 0;} the argument word count
*/
/**
* Makes an instance for the given value. This will return an
* already-allocated instance.
- *
+ *
* @param value the {@code boolean} value
* @return {@code non-null;} the appropriate instance
*/
/**
* Makes an instance for the given {@code int} value. This
* will return an already-allocated instance.
- *
+ *
* @param value must be either {@code 0} or {@code 1}
* @return {@code non-null;} the appropriate instance
*/
/**
* Constructs an instance. This constructor is private; use {@link #make}.
- *
+ *
* @param value the {@code boolean} value
*/
private CstBoolean(boolean value) {
/**
* Gets the {@code boolean} value.
- *
+ *
* @return the value
*/
public boolean getValue() {
extends CstLiteral32 {
/** {@code non-null;} the value {@code 0} as an instance of this class */
public static final CstByte VALUE_0 = make((byte) 0);
-
+
/**
* Makes an instance for the given value. This may (but does not
* necessarily) return an already-allocated instance.
- *
+ *
* @param value the {@code byte} value
*/
public static CstByte make(byte value) {
* Makes an instance for the given {@code int} value. This
* may (but does not necessarily) return an already-allocated
* instance.
- *
+ *
* @param value the value, which must be in range for a {@code byte}
* @return {@code non-null;} the appropriate instance
*/
byte cast = (byte) value;
if (cast != value) {
- throw new IllegalArgumentException("bogus byte value: " +
+ throw new IllegalArgumentException("bogus byte value: " +
value);
}
/**
* Constructs an instance. This constructor is private; use {@link #make}.
- *
+ *
* @param value the {@code byte} value
*/
private CstByte(byte value) {
/**
* Gets the {@code byte} value.
- *
+ *
* @return the value
*/
public byte getValue() {
/**
* Makes an instance for the given value. This may (but does not
* necessarily) return an already-allocated instance.
- *
+ *
* @param value the {@code char} value
*/
public static CstChar make(char value) {
* Makes an instance for the given {@code int} value. This
* may (but does not necessarily) return an already-allocated
* instance.
- *
+ *
* @param value the value, which must be in range for a {@code char}
* @return {@code non-null;} the appropriate instance
*/
char cast = (char) value;
if (cast != value) {
- throw new IllegalArgumentException("bogus char value: " +
+ throw new IllegalArgumentException("bogus char value: " +
value);
}
/**
* Constructs an instance. This constructor is private; use {@link #make}.
- *
+ *
* @param value the {@code char} value
*/
private CstChar(char value) {
/**
* Gets the {@code char} value.
- *
+ *
* @return the value
*/
public char getValue() {
/**
* Makes an instance for the given value. This may (but does not
* necessarily) return an already-allocated instance.
- *
+ *
* @param bits the {@code double} value as {@code long} bits
*/
public static CstDouble make(long bits) {
/**
* Constructs an instance. This constructor is private; use {@link #make}.
- *
+ *
* @param bits the {@code double} value as {@code long} bits
*/
private CstDouble(long bits) {
/**
* Gets the {@code double} value.
- *
+ *
* @return the value
*/
public double getValue() {
public final class CstEnumRef extends CstMemberRef {
/** {@code null-ok;} the corresponding field ref, lazily initialized */
private CstFieldRef fieldRef;
-
+
/**
* Constructs an instance.
*
}
/**
- * {@inheritDoc}
- *
+ * {@inheritDoc}
+ *
* <b>Note:</b> This returns the enumerated type.
*/
public Type getType() {
/**
* Get a {@link CstFieldRef} that corresponds with this instance.
- *
+ *
* @return {@code non-null;} the corresponding field reference
*/
public CstFieldRef getFieldRef() {
* primitive type. For example, if given {@link Type#INT}, this
* method returns an instance corresponding to the field
* {@code java.lang.Integer.TYPE}.
- *
+ *
* @param primitiveType {@code non-null;} the primitive type
* @return {@code non-null;} the corresponding static field
*/
/**
* Constructs an instance.
- *
+ *
* @param definingClass {@code non-null;} the type of the defining class
* @param nat {@code non-null;} the name-and-type
*/
/**
* Returns the type of this field.
- *
+ *
* @return {@code non-null;} the field's type
*/
public Type getType() {
/**
* Makes an instance for the given value. This may (but does not
* necessarily) return an already-allocated instance.
- *
+ *
* @param bits the {@code float} value as {@code int} bits
*/
public static CstFloat make(int bits) {
/**
* Constructs an instance. This constructor is private; use {@link #make}.
- *
+ *
* @param bits the {@code float} value as {@code int} bits
*/
private CstFloat(int bits) {
/**
* Gets the {@code float} value.
- *
+ *
* @return the value
*/
public float getValue() {
/**
* Makes an instance for the given value. This may (but does not
* necessarily) return an already-allocated instance.
- *
+ *
* @param value the {@code int} value
* @return {@code non-null;} the appropriate instance
*/
/**
* Constructs an instance. This constructor is private; use {@link #make}.
- *
+ *
* @param value the {@code int} value
*/
private CstInteger(int value) {
/**
* Gets the {@code int} value.
- *
+ *
* @return the value
*/
public int getValue() {
extends CstBaseMethodRef {
/**
* {@code null-ok;} normal {@link CstMethodRef} that corresponds to this
- * instance, if calculated
+ * instance, if calculated
*/
private CstMethodRef methodRef;
/**
* Constructs an instance.
- *
+ *
* @param definingClass {@code non-null;} the type of the defining class
* @param nat {@code non-null;} the name-and-type
*/
/**
* Gets a normal (non-interface) {@link CstMethodRef} that corresponds to
* this instance.
- *
+ *
* @return {@code non-null;} an appropriate instance
*/
public CstMethodRef toMethodRef() {
/**
* {@inheritDoc}
- *
+ *
* As "literal bits," a known-null is always represented as the
* number zero.
*/
/**
* {@inheritDoc}
- *
+ *
* As "literal bits," a known-null is always represented as the
* number zero.
*/
/**
* Constructs an instance.
- *
+ *
* @param bits the value as {@code int} bits
*/
/*package*/ CstLiteral32(int bits) {
/**
* Constructs an instance.
- *
+ *
* @param bits the value as {@code long} bits
*/
/*package*/ CstLiteral64(long bits) {
* Gets the value as {@code long} bits. If this instance contains
* fewer bits than fit in a {@code long}, then the result of this
* method is the sign extension of the value.
- *
+ *
* @return the bits
*/
public abstract long getLongBits();
if (! fitsInInt()) {
return false;
}
-
+
int bits = getIntBits();
return (short) bits == bits;
}
/**
* Makes an instance for the given value. This may (but does not
* necessarily) return an already-allocated instance.
- *
+ *
* @param value the {@code long} value
*/
public static CstLong make(long value) {
/**
* Constructs an instance. This constructor is private; use {@link #make}.
- *
+ *
* @param value the {@code long} value
*/
private CstLong(long value) {
/**
* Gets the {@code long} value.
- *
+ *
* @return the value
*/
public long getValue() {
/**
* Constructs an instance.
- *
+ *
* @param definingClass {@code non-null;} the type of the defining class
* @param nat {@code non-null;} the name-and-type
*/
}
CstMemberRef otherRef = (CstMemberRef) other;
- return definingClass.equals(otherRef.definingClass) &&
+ return definingClass.equals(otherRef.definingClass) &&
nat.equals(otherRef.nat);
}
/**
* Gets the type of the defining class.
- *
+ *
* @return {@code non-null;} the type of defining class
*/
public final CstType getDefiningClass() {
/**
* Gets the defining name-and-type.
- *
+ *
* @return {@code non-null;} the name-and-type
*/
public final CstNat getNat() {
extends CstBaseMethodRef {
/**
* Constructs an instance.
- *
+ *
* @param definingClass {@code non-null;} the type of the defining class
* @param nat {@code non-null;} the name-and-type
*/
/**
* {@code non-null;} the instance for name {@code TYPE} and descriptor
* {@code java.lang.Class}, which is useful when dealing with
- * wrapped primitives
+ * wrapped primitives
*/
public static final CstNat PRIMITIVE_TYPE_NAT =
new CstNat(new CstUtf8("TYPE"),
/**
* Constructs an instance.
- *
+ *
* @param name {@code non-null;} the name
* @param descriptor {@code non-null;} the descriptor
*/
}
CstNat otherNat = (CstNat) other;
- return name.equals(otherNat.name) &&
+ return name.equals(otherNat.name) &&
descriptor.equals(otherNat.descriptor);
}
/**
* Gets the name.
- *
+ *
* @return {@code non-null;} the name
*/
public CstUtf8 getName() {
/**
* Gets the descriptor.
- *
+ *
* @return {@code non-null;} the descriptor
*/
public CstUtf8 getDescriptor() {
/**
* Returns an unadorned but human-readable version of the name-and-type
* value.
- *
+ *
* @return {@code non-null;} the human form
*/
public String toHuman() {
* Gets the field type corresponding to this instance's descriptor.
* This method is only valid to call if the descriptor in fact describes
* a field (and not a method).
- *
+ *
* @return {@code non-null;} the field type
*/
public Type getFieldType() {
* Gets whether this instance has the name of a standard instance
* initialization method. This is just a convenient shorthand for
* {@code getName().getString().equals("<init>")}.
- *
+ *
* @return {@code true} iff this is a reference to an
* instance initialization method
*/
* Gets whether this instance has the name of a standard class
* initialization method. This is just a convenient shorthand for
* {@code getName().getString().equals("<clinit>")}.
- *
+ *
* @return {@code true} iff this is a reference to an
* instance initialization method
*/
/**
* Makes an instance for the given value. This may (but does not
* necessarily) return an already-allocated instance.
- *
+ *
* @param value the {@code short} value
* @return {@code non-null;} the appropriate instance
*/
* Makes an instance for the given {@code int} value. This
* may (but does not necessarily) return an already-allocated
* instance.
- *
+ *
* @param value the value, which must be in range for a {@code short}
* @return {@code non-null;} the appropriate instance
*/
short cast = (short) value;
if (cast != value) {
- throw new IllegalArgumentException("bogus short value: " +
+ throw new IllegalArgumentException("bogus short value: " +
value);
}
/**
* Constructs an instance. This constructor is private; use {@link #make}.
- *
+ *
* @param value the {@code short} value
*/
private CstShort(short value) {
/**
* Gets the {@code short} value.
- *
+ *
* @return the value
*/
public short getValue() {
/**
* Constructs an instance.
- *
+ *
* @param string {@code non-null;} the string value
*/
public CstString(CstUtf8 string) {
/**
* Constructs an instance.
- *
+ *
* @param string {@code non-null;} the string value
*/
public CstString(String string) {
/**
* Gets the string value.
- *
+ *
* @return {@code non-null;} the string value
*/
public CstUtf8 getString() {
* class corresponding to a given primitive type. For example, if
* given {@link Type#INT}, this method returns the class reference
* {@code java.lang.Integer}.
- *
+ *
* @param primitiveType {@code non-null;} the primitive type
* @return {@code non-null;} the corresponding wrapper class
*/
/**
* Returns an interned instance of this class for the given type.
- *
+ *
* @param type {@code non-null;} the underlying type
* @return {@code non-null;} an appropriately-constructed instance
*/
/**
* Constructs an instance.
- *
+ *
* @param type {@code non-null;} the underlying type
*/
public CstType(Type type) {
* Gets the underlying type (as opposed to the type corresponding
* to this instance as a constant, which is always
* {@code Class}).
- *
+ *
* @return {@code non-null;} the type corresponding to the name
*/
public Type getClassType() {
/**
* Gets the type descriptor for this instance.
- *
+ *
* @return {@code non-null;} the descriptor
*/
public CstUtf8 getDescriptor() {
if (descriptor == null) {
descriptor = new CstUtf8(type.getDescriptor());
}
-
+
return descriptor;
}
}
* Constants of type {@code CONSTANT_Utf8_info}.
*/
public final class CstUtf8 extends Constant {
- /**
+ /**
* {@code non-null;} instance representing {@code ""}, that is, the
- * empty string
+ * empty string
*/
public static final CstUtf8 EMPTY_STRING = new CstUtf8("");
-
+
/** {@code non-null;} the UTF-8 value as a string */
private final String string;
* Converts a string into its Java-style UTF-8 form. Java-style UTF-8
* differs from normal UTF-8 in the handling of character '\0' and
* surrogate pairs.
- *
+ *
* @param string {@code non-null;} the string to convert
* @return {@code non-null;} the UTF-8 bytes for it
*/
/**
* Converts an array of UTF-8 bytes into a string.
- *
+ *
* @param bytes {@code non-null;} the bytes to convert
* @return {@code non-null;} the converted string
*/
/**
* Helper for {@link #utf8BytesToString}, which throws the right
* exception for a bogus utf-8 byte.
- *
+ *
* @param value the byte value
* @param offset the file offset
* @return never
/**
* Constructs an instance from a {@code String}.
- *
+ *
* @param string {@code non-null;} the UTF-8 value as a string
*/
public CstUtf8(String string) {
/**
* Constructs an instance from some UTF-8 bytes.
- *
+ *
* @param bytes {@code non-null;} array of the UTF-8 bytes
*/
public CstUtf8(ByteArray bytes) {
*/
char nextChar =
(i < (len - 1)) ? string.charAt(i + 1) : 0;
- boolean displayZero =
+ boolean displayZero =
(nextChar >= '0') && (nextChar <= '7');
sb.append('\\');
for (int shift = 6; shift >= 0; shift -= 3) {
/**
* Gets the value as a human-oriented string, surrounded by double
* quotes.
- *
+ *
* @return {@code non-null;} the quoted string
*/
public String toQuoted() {
* Gets the value as a human-oriented string, surrounded by double
* quotes, but ellipsizes the result if it is longer than the given
* maximum length
- *
+ *
* @param maxLength {@code >= 5;} the maximum length of the string to return
* @return {@code non-null;} the quoted string
*/
/**
* Gets the UTF-8 value as a string.
* The returned string is always already interned.
- *
+ *
* @return {@code non-null;} the UTF-8 value as a string
*/
public String getString() {
/**
* Gets the UTF-8 value as UTF-8 encoded bytes.
- *
+ *
* @return {@code non-null;} an array of the UTF-8 bytes
*/
public ByteArray getBytes() {
/**
* Gets the size of this instance as UTF-8 code points. That is,
* get the number of bytes in the UTF-8 encoding of this instance.
- *
+ *
* @return {@code >= 0;} the UTF-8 size
*/
public int getUtf8Size() {
* get the number of 16-bit chars in the UTF-16 encoding of this
* instance. This is the same as the {@code length} of the
* Java {@code String} representation of this instance.
- *
+ *
* @return {@code >= 0;} the UTF-16 size
*/
public int getUtf16Size() {
return string.length();
- }
+ }
}
/**
* Constructs an instance. All indices initially contain {@code null}.
- *
+ *
* @param size the size of the pool; this corresponds to the
* class file field {@code constant_pool_count}, and is in fact
* always at least one more than the actual size of the constant pool,
/**
* Sets the entry at the given index.
- *
+ *
* @param n {@code >= 1, < size();} which entry
* @param cst {@code null-ok;} the constant to store
*/
/**
* Throws the right exception for an invalid cpi.
- *
+ *
* @param idx the bad cpi
* @return never
* @throws ExceptionWithContext always thrown
extends Constant implements TypeBearer {
/**
* {@inheritDoc}
- *
+ *
* This implentation always returns {@code this}.
*/
public final TypeBearer getFrameType() {
private Zeroes() {
// This space intentionally left blank.
}
-
+
/**
* Gets the "zero" (or {@code null}) value for the given type.
- *
+ *
* @param type {@code non-null;} the type in question
* @return {@code non-null;} its "zero" value
*/
private StdTypeList parameterFrameTypes;
/**
- * Returns the unique instance corresponding to the
+ * Returns the unique instance corresponding to the
* given method descriptor. See vmspec-2 sec4.3.3 for details on the
* field descriptor syntax.
- *
+ *
* @param descriptor {@code non-null;} the descriptor
* @return {@code non-null;} the corresponding instance
* @throws IllegalArgumentException thrown if the descriptor has
* populate with parsed parameter types, and which also ensures
* that there is a '(' at the start of the descriptor and a
* single ')' somewhere before the end.
- *
+ *
* @param descriptor {@code non-null;} the descriptor string
* @return {@code non-null;} array large enough to hold all parsed parameter
* types, but which is likely actually larger than needed
* on the given definer, name, and flags. For example, an init
* method has an uninitialized object of type {@code definer}
* as its first argument.
- *
+ *
* @param descriptor {@code non-null;} the descriptor string
* @param definer {@code non-null;} class the method is defined on
* @param isStatic whether this is a static method
/**
* Interns an instance which consists of the given number of
* {@code int}s along with the given return type
- *
+ *
* @param returnType {@code non-null;} the return type
* @param count {@code > 0;} the number of elements in the prototype
* @return {@code non-null;} the interned instance
/**
* Constructs an instance. This is a private constructor; use one
* of the public static methods to get instances.
- *
+ *
* @param descriptor {@code non-null;} the descriptor string
*/
private Prototype(String descriptor, Type returnType,
if (this == other) {
return 0;
}
-
+
/*
* The return type is the major order, and then args in order,
* and then the shorter list comes first (similar to string
/**
* Gets the descriptor string.
- *
+ *
* @return {@code non-null;} the descriptor
*/
public String getDescriptor() {
/**
* Gets the return type.
- *
+ *
* @return {@code non-null;} the return type
*/
public Type getReturnType() {
/**
* Gets the list of parameter types.
- *
+ *
* @return {@code non-null;} the list of parameter types
*/
public StdTypeList getParameterTypes() {
* types. The difference between the two lists (if any) is that all
* "intlike" types (see {@link Type#isIntlike}) are replaced by
* {@link Type#INT}.
- *
+ *
* @return {@code non-null;} the list of parameter frame types
*/
public StdTypeList getParameterFrameTypes() {
* Returns a new interned instance, which is the same as this instance,
* except that it has an additional parameter prepended to the original's
* argument list.
- *
+ *
* @param param {@code non-null;} the new first parameter
* @return {@code non-null;} an appropriately-constructed instance
*/
* Puts the given instance in the intern table if it's not already
* there. If a conflicting value is already in the table, then leave it.
* Return the interned value.
- *
+ *
* @param desc {@code non-null;} instance to make interned
* @return {@code non-null;} the actual interned object
*/
/**
* Makes a single-element instance.
- *
+ *
* @param type {@code non-null;} the element
* @return {@code non-null;} an appropriately-constructed instance
*/
/**
* Makes a two-element instance.
- *
+ *
* @param type0 {@code non-null;} the first element
* @param type1 {@code non-null;} the second element
* @return {@code non-null;} an appropriately-constructed instance
/**
* Makes a three-element instance.
- *
+ *
* @param type0 {@code non-null;} the first element
* @param type1 {@code non-null;} the second element
* @param type2 {@code non-null;} the third element
/**
* Makes a four-element instance.
- *
+ *
* @param type0 {@code non-null;} the first element
* @param type1 {@code non-null;} the second element
* @param type2 {@code non-null;} the third element
* Returns the given list as a comma-separated list of human forms. This
* is a static method so as to work on arbitrary {@link TypeList}
* instances.
- *
+ *
* @param list {@code non-null;} the list to convert
* @return {@code non-null;} the human form
*/
if (size == 0) {
return "<empty>";
}
-
+
StringBuffer sb = new StringBuffer(100);
for (int i = 0; i < size; i++) {
* Returns a hashcode of the contents of the given list. This
* is a static method so as to work on arbitrary {@link TypeList}
* instances.
- *
+ *
* @param list {@code non-null;} the list to inspect
* @return {@code non-null;} the hash code
*/
return hash;
}
-
+
/**
* Compares the contents of the given two instances for equality. This
* is a static method so as to work on arbitrary {@link TypeList}
* instances.
- *
+ *
* @param list1 {@code non-null;} one list to compare
* @param list2 {@code non-null;} another list to compare
* @return whether the two lists contain corresponding equal elements
* Compares the contents of the given two instances for ordering. This
* is a static method so as to work on arbitrary {@link TypeList}
* instances.
- *
+ *
* @param list1 {@code non-null;} one list to compare
* @param list2 {@code non-null;} another list to compare
* @return the order of the two lists
return 1;
}
}
-
+
/**
* Constructs an instance. All indices initially contain {@code null}.
- *
+ *
* @param size the size of the list
*/
public StdTypeList(int size) {
* Gets the indicated element. It is an error to call this with the
* index for an element which was never set; if you do that, this
* will throw {@code NullPointerException}.
- *
+ *
* @param n {@code >= 0, < size();} which element
* @return {@code non-null;} the indicated element
*/
/**
* Sets the type at the given index.
- *
+ *
* @param n {@code >= 0, < size();} which element
* @param type {@code non-null;} the type to store
*/
* Returns a new instance, which is the same as this instance,
* except that it has an additional type prepended to the
* original.
- *
+ *
* @param type {@code non-null;} the new first element
* @return {@code non-null;} an appropriately-constructed instance
*/
*/
public final class Type implements TypeBearer, Comparable<Type> {
/** {@code non-null;} intern table mapping string descriptors to instances */
- private static final HashMap<String, Type> internTable =
+ private static final HashMap<String, Type> internTable =
new HashMap<String, Type>(500);
/** basic type constant for {@code void} */
/**
* {@code non-null;} instance representing {@code java.lang.Boolean}; the
* suffix on the name helps disambiguate this from the instance
- * representing a primitive type
+ * representing a primitive type
*/
public static final Type BOOLEAN_CLASS = intern("Ljava/lang/Boolean;");
/**
* {@code non-null;} instance representing {@code java.lang.Byte}; the
* suffix on the name helps disambiguate this from the instance
- * representing a primitive type
+ * representing a primitive type
*/
public static final Type BYTE_CLASS = intern("Ljava/lang/Byte;");
/**
* {@code non-null;} instance representing {@code java.lang.Character}; the
* suffix on the name helps disambiguate this from the instance
- * representing a primitive type
+ * representing a primitive type
*/
public static final Type CHARACTER_CLASS = intern("Ljava/lang/Character;");
/**
* {@code non-null;} instance representing {@code java.lang.Double}; the
* suffix on the name helps disambiguate this from the instance
- * representing a primitive type
+ * representing a primitive type
*/
public static final Type DOUBLE_CLASS = intern("Ljava/lang/Double;");
/**
* {@code non-null;} instance representing {@code java.lang.Float}; the
* suffix on the name helps disambiguate this from the instance
- * representing a primitive type
+ * representing a primitive type
*/
public static final Type FLOAT_CLASS = intern("Ljava/lang/Float;");
/**
* {@code non-null;} instance representing {@code java.lang.Integer}; the
* suffix on the name helps disambiguate this from the instance
- * representing a primitive type
+ * representing a primitive type
*/
public static final Type INTEGER_CLASS = intern("Ljava/lang/Integer;");
/**
* {@code non-null;} instance representing {@code java.lang.Long}; the
* suffix on the name helps disambiguate this from the instance
- * representing a primitive type
+ * representing a primitive type
*/
public static final Type LONG_CLASS = intern("Ljava/lang/Long;");
/**
* {@code non-null;} instance representing {@code java.lang.Short}; the
* suffix on the name helps disambiguate this from the instance
- * representing a primitive type
+ * representing a primitive type
*/
public static final Type SHORT_CLASS = intern("Ljava/lang/Short;");
/**
* {@code non-null;} instance representing {@code java.lang.Void}; the
* suffix on the name helps disambiguate this from the instance
- * representing a primitive type
+ * representing a primitive type
*/
public static final Type VOID_CLASS = intern("Ljava/lang/Void;");
/**
* basic type corresponding to this type; one of the
- * {@code BT_*} constants
+ * {@code BT_*} constants
*/
private final int basicType;
* {@code >= -1;} for an uninitialized type, bytecode index that this
* instance was allocated at; {@code Integer.MAX_VALUE} if it
* was an incoming uninitialized instance; {@code -1} if this
- * is an <i>inititialized</i> instance
+ * is an <i>inititialized</i> instance
*/
private final int newAt;
/**
* {@code null-ok;} the internal-form class name corresponding to this type, if
* calculated; only valid if {@code this} is a reference type and
- * additionally not a return address
+ * additionally not a return address
*/
private String className;
/**
* {@code null-ok;} the type corresponding to an array of this type, if
- * calculated
+ * calculated
*/
private Type arrayType;
/**
* {@code null-ok;} the type corresponding to elements of this type, if
- * calculated; only valid if {@code this} is an array type
+ * calculated; only valid if {@code this} is an array type
*/
private Type componentType;
/**
* {@code null-ok;} the type corresponding to the initialized version of
- * this type, if this instance is in fact an uninitialized type
+ * this type, if this instance is in fact an uninitialized type
*/
private Type initializedType;
* field descriptor syntax. This method does <i>not</i> allow
* {@code "V"} (that is, type {@code void}) as a valid
* descriptor.
- *
+ *
* @param descriptor {@code non-null;} the descriptor
* @return {@code non-null;} the corresponding instance
* @throws IllegalArgumentException thrown if the descriptor has
char c = descriptor.charAt(i);
switch (c) {
case '[':
- case ';':
- case '.':
+ case ';':
+ case '.':
case '(':
case ')': {
throw new IllegalArgumentException("bad descriptor");
* given descriptor, allowing {@code "V"} to return the type
* for {@code void}. Other than that one caveat, this method
* is identical to {@link #intern}.
- *
+ *
* @param descriptor {@code non-null;} the descriptor
* @return {@code non-null;} the corresponding instance
* @throws IllegalArgumentException thrown if the descriptor has
* calling {@code intern(name)} if {@code name} begins
* with {@code "["} and calling {@code intern("L" + name + ";")}
* in all other cases.
- *
+ *
* @param name {@code non-null;} the name of the class whose type is desired
* @return {@code non-null;} the corresponding type
* @throws IllegalArgumentException thrown if the name has
* Constructs an instance corresponding to an "uninitialized type."
* This is a private constructor; use one of the public static
* methods to get instances.
- *
+ *
* @param descriptor {@code non-null;} the field descriptor for the type
* @param basicType basic type corresponding to this type; one of the
* {@code BT_*} constants
* Constructs an instance corresponding to an "initialized type."
* This is a private constructor; use one of the public static
* methods to get instances.
- *
+ *
* @param descriptor {@code non-null;} the field descriptor for the type
* @param basicType basic type corresponding to this type; one of the
* {@code BT_*} constants
/**
* Gets the descriptor.
- *
+ *
* @return {@code non-null;} the descriptor
*/
public String getDescriptor() {
* form. This method is only valid if this instance is for a
* normal reference type (that is, a reference type and
* additionally not a return address).
- *
+ *
* @return {@code non-null;} the internal-form class name
*/
public String getClassName() {
/**
* Gets the category. Most instances are category 1. {@code long}
* and {@code double} are the only category 2 types.
- *
+ *
* @see #isCategory1
* @see #isCategory2
* @return the category
/**
* Returns whether or not this is a category 1 type.
- *
+ *
* @see #getCategory
* @see #isCategory2
* @return whether or not this is a category 1 type
/**
* Returns whether or not this is a category 2 type.
- *
+ *
* @see #getCategory
* @see #isCategory1
* @return whether or not this is a category 2 type
* Gets whether this type is "intlike." An intlike type is one which, when
* placed on a stack or in a local, is automatically converted to an
* {@code int}.
- *
+ *
* @return whether this type is "intlike"
*/
public boolean isIntlike() {
/**
* Gets whether this type is a primitive type. All types are either
* primitive or reference types.
- *
+ *
* @return whether this type is primitive
*/
public boolean isPrimitive() {
* reference type is a reference type that is not a return
* address. This method is just convenient shorthand for
* {@code getBasicType() == Type.BT_OBJECT}.
- *
+ *
* @return whether this type is a normal reference type
*/
public boolean isReference() {
* Gets whether this type is an array type. If this method returns
* {@code true}, then it is safe to use {@link #getComponentType}
* to determine the component type.
- *
+ *
* @return whether this type is an array type
*/
public boolean isArray() {
/**
* Gets whether this type is an array type or is a known-null, and
* hence is compatible with array types.
- *
+ *
* @return whether this type is an array type
*/
public boolean isArrayOrKnownNull() {
* uninitialized instance is what one gets back from the {@code new}
* opcode, and remains uninitialized until a valid constructor is
* invoked on it.
- *
+ *
* @return whether this type is "uninitialized"
*/
public boolean isUninitialized() {
* type is an uninitialized incoming parameter (i.e., the
* {@code this} of an {@code <init>} method) or
* {@code -1} if this type is in fact <i>initialized</i>.
- *
+ *
* @return {@code >= -1;} the allocation bytecode index
*/
public int getNewAt() {
/**
* Gets the initialized type corresponding to this instance, but only
* if this instance is in fact an uninitialized object type.
- *
+ *
* @return {@code non-null;} the initialized type
*/
public Type getInitializedType() {
/**
* Gets the type corresponding to an array of this type.
- *
+ *
* @return {@code non-null;} the array type
*/
public Type getArrayType() {
/**
* Gets the component type of this type. This method is only valid on
* array types.
- *
+ *
* @return {@code non-null;} the component type
*/
public Type getComponentType() {
* Returns a new interned instance which is identical to this one, except
* it is indicated as uninitialized and allocated at the given bytecode
* index. This instance must be an initialized object type.
- *
+ *
* @param newAt {@code >= 0;} the allocation bytecode index
* @return {@code non-null;} an appropriately-constructed instance
*/
* Puts the given instance in the intern table if it's not already
* there. If a conflicting value is already in the table, then leave it.
* Return the interned value.
- *
+ *
* @param type {@code non-null;} instance to make interned
* @return {@code non-null;} the actual interned object
*/
* is the same as calling {@code getFrameType()} unless this
* instance is an int-like type, in which case this method returns
* {@code BT_INT}.
- *
+ *
* @see #getBasicType
* @see #getFrameType
- *
+ *
* @return the basic frame type; one of the {@code BT_*} constants
* defined by {@link Type}
*/
/**
* Returns whether this instance represents a constant value.
- *
+ *
* @return {@code true} if this instance represents a constant value
* and {@code false} if not
*/
* {@code TypeList} interface itself doesn't provide any
* means of mutation, but that doesn't mean that there isn't an
* extra-interface way of mutating an instance.
- *
+ *
* @return {@code true} if this instance is mutable or
* {@code false} if it is immutable
*/
public boolean isMutable();
-
+
/**
* Gets the size of this list.
*
* Gets the number of 32-bit words required to hold instances of
* all the elements of this list. This is a sum of the widths (categories)
* of all the elements.
- *
+ *
* @return {@code >= 0;} the required number of words
*/
public int getWordCount();
* Returns a new instance which is identical to this one, except that
* the given item is appended to the end and it is guaranteed to be
* immutable.
- *
+ *
* @param type {@code non-null;} item to append
* @return {@code non-null;} an appropriately-constructed instance
*/
/**
* Creates a new OneToOneRegisterMapper.
- *
+ *
* @param countOldRegisters the number of registers in the old name space
*/
public BasicRegisterMapper(int countOldRegisters) {
/**
* Constructs an instance.
- *
+ *
* @param ssaMethod {@code non-null;} method to process
*/
private ConstCollector(SsaMethod ssaMethod) {
ArrayList<TypedConstant> constantList
= getConstsSortedByCountUse();
-
+
int toCollect = Math.min(constantList.size(), MAX_COLLECTED_CONSTANTS);
SsaBasicBlock start = ssaMeth.getEntryBlock();
SsaBasicBlock resultBlock
= constBlock.insertNewSuccessor(successorBlock);
- PlainInsn insn
+ PlainInsn insn
= new PlainInsn(
Rops.opMoveResultPseudo(result.getTypeBearer()),
SourcePosition.NO_INFO,
}
/*
* We can't move any throwable const whose throw will be
- * caught, so don't count them.
+ * caught, so don't count them.
*/
if (insn.getBlock().getSuccessors().cardinality() > 1) {
continue;
* variable, then insert a mark-local for {@code newReg} just below
* it. We expect the definition of {@code origReg} to ultimately
* be removed by the dead code eliminator
- *
+ *
* @param origReg {@code non-null;} original register
* @param newReg {@code non-null;} new register that will replace
* {@code origReg}
if (ssaMeth.isRegALocal(origReg)) {
if (!COLLECT_ONE_LOCAL) {
- continue;
+ continue;
} else {
/*
* TODO: If the same local gets the same cst
/**
* Process a method with the dead-code remver
- *
+ *
* @param ssaMethod method to process
*/
public static void process(SsaMethod ssaMethod) {
/**
* Constructs an instance.
- *
+ *
* @param ssaMethod method to process
*/
private DeadCodeRemover(SsaMethod ssaMethod) {
/**
* Returns true if the only uses of this register form a circle of
* operations with no side effects.
- *
+ *
* @param regV register to examine
* @param set a set of registers that we've already determined
* are only used as sources in operations with no side effect or null
return true;
}
- return insn.hasSideEffect();
+ return insn.hasSideEffect();
}
/**
private final SsaMethod meth;
private final ArrayList<SsaBasicBlock> nodes;
-
+
private final DomInfo[] domInfos;
/**
}
/**
- * Constructs instance. Call {@link DomFront#run} to process.
- *
+ * Constructs instance. Call {@link DomFront#run} to process.
+ *
* @param meth {@code non-null;} method to process
*/
public DomFront(SsaMethod meth) {
}
buildDomTree();
-
+
if (DEBUG) {
debugPrintDomChildren();
}
/**
* Constructs an instance.
- *
+ *
* @param meth {@code non-null;} method to process
* @param domInfos {@code non-null;} the raw dominator info
* @param postdom true for postdom information, false for normal dom info
/**
* Constructs a fully-initialized instance. (This method exists so as
* to avoid calling a large amount of code in the constructor.)
- *
+ *
* @param meth {@code non-null;} method to process
* @param domInfos {@code non-null;} the raw dominator info
* @param postdom true for postdom information, false for normal dom info
/**
* Performs path compress on the DFS info.
- *
+ *
* @param in Basic block whose DFS info we are path compressing.
*/
private void compress(SsaBasicBlock in) {
ArrayList<SsaBasicBlock> worklist = new ArrayList<SsaBasicBlock>();
HashSet<SsaBasicBlock> visited = new HashSet<SsaBasicBlock>();
worklist.add(in);
-
+
while (!worklist.isEmpty()) {
int wsize = worklist.size();
SsaBasicBlock v = worklist.get(wsize - 1);
/**
* Performs dominator/post-dominator calculation for the control
* flow graph.
- *
+ *
* @param meth {@code non-null;} method to analyze
*/
private void run() {
vertex.add(root);
domInfos[root.getIndex()].idom = root.getIndex();
}
-
+
/*
* First we perform a DFS numbering of the blocks, by
* numbering the dfs tree roots.
/**
* Constructs an instance
- *
+ *
* @param countOldRegisters number of registers in old namespace
*/
public InterferenceRegisterMapper(InterferenceGraph oldRegInterference,
/**
* Adds a register's interference set to the interference list,
* growing it if necessary.
- *
+ *
* @param newReg register in new namespace
* @param oldReg register in old namespace
*/
return true;
}
}
-
+
return false;
}
}
LiteralOpUpgrader dc;
dc = new LiteralOpUpgrader(ssaMethod);
-
+
dc.run();
}
/**
* Processes a method with this optimization step.
- *
+ *
* @param ssaMethod method to process
*/
public static void process(SsaMethod ssaMethod) {
}
private MoveParamCombiner(SsaMethod ssaMeth) {
- this.ssaMeth = ssaMeth;
+ this.ssaMeth = ssaMeth;
}
/**
// Use list is modified by mapSourceRegisters
for (int i = uses.size() - 1; i >= 0; i--) {
- SsaInsn use = uses.get(i);
+ SsaInsn use = uses.get(i);
use.mapSourceRegisters(mapper);
}
for (int i = 0; i < sz; i++) {
newSources.set(i, i == index ? newSpec : origSources.get(i));
}
-
+
newSources.setImmutable();
RegisterSpec origSpec = origSources.get(index);
if (origSpec.getReg() != newSpec.getReg()) {
/*
- * If the register remains unchanged, we're only changing
+ * If the register remains unchanged, we're only changing
* the type or local var name so don't update use list
*/
getBlock().getParent().onSourceChanged(this, origSpec, newSpec);
/**
* Like rop.Insn.getSources().
- *
+ *
* @return {@code null-ok;} sources list
*/
public RegisterSpecList getSources() {
/** {@inheritDoc} */
public RegisterSpec getLocalAssignment() {
RegisterSpec assignment;
-
+
if (insn.getOpcode().getOpcode() == RegOps.MARK_LOCAL) {
assignment = insn.getSources().get(0);
} else {
boolean isStatic, boolean inPreserveLocals,
TranslationAdvice inAdvice) {
- return optimize(rmeth, paramWidth, isStatic, inPreserveLocals, inAdvice,
+ return optimize(rmeth, paramWidth, isStatic, inPreserveLocals, inAdvice,
EnumSet.allOf(OptionalStep.class));
}
/**
* Runs optimization algorthims over this method, and returns a new
* instance of RopMethod with the changes.
- *
+ *
* @param rmeth method to process
* @param paramWidth the total width, in register-units, of this method's
* parameters
LivenessAnalyzer.constructInterferenceGraph(ssaMeth);
- return ssaMeth;
+ return ssaMeth;
}
}
/**
* Constructs a new phi insn with no operands.
- *
+ *
* @param resultReg the result reg for this phi insn
* @param block block containing this insn.
*/
/**
* Makes a phi insn with a void result type.
- *
+ *
* @param resultReg the result register for this phi insn.
* @param block block containing this insn.
*/
*/
public void updateSourcesToDefinitions(SsaMethod ssaMeth) {
for (Operand o : operands) {
- RegisterSpec def
+ RegisterSpec def
= ssaMeth.getDefinitionForRegister(
o.regSpec.getReg()).getResult();
/**
* Gets the original rop-form result reg. This is useful during renaming.
- *
+ *
* @return the original rop-form result reg
*/
public int getRopResultReg() {
/**
* Adds an operand to this phi instruction.
- *
+ *
* @param registerSpec register spec, including type and reg of operand
* @param predBlock predecessor block to be associated with this operand
*/
SsaBasicBlock predBlock) {
operands.add(new Operand(registerSpec, predBlock.getIndex(),
predBlock.getRopLabel()));
-
+
// Un-cache sources, in case someone has already called getSources().
sources = null;
}
/**
* Gets the index of the pred block associated with the RegisterSpec
* at the particular getSources() index.
- *
+ *
* @param sourcesIndex index of source in getSources()
* @return block index
*/
/**
* Gets sources. Constructed lazily from phi operand data structures and
* then cached.
- *
+ *
* @return {@code non-null;} sources list
*/
public RegisterSpecList getSources() {
/**
* Always throws an exeption, since a phi insn may not be
* converted back to rop form.
- *
+ *
* @return always throws exception
*/
@Override
/** {@inheritDoc} */
@Override
public boolean isPhiOrMove() {
- return true;
+ return true;
}
/** {@inheritDoc} */
/**
* Returns human-readable string for listing dumps. This method
* allows sub-classes to specify extra text.
- *
+ *
* @param extra {@code null-ok;} the argument to print after the opcode
* @return human-readable string for listing dumps
*/
StringBuffer sb = new StringBuffer(80);
sb.append(SourcePosition.NO_INFO);
- sb.append(": phi");
+ sb.append(": phi");
if (extra != null) {
sb.append("(");
}
RegisterSpec result = getResult();
-
+
if (result == null) {
sb.append(" .");
} else {
* Resolves the result of a phi insn based on its operands. The "void"
* type, which is a nonsensical type for a register, is used for
* registers defined by as-of-yet-unresolved phi operations.
- *
+ *
* @return true if the result type changed, false if no change
*/
boolean resolveResultType(PhiInsn insn) {
}
LocalItem newLocal = sameLocals ? firstLocal : null;
-
+
RegisterSpec result = insn.getResult();
if ((result.getTypeBearer() == newResultType)
import com.android.dx.util.ToHuman;
/**
- * Represents a mapping between two register numbering schemes.
+ * Represents a mapping between two register numbering schemes.
* Subclasses of this may be mutable, and as such the mapping provided
* is only valid for the lifetime of the method call in which
* instances of this class are passed.
return false;
}
}
-
+
/**
* Simulates a PHI node and set the lattice for the result
* to the approriate value.
* steps.
*/
private void replaceConstants() {
- for (int reg = 0; reg < regCount; reg++) {
+ for (int reg = 0; reg < regCount; reg++) {
if (latticeValues[reg] != CONSTANT) {
continue;
}
/**
* Constructs an instance.
- *
+ *
* @param result {@code null-ok;} initial result register. May be changed.
* @param block {@code non-null;} block containing this insn. Can
* never change.
/**
* Like {@link com.android.dx.rop.code.Insn getResult()}.
- *
+ *
* @return result register
*/
public RegisterSpec getResult() {
/**
* Set the result register.
- *
+ *
* @param result {@code non-null;} the new result register
*/
protected void setResult(RegisterSpec result) {
/**
* Like {@link com.android.dx.rop.code.Insn getSources()}.
- *
+ *
* @return {@code non-null;} sources list
*/
abstract public RegisterSpecList getSources();
/**
* Returns whether or not the specified reg is the result reg.
- *
+ *
* @param reg register to test
* @return true if there is a result and it is stored in the specified
* register
/**
* Changes the result register if this insn has a result. This is used
* during renaming.
- *
+ *
* @param reg new result register
*/
public void changeResultReg(int reg) {
result = mapper.map(result);
block.getParent().updateOneDefinition(this, oldResult);
- mapSourceRegisters(mapper);
+ mapSourceRegisters(mapper);
}
/**
/**
* Returns the original Rop insn for this insn, or null if this is
* a phi insn.
- *
+ *
* TODO: Move this up into NormalSsaInsn.
*
* @return {@code null-ok;} Rop insn if there is one.
* may be the result register, or for {@code mark-local} insns
* it may be the source.
*
- * @see com.android.dx.rop.code.Insn#getLocalAssignment()
- *
+ * @see com.android.dx.rop.code.Insn#getLocalAssignment()
+ *
* @return {@code null-ok;} a local-associated register spec or null
*/
public RegisterSpec getLocalAssignment() {
/**
* Indicates whether the specified register is amongst the registers
* used as sources for this instruction.
- *
+ *
* @param reg the register in question
* @return true if the reg is a source
*/
/**
* Returns true if this insn is considered to have a side effect beyond
* that of assigning to the result reg.
- *
+ *
* @return true if this insn is considered to have a side effect beyond
* that of assigning to the result reg.
*/
/**
* Accepts a visitor.
- *
+ *
* @param v {@code non-null} the visitor
*/
public abstract void accept(Visitor v);
/**
* Constructs instance. Call {@code process()} to run.
- *
+ *
* @param rm {@code non-null;} instance to process
*/
public IdenticalBlockCombiner(RopMethod rm) {
/**
* Helper method to compare the contents of two blocks.
- *
+ *
* @param a {@code non-null;} a block to compare
* @param b {@code non-null;} another block to compare
* @return {@code true} iff the two blocks' instructions are the same
return interference;
}
-
+
/**
* Makes liveness analyzer instance for specific register.
*
}
return mapper;
- }
+ }
}
/**
* Runs the algorithm.
- *
+ *
* @return a register mapper to apply to the {@code SsaMethod}
*/
public abstract RegisterMapper allocateRegisters();
/**
* Returns true if the definition site of this register is a
* move-param (ie, this is a method parameter).
- *
+ *
* @param reg register in question
* @return {@code true} if this is a method parameter
*/
/**
* Converts a method in SSA form to ROP form.
- *
+ *
* @param ssaMeth {@code non-null;} method to process
* @param minimizeRegisters {@code true} if the converter should
* attempt to minimize the rop-form register count
/**
* Constructs an instance.
- *
+ *
* @param ssaMeth {@code non-null;} method to process
* @param minimizeRegisters {@code true} if the converter should
* attempt to minimize the rop-form register count
/**
* Performs the conversion.
- *
+ *
* @return {@code non-null;} rop-form output
*/
private RopMethod convert() {
if (DEBUG) {
System.out.println("Printing reg map");
System.out.println(((BasicRegisterMapper)mapper).toHuman());
- }
+ }
ssaMeth.setBackMode();
}
/**
- * Removes all blocks containing only GOTOs from the control flow.
+ * Removes all blocks containing only GOTOs from the control flow.
* Although much of this work will be done later when converting
* from rop to dex, not all simplification cases can be handled
* there. Furthermore, any no-op block between the exit block and
*/
private void removePhiFunctions() {
ArrayList<SsaBasicBlock> blocks = ssaMeth.getBlocks();
-
+
for (SsaBasicBlock block : blocks) {
// Add moves in all the pred blocks for each phi insn.
block.forEachPhiInsn(new PhiVisitor(blocks));
/**
* Converts an insn list to rop form.
- *
+ *
* @param ssaInsns {@code non-null;} old instructions
* @return {@code non-null;} immutable instruction list
*/
/**
* <b>Note:</b> This method is not presently used.
- *
+ *
* @return a list of registers ordered by most-frequently-used to
* least-frequently-used. Each register is listed once and only
* once.
}
return result;
- }
+ }
}
extends Output {
/**
* Get whether this instance will actually keep annotations.
- *
+ *
* @return {@code true} iff annotations are being kept
*/
public boolean annotates();
* Get whether this instance is intended to keep verbose annotations.
* Annotators may use the result of calling this method to inform their
* annotation activity.
- *
+ *
* @return {@code true} iff annotations are to be verbose
*/
public boolean isVerbose();
* open annotation will be closed by this call, and the new
* annotation marks all subsequent output until another annotation
* call.
- *
+ *
* @param msg {@code non-null;} the annotation message
*/
public void annotate(String msg);
* call. If there is already pending annotation from one or more
* previous calls to this method, the new call "consumes" output
* after all the output covered by the previous calls.
- *
+ *
* @param amt {@code >= 0;} the amount of output for this annotation to
* cover
* @param msg {@code non-null;} the annotation message
* Implementations of this interface are encouraged to deal with too-wide
* output, but annotaters are encouraged to attempt to avoid exceeding
* the indicated width.
- *
+ *
* @return {@code >= 1;} the maximum width
*/
public int getAnnotationWidth();
/** @inheritDoc */
public boolean has(int value) {
- return (value < Bits.getMax(bits)) && Bits.get(bits, value);
+ return (value < Bits.getMax(bits)) && Bits.get(bits, value);
}
/** @inheritDoc */
/** @inheritDoc */
public int elements() {
- return Bits.bitCount(bits);
+ return Bits.bitCount(bits);
}
/** @inheritDoc */
/**
* Constructs a bit set to contain bits up to the given index (exclusive).
- *
+ *
* @param max {@code >= 0;} the maximum bit index (exclusive)
* @return {@code non-null;} an appropriately-constructed instance
*/
/**
* Gets the maximum index (exclusive) for the given bit set.
- *
+ *
* @param bits {@code non-null;} bit set in question
* @return {@code >= 0;} the maximum index (exclusive) that may be set
*/
/**
* Gets the value of the bit at the given index.
- *
+ *
* @param bits {@code non-null;} bit set to operate on
* @param idx {@code >= 0, < getMax(set);} which bit
* @return the value of the indicated bit
/**
* Sets the given bit to the given value.
- *
+ *
* @param bits {@code non-null;} bit set to operate on
* @param idx {@code >= 0, < getMax(set);} which bit
* @param value the new value for the bit
/**
* Sets the given bit to {@code true}.
- *
+ *
* @param bits {@code non-null;} bit set to operate on
* @param idx {@code >= 0, < getMax(set);} which bit
*/
/**
* Sets the given bit to {@code false}.
- *
+ *
* @param bits {@code non-null;} bit set to operate on
* @param idx {@code >= 0, < getMax(set);} which bit
*/
/**
* Returns whether or not the given bit set is empty, that is, whether
* no bit is set to {@code true}.
- *
+ *
* @param bits {@code non-null;} bit set to operate on
* @return {@code true} iff all bits are {@code false}
*/
/**
* Gets the number of bits set to {@code true} in the given bit set.
- *
+ *
* @param bits {@code non-null;} bit set to operate on
* @return {@code >= 0;} the bit count (aka population count) of the set
*/
/**
* Returns whether any bits are set to {@code true} in the
* specified range.
- *
+ *
* @param bits {@code non-null;} bit set to operate on
* @param start {@code >= 0;} index of the first bit in the range (inclusive)
* @param end {@code >= 0;} index of the last bit in the range (exclusive)
/**
* Finds the lowest-order bit set at or after the given index in the
* given bit set.
- *
+ *
* @param bits {@code non-null;} bit set to operate on
* @param idx {@code >= 0;} minimum index to return
* @return {@code >= -1;} lowest-order bit set at or after {@code idx},
/**
* Finds the lowest-order bit set at or after the given index in the
* given {@code int}.
- *
+ *
* @param value the value in question
* @param idx 0..31 the minimum bit index to return
* @return {@code >= -1;} lowest-order bit set at or after {@code idx},
* Copies the contents of this instance into the given raw
* {@code byte[]} at the given offset. The given array must be
* large enough.
- *
+ *
* @param out {@code non-null;} array to hold the output
* @param offset {@code non-null;} index into {@code out} for the first
* byte of output
* with the cursor starting at the beginning of this instance's data.
* <b>Note:</b> The returned instance may be cast to {@link #GetCursor}
* if needed.
- *
+ *
* @return {@code non-null;} an appropriately-constructed
* {@code DataInputStream} instance
*/
* with the cursor starting at the beginning of this instance's data.
* <b>Note:</b> The returned instance may be cast to {@link #GetCursor}
* if needed.
- *
+ *
* @return {@code non-null;} an appropriately-constructed
* {@code InputStream} instancex
*/
public interface GetCursor {
/**
* Gets the current cursor.
- *
+ *
* @return {@code 0..size();} the cursor
*/
public int getCursor();
}
-
+
/**
* Helper class for {@link #makeInputStream}, which implements the
* stream functionality.
/** 0..size; the mark */
private int mark;
-
+
public MyInputStream() {
cursor = 0;
mark = 0;
if ((offset + length) > arr.length) {
length = arr.length - offset;
}
-
+
int maxLength = size - cursor;
if (length > maxLength) {
length = maxLength;
public static class MyDataInputStream extends DataInputStream {
/** {@code non-null;} the underlying {@link #MyInputStream} */
private final MyInputStream wrapped;
-
+
public MyDataInputStream(MyInputStream wrapped) {
super(wrapped);
/**
* Implementation of {@link AnnotatedOutput} which stores the written data
* into a {@code byte[]}.
- *
+ *
* <p><b>Note:</b> As per the {@link Output} interface, multi-byte
* writes all use little-endian order.</p>
*/
implements AnnotatedOutput {
/** default size for stretchy instances */
private static final int DEFAULT_SIZE = 1000;
-
+
/**
* whether the instance is stretchy, that is, whether its array
* may be resized to increase capacity
/**
* {@code null-ok;} list of annotations, or {@code null} if this instance
- * isn't keeping them
+ * isn't keeping them
*/
private ArrayList<Annotation> annotations;
/**
* {@code >= 8 (if used);} the number of bytes of hex output to use
- * in annotations
+ * in annotations
*/
private int hexCols;
* particular, no reallocation will occur in order to expand the
* capacity of the resulting instance. Also, the constructed
* instance does not keep annotations by default.
- *
+ *
* @param data {@code non-null;} data array to use for output
*/
public ByteArrayAnnotatedOutput(byte[] data) {
/**
* Internal constructor.
- *
+ *
* @param data {@code non-null;} data array to use for output
* @param stretchy whether the instance is to be stretchy
*/
/**
* Gets the underlying {@code byte[]} of this instance, which
* may be larger than the number of bytes written
- *
+ *
* @see #toByteArray
- *
+ *
* @return {@code non-null;} the {@code byte[]}
*/
public byte[] getArray() {
* Constructs and returns a new {@code byte[]} that contains
* the written contents exactly (that is, with no extra unwritten
* bytes at the end).
- *
+ *
* @see #getArray
- *
+ *
* @return {@code non-null;} an appropriately-constructed array
*/
public byte[] toByteArray() {
return count;
}
-
+
/** {@inheritDoc} */
public void write(ByteArray bytes) {
int blen = bytes.size();
// twos-complement math trick: ((x < 0) || (y < 0)) <=> ((x|y) < 0)
if (((offset | length | end) < 0) || (bytesEnd > bytes.length)) {
throw new IndexOutOfBoundsException("bytes.length " +
- bytes.length + "; " +
+ bytes.length + "; " +
offset + "..!" + end);
}
* Indicates that this instance should keep annotations. This method may
* be called only once per instance, and only before any data has been
* written to the it.
- *
+ *
* @param annotationWidth {@code >= 40;} the desired maximum annotation width
* @param verbose whether or not to indicate verbose annotations
*/
/**
* Writes the annotated content of this instance to the given writer.
- *
+ *
* @param out {@code non-null;} where to write to
*/
public void writeAnnotationsTo(Writer out) throws IOException {
/**
* Reallocates the underlying array if necessary. Calls to this method
* should be guarded by a test of {@link #stretchy}.
- *
+ *
* @param desiredSize {@code >= 0;} the desired minimum total size of the array
*/
private void ensureCapacity(int desiredSize) {
/**
* {@code >= 0;} end of annotated range (exclusive);
- * {@code Integer.MAX_VALUE} if unclosed
+ * {@code Integer.MAX_VALUE} if unclosed
*/
private int end;
/**
* Constructs an instance.
- *
+ *
* @param start {@code >= 0;} start of annotated range
* @param end {@code >= start;} end of annotated range (exclusive) or
* {@code Integer.MAX_VALUE} if unclosed
/**
* Constructs an instance. It is initally unclosed.
- *
+ *
* @param start {@code >= 0;} start of annotated range
* @param text {@code non-null;} annotation text
*/
/**
* Sets the end as given, but only if the instance is unclosed;
* otherwise, do nothing.
- *
+ *
* @param end {@code >= start;} the end
*/
public void setEndIfUnset(int end) {
/**
* Sets the end as given.
- *
+ *
* @param end {@code >= start;} the end
*/
public void setEnd(int end) {
/**
* Gets the start.
- *
+ *
* @return the start
*/
public int getStart() {
/**
* Gets the end.
- *
+ *
* @return the end
*/
public int getEnd() {
/**
* Gets the text.
- *
+ *
* @return {@code non-null;} the text
*/
public String getText() {
/**
* Reads the named file, translating {@link IOException} to a
* {@link RuntimeException} of some sort.
- *
+ *
* @param fileName {@code non-null;} name of the file to read
* @return {@code non-null;} contents of the file
*/
/**
* Reads the given file, translating {@link IOException} to a
* {@link RuntimeException} of some sort.
- *
+ *
* @param file {@code non-null;} the file to read
* @return {@code non-null;} contents of the file
*/
/**
* Constructs an instance. All indices initially contain {@code null}.
- *
+ *
* @param size the size of the list
*/
public FixedSizeList(int size) {
/**
* {@inheritDoc}
- *
+ *
* This method will only work if every element of the list
* implements {@link ToHuman}.
*/
/**
* Gets a customized string form for this instance.
- *
+ *
* @param prefix {@code null-ok;} prefix for the start of the result
* @param separator {@code null-ok;} separator to insert between each item
* @param suffix {@code null-ok;} suffix for the end of the result
* Gets a customized human string for this instance. This method will
* only work if every element of the list implements {@link
* ToHuman}.
- *
+ *
* @param prefix {@code null-ok;} prefix for the start of the result
* @param separator {@code null-ok;} separator to insert between each item
* @param suffix {@code null-ok;} suffix for the end of the result
* will throw {@code NullPointerException}. This method is
* protected so that subclasses may offer a safe type-checked
* public interface to their clients.
- *
+ *
* @param n {@code >= 0, < size();} which element
* @return {@code non-null;} the indicated element
*/
* returned. This method is protected so that subclasses may
* (optionally) offer a safe type-checked public interface to
* their clients.
- *
+ *
* @param n {@code >= 0, < size();} which element
* @return {@code null-ok;} the indicated element
*/
* checks on the element. This method is protected so that
* subclasses may offer a safe type-checked public interface to
* their clients.
- *
+ *
* @param n {@code >= 0, < size();} which element
* @param obj {@code null-ok;} the value to store
*/
/**
* Throws the appropriate exception for the given index value.
- *
+ *
* @param n the index value
* @return never
* @throws IndexOutOfBoundsException always thrown
/**
* Helper for {@link #toString} and {@link #toHuman}, which both of
* those call to pretty much do everything.
- *
+ *
* @param prefix {@code null-ok;} prefix for the start of the result
* @param separator {@code null-ok;} separator to insert between each item
* @param suffix {@code null-ok;} suffix for the end of the result
- * @param human whether the output is to be human
+ * @param human whether the output is to be human
* @return {@code non-null;} the custom string
*/
private String toString0(String prefix, String separator, String suffix,
/**
* Formats a {@code long} as an 8-byte unsigned hex value.
- *
+ *
* @param v value to format
* @return {@code non-null;} formatted form
*/
/**
* Formats an {@code int} as a 4-byte unsigned hex value.
- *
+ *
* @param v value to format
* @return {@code non-null;} formatted form
*/
/**
* Formats an {@code int} as a 3-byte unsigned hex value.
- *
+ *
* @param v value to format
* @return {@code non-null;} formatted form
*/
/**
* Formats an {@code int} as a 2-byte unsigned hex value.
- *
+ *
* @param v value to format
* @return {@code non-null;} formatted form
*/
* Formats an {@code int} as either a 2-byte unsigned hex value
* (if the value is small enough) or a 4-byte unsigned hex value (if
* not).
- *
+ *
* @param v value to format
* @return {@code non-null;} formatted form
*/
/**
* Formats an {@code int} as a 1-byte unsigned hex value.
- *
+ *
* @param v value to format
* @return {@code non-null;} formatted form
*/
/**
* Formats an {@code int} as a 4-bit unsigned hex nibble.
- *
+ *
* @param v value to format
* @return {@code non-null;} formatted form
*/
/**
* Formats a {@code long} as an 8-byte signed hex value.
- *
+ *
* @param v value to format
* @return {@code non-null;} formatted form
*/
/**
* Formats an {@code int} as a 4-byte signed hex value.
- *
+ *
* @param v value to format
* @return {@code non-null;} formatted form
*/
/**
* Formats an {@code int} as a 2-byte signed hex value.
- *
+ *
* @param v value to format
* @return {@code non-null;} formatted form
*/
/**
* Formats an {@code int} as a 1-byte signed hex value.
- *
+ *
* @param v value to format
* @return {@code non-null;} formatted form
*/
* Formats a hex dump of a portion of a {@code byte[]}. The result
* is always newline-terminated, unless the passed-in length was zero,
* in which case the result is always the empty string ({@code ""}).
- *
+ *
* @param arr {@code non-null;} array to format
* @param offset {@code >= 0;} offset to the part to dump
* @param length {@code >= 0;} number of bytes to dump
// twos-complement math trick: ((x < 0) || (y < 0)) <=> ((x|y) < 0)
if (((offset | length | end) < 0) || (end > arr.length)) {
throw new IndexOutOfBoundsException("arr.length " +
- arr.length + "; " +
+ arr.length + "; " +
offset + "..!" + end);
}
sb.append('\n');
}
- return sb.toString();
+ return sb.toString();
}
}
* comment. If a double quote is encountered, then the ASCII value
* of the subsequent characters is used, until the next double
* quote. Quoted strings may not span multiple lines.
- *
+ *
* @param src {@code non-null;} the source string
* @return {@code non-null;} the parsed form
*/
/**
* Constructs an instance.
- *
+ *
* @param out {@code non-null;} writer to send final output to
* @param width {@code >= 0;} the maximum output width (not including
* {@code prefix}), or {@code 0} for no maximum
/**
* Constructs a no-prefix instance.
- *
+ *
* @param out {@code non-null;} writer to send final output to
* @param width {@code >= 0;} the maximum output width (not including
* {@code prefix}), or {@code 0} for no maximum
/**
* Constructs a new immutable instance with the given element.
- *
+ *
* @param value the sole value in the list
*/
public static IntList makeImmutable(int value) {
/**
* Constructs a new immutable instance with the given elements.
- *
+ *
* @param value0 the first value in the list
* @param value1 the second value in the list
*/
/**
* Constructs an empty instance.
- *
+ *
* @param initialCapacity {@code >= 0;} initial capacity of the list
*/
public IntList(int initialCapacity) {
/**
* Gets the indicated value.
- *
+ *
* @param n {@code >= 0, < size();} which element
* @return the indicated element's value
*/
/**
* Sets the value at the given index.
- *
+ *
* @param n {@code >= 0, < size();} which element
* @param value value to store
*/
/**
* Adds an element to the end of the list. This will increase the
* list's capacity if necessary.
- *
+ *
* @param value the value to add
*/
public void add(int value) {
result = get(size-1);
size--;
- return result;
+ return result;
}
/**
/**
* Shrinks the size of the list.
- *
+ *
* @param newSize {@code >= 0;} the new size
*/
public void shrink(int newSize) {
/**
* Makes and returns a mutable copy of the list.
- *
+ *
* @return {@code non-null;} an appropriately-constructed instance
*/
public IntList mutableCopy() {
* Returns whether or not the given value appears in the list.
* This will do a binary search if the list is sorted or a linear
* search if not.
- *
+ *
* @see #sort
- *
+ *
* @param value value to look for
* @return whether the list contains the given value
*/
if (item != null) {
addLabelIndex(item.getLabel(), n);
- }
+ }
}
}
/**
* Gets the number of bytes in the unsigned LEB128 encoding of the
* given value.
- *
+ *
* @param value the value in question
* @return its write size, in bytes
*/
public static int unsignedLeb128Size(int value) {
// TODO: This could be much cleverer.
-
+
int remaining = value >> 7;
int count = 0;
/**
* Gets the number of bytes in the signed LEB128 encoding of the
* given value.
- *
+ *
* @param value the value in question
* @return its write size, in bytes
*/
/** @inheritDoc */
public boolean has(int value) {
- return ints.indexOf(value) >= 0;
+ return ints.indexOf(value) >= 0;
}
/** @inheritDoc */
while (j < szOther && i < szThis) {
while (j < szOther && o.ints.get(j) < ints.get(i)) {
add(o.ints.get(j++));
- }
+ }
if (j == szOther) {
break;
}
package com.android.dx.util;
/**
- * Interface for a sink for binary output. This is similar to
+ * Interface for a sink for binary output. This is similar to
* {@code java.util.DataOutput}, but no {@code IOExceptions}
* are declared, and multibyte output is defined to be little-endian.
*/
/**
* Gets the current cursor position. This is the same as the number of
* bytes written to this instance.
- *
+ *
* @return {@code >= 0;} the cursor position
*/
public int getCursor();
/**
* Asserts that the cursor is the given value.
- *
+ *
* @param expectedCursor the expected cursor value
* @throws RuntimeException thrown if {@code getCursor() !=
* expectedCursor}
*/
public void assertCursor(int expectedCursor);
-
+
/**
* Writes a {@code byte} to this instance.
- *
+ *
* @param value the value to write; all but the low 8 bits are ignored
*/
public void writeByte(int value);
/**
* Writes a {@code short} to this instance.
- *
+ *
* @param value the value to write; all but the low 16 bits are ignored
*/
public void writeShort(int value);
/**
* Writes an {@code int} to this instance.
- *
+ *
* @param value the value to write
*/
public void writeInt(int value);
/**
* Writes a {@code long} to this instance.
- *
+ *
* @param value the value to write
*/
public void writeLong(long value);
/**
* Writes a {@link ByteArray} to this instance.
- *
+ *
* @param bytes {@code non-null;} the array to write
*/
public void write(ByteArray bytes);
/**
* Writes a portion of a {@code byte[]} to this instance.
- *
+ *
* @param bytes {@code non-null;} the array to write
* @param offset {@code >= 0;} offset into {@code bytes} for the first
* byte to write
/**
* Writes a {@code byte[]} to this instance. This is just
* a convenient shorthand for {@code write(bytes, 0, bytes.length)}.
- *
+ *
* @param bytes {@code non-null;} the array to write
*/
public void write(byte[] bytes);
- /**
+ /**
* Writes the given number of {@code 0} bytes.
- *
+ *
* @param count {@code >= 0;} the number of zeroes to write
*/
public void writeZeroes(int count);
- /**
+ /**
* Adds extra bytes if necessary (with value {@code 0}) to
* force alignment of the output cursor as given.
- *
+ *
* @param alignment {@code > 0;} the alignment; must be a power of two
*/
public void alignTo(int alignment);
/**
* Turns the given two strings (with widths) and spacer into a formatted
* two-column string.
- *
+ *
* @param s1 {@code non-null;} first string
* @param width1 {@code > 0;} width of the first column
* @param spacer {@code non-null;} spacer string
/**
* Constructs an instance.
- *
+ *
* @param out {@code non-null;} writer to send final output to
* @param leftWidth {@code > 0;} width of the left column, in characters
* @param rightWidth {@code > 0;} width of the right column, in characters
/**
* Constructs an instance.
- *
+ *
* @param out {@code non-null;} stream to send final output to
* @param leftWidth {@code >= 1;} width of the left column, in characters
* @param rightWidth {@code >= 1;} width of the right column, in characters
/**
* Gets the writer to use to write to the left column.
- *
+ *
* @return {@code non-null;} the left column writer
*/
public Writer getLeft() {
/**
* Gets the writer to use to write to the right column.
- *
+ *
* @return {@code non-null;} the right column writer
*/
public Writer getRight() {
/**
* Appends a newline to the given buffer via the given writer, but
* only if it isn't empty and doesn't already end with one.
- *
+ *
* @param buf {@code non-null;} the buffer in question
* @param out {@code non-null;} the writer to use
*/
private static void appendNewlineIfNecessary(StringBuffer buf,
- Writer out)
+ Writer out)
throws IOException {
int len = buf.length();
/**
* Writes the given number of spaces to the given writer.
- *
+ *
* @param out {@code non-null;} where to write
* @param amt {@code >= 0;} the number of spaces to write
*/
* Makes a {@code PrintWriter} for the given {@code Writer},
* returning the given writer if it already happens to be the right
* class.
- *
+ *
* @param writer {@code non-null;} writer to (possibly) wrap
* @return {@code non-null;} an appropriate instance
*/
assertTrue(set.has(31));
assertEquals(3, set.elements());
-
+
assertFalse(set.has(2));
assertFalse(set.has(7));
assertFalse(set.has(30));
IntIterator iter = set.iterator();
- assertFalse(iter.hasNext());
+ assertFalse(iter.hasNext());
}
public void test_remove() {
* limitations under the License.
*/
-public class Blort
+public class Blort
{
static public int hello() {
return 10;
* limitations under the License.
*/
-public class Blort
+public class Blort
{
// This space intentionally left blank.
}
* limitations under the License.
*/
-public class Blort
+public class Blort
{
private volatile int i;
private volatile long l;
private volatile float f;
private volatile double d;
-
+
public void blort(int i1, int i2) {
i = -i1;
i = ~i1;
d = d1 * d2;
d = d1 / d2;
d = d1 % d2;
- }
+ }
}
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public int switchTest1(int x) {
switch (x) {
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static int maybeThrow(int x) {
if (x < 10) {
return x;
}
-
+
public static int exTest1(int x) {
try {
maybeThrow(x);
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static long test1(int w, long x, int y, long z) {
return w + x + y + z;
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static void sink(Object x) {
// Do nothing.
}
-
+
public static void test() {
sink(new boolean[0]);
sink(new byte[1]);
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static boolean test(Object x) {
return x instanceof Blort;
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static Blort test(Object x) {
return (Blort) x;
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static Object test1() {
return null;
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static boolean staticBoolean;
public static byte staticByte;
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public boolean insBoolean;
public byte insByte;
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static void sink(int i) {
// Do nothing.
* limitations under the License.
*/
-public class Blort
+public class Blort
{
private static RuntimeException theException = new RuntimeException();
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static int test(Zorch z, double d) {
z.zorch1();
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static int test(Zorch z) {
z.zorch1();
public class Zorch
{
- public void zorch1() {
+ public void zorch1() {
// This space intentionally left blank.
}
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static int test(Blort b) {
b.zorch1();
* limitations under the License.
*/
-public class Blort
+public class Blort
extends Zorch
{
public int test1() {
public class Zorch
{
- public void zorch1() {
+ public void zorch1() {
// This space intentionally left blank.
}
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static int test() {
Zorch.zorch1();
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static void caught() {
// This space intentionally left blank.
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public synchronized void testInstance1() {
// This space intentionally left blank.
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public int test1(int x) {
switch (x) {
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public boolean test01(boolean[] x) {
x[0] = true;
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public boolean[] test1() {
return new boolean[1];
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static Object zorch1(String s) {
return null;
}
-
+
public static void test1() {
try {
zorch1("x");
public static int zorch3(String s) {
return 0;
}
-
+
public static void test3() {
try {
zorch3("x");
public static Object zorch4(int x) {
return null;
}
-
+
public static void test4() {
try {
zorch4(1);
public static Object zorch5(int x) {
return null;
}
-
+
public static Object test5() {
try {
return zorch5(1);
* limitations under the License.
*/
-public class Blort
+public class Blort
{
static public void blort() {
// This space intentionally left blank.
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static boolean zorch() {
return true;
}
-
+
public static void test1() {
for (;;) {
// This space intentionally left blank.
if (zorch()) {
break;
}
-
+
while (zorch()) {
zorch();
}
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static int test(int x) {
if (x == 0) { // line 6
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static Object test01() {
Object[][] x = new Object[2][5];
* limitations under the License.
*/
-public class Blort
+public class Blort
{
// Empty switch statement. (Note: This is the same as a default-only
// switch statement, since under the covers every switch statement
return 1;
}
-
+
// Single element: Integer.MAX_VALUE.
public int test4(int x) {
switch (x) {
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static Object test1() {
return ((Object[]) null)[0];
return arr[0];
}
-
+
public static void test8(Object[] arr) {
if (check()) {
arr = null;
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public void test()
{
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static void test(long[] arr)
{
long x = 0;
-
+
for (;;) {
x += arr[0];
}
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public synchronized void test() {
new Object();
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static void justReturn1() {
// This space intentionally left blank.
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static void test01(Object x) {
x.hashCode();
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public static int test1(int x) {
float f0 = 0.0f;
return 10;
} catch (RuntimeException ex) {
return 11;
- }
+ }
call3();
return 12;
call1();
} catch (RuntimeException ex) {
return 10;
- }
+ }
try {
call2();
} catch (RuntimeException ex) {
return 11;
- }
+ }
return 12;
}
call2();
} catch (RuntimeException ex) {
return 10;
- }
+ }
try {
call3();
call4();
} catch (RuntimeException ex) {
return 11;
- }
+ }
return 12;
}
return 14;
}
-
+
}
* limitations under the License.
*/
-public class Blort
+public class Blort
{
public int phiTest() {
int j = 1;
int k = 0;
- while (k < 100) {
+ while (k < 100) {
if (j < 20) {
j = i;
k++;
* limitations under the License.
*/
-public class Blort
+public class Blort
{
private static int i;
private static long l;
private static Object o;
-
+
public static void test() {
int i0 = 0;
int i1 = 0;
* limitations under the License.
*/
-public class Blort
+public class Blort
{
/**
* This method requires the edge-splitter to add a node
* to get to the finally block, since there are
* two exception sources.
- *
+ *
*/
public int edgeSplitPredTest(int x) {
int y = 1;
* a unique predecessor
*/
void edgeSplitMoveException() {
- try {
+ try {
hashCode();
hashCode();
} catch (Throwable tr) {
*/
int edgeSplitSuccessor(int x) {
int y = 0;
-
+
switch(x) {
case 1: y++;
break;
System.out.println("object -> string (modified)");
objectArray[4] = new Object();
try {
- System.arraycopy(objectArray, 0, stringArray, 0,stringArray.length);
+ System.arraycopy(objectArray, 0, stringArray, 0,stringArray.length);
} catch (ArrayStoreException ase) {
// "ase" is an unused local which still must be preserved
System.out.println("caught ArrayStoreException (expected)");
System.err.println(foo);
}
/**
- * Stolen from
+ * Stolen from
* java/android/org/apache/http/impl/io/AbstractMessageParser.java
* Simplified.
*
}
i++;
}
- if (maxLineLen > 0
+ if (maxLineLen > 0
&& previous.length() + 1 + current.length() - i > maxLineLen) {
throw new IOException("Maximum line length limit exceeded");
}
* limitations under the License.
*/
-public class Blort
+public class Blort
{
/**
* just because this should do nothing
* a unique predecessor
*/
void edgeSplitMoveException() {
- try {
+ try {
hashCode();
hashCode();
} catch (Throwable tr) {
package java.lang;
public class Object {
- public Object() {
+ public Object() {
// This space intentionally left blank.
}
public boolean equals(Object o) {
- return true;
+ return true;
}
- protected void finalize() {
+ protected void finalize() {
// This space intentionally left blank.
}
public final native void notifyAll();
public String toString() {
- return "blort";
+ return "blort";
}
public final void wait() {
* limitations under the License.
*/
-public class Blort
+public class Blort
{
/*
* Note: The use of the casts after the "?" in the following are
enum Foo {
ONE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT
}
-
+
/** all uses of 10 should be combined except the local assignment */
void testNumeric() {
int foo = 10;
class Blort {
-
+
void testMultipleIdenticalSuccessors(int foo) {
switch(foo) {
case 1:
class Blort {
-
+
static void methodThatNeedsInvokeRange
(int a, int b, int c, int d, int e, int f) {
}
-
+
void testNoLocals() {
methodThatNeedsInvokeRange(5, 0, 5, 0, 5, 0);
}
methodThatNeedsInvokeRange(src, 0, dest, 1, 5, 0);
methodThatNeedsInvokeRange(dest, 0, src, 1, 5, 0);
}
-
+
// ensure that an attempt to combine registers for a local
// with a differing category doesn't mess us up.
long testMixedCategory(boolean foo) {
for i in $failNames; do
echo "failed: $i"
done
-
+
private int mType;
private int mNumEntries;
private byte[] mData;
-
- public ArrayInstance(long id, StackTrace stack, int type, int numEntries,
+
+ public ArrayInstance(long id, StackTrace stack, int type, int numEntries,
byte[] data) {
mId = id;
mStack = stack;
if (mType != Types.OBJECT) {
return;
}
-
+
/*
* mData holds a stream of object instance ids
* Spin through them all and list ourselves as a reference holder.
*/
int idSize = Types.getTypeSize(mType);
final int N = mNumEntries;
-
+
ByteArrayInputStream bais = new ByteArrayInputStream(mData);
DataInputStream dis = new DataInputStream(bais);
-
+
for (int i = 0; i < N; i++) {
long id;
}
Instance instance = state.findReference(id);
-
+
if (instance != null) {
instance.addParent(this);
}
if (resultSet.contains(this)) {
return;
}
-
+
if (null != filter) {
if (filter.accept(this)) {
resultSet.add(this);
if (mType != Types.OBJECT) {
return;
}
-
+
/*
* mData holds a stream of object instance ids
* Spin through them all and visit them
*/
int idSize = Types.getTypeSize(mType);
final int N = mNumEntries;
-
+
ByteArrayInputStream bais = new ByteArrayInputStream(mData);
DataInputStream dis = new DataInputStream(bais);
State state = mHeap.mState;
-
+
for (int i = 0; i < N; i++) {
long id;
-
+
try {
if (idSize == 4) {
id = dis.readInt();
} else {
id = dis.readLong();
}
-
+
Instance instance = state.findReference(id);
-
+
if (instance != null) {
instance.visit(resultSet, filter);
}
if (mType != Types.OBJECT) {
return super.describeReferenceTo(referent);
}
-
+
int idSize = Types.getTypeSize(mType);
final int N = mNumEntries;
int numRefs = 0;
StringBuilder result = new StringBuilder("Elements [");
ByteArrayInputStream bais = new ByteArrayInputStream(mData);
DataInputStream dis = new DataInputStream(bais);
-
+
/*
* Spin through all the objects and build up a string describing
* all of the array elements that refer to the target object.
*/
for (int i = 0; i < N; i++) {
long id;
-
+
try {
if (idSize == 4) {
id = dis.readInt();
} else {
id = dis.readLong();
}
-
+
if (id == referent) {
numRefs++;
-
+
if (numRefs > 1) {
result.append(", ");
}
-
+
result.append(i);
}
} catch (java.io.IOException e) {
e.printStackTrace();
}
}
-
+
if (numRefs == 0) {
return super.describeReferenceTo(referent);
}
result.append("]");
-
+
return result.toString();
}
}
mStack = stack;
mClassId = classId;
}
-
+
public final void loadFieldData(DataInputStream in, int numBytes)
throws IOException {
mFieldValues = new byte[numBytes];
resolve(state, isa, isa.mFieldTypes, mFieldValues);
}
- private void resolve(State state, ClassObj isa, int[] types,
+ private void resolve(State state, ClassObj isa, int[] types,
byte[] values) {
ByteArrayInputStream bais = new ByteArrayInputStream(values);
DataInputStream dis = new DataInputStream(bais);
if (type == Types.OBJECT) {
long id;
-
+
if (size == 4) {
id = dis.readInt();
} else {
id = dis.readLong();
}
-
+
Instance instance = state.findReference(id);
-
+
if (instance != null) {
instance.addParent(this);
}
@Override
public final int getSize() {
ClassObj isa = mHeap.mState.findClass(mClassId);
-
+
return isa.getSize();
}
if (resultSet.contains(this)) {
return;
}
-
+
if (filter != null) {
if (filter.accept(this)) {
resultSet.add(this);
ByteArrayInputStream bais = new ByteArrayInputStream(mFieldValues);
DataInputStream dis = new DataInputStream(bais);
final int N = types.length;
-
+
/*
* Spin through the list of fields, find all object references,
* and list ourselves as a reference holder.
for (int i = 0; i < N; i++) {
int type = types[i];
int size = Types.getTypeSize(type);
-
+
if (type == Types.OBJECT) {
long id;
-
+
if (size == 4) {
id = dis.readInt();
} else {
id = dis.readLong();
}
-
+
Instance instance = state.findReference(id);
-
+
if (instance != null) {
instance.visit(resultSet, filter);
}
@Override
public final String getTypeName() {
ClassObj theClass = mHeap.mState.findClass(mClassId);
-
+
return theClass.mClassName;
}
final int N = types.length;
StringBuilder result = new StringBuilder("Referenced in field(s):");
int numReferences = 0;
-
+
/*
* Spin through the list of fields, add info about the field
* references to the output text.
for (int i = 0; i < N; i++) {
int type = types[i];
int size = Types.getTypeSize(type);
-
+
if (type == Types.OBJECT) {
long id;
-
+
if (size == 4) {
id = dis.readInt();
} else {
id = dis.readLong();
}
-
+
if (id == referent) {
numReferences++;
result.append("\n ");
if (numReferences == 0) {
return super.describeReferenceTo(referent);
}
-
+
return result.toString();
}
}
DataInputStream dis = new DataInputStream(bais);
int[] types = mStaticFieldTypes;
final int N = types.length;
-
+
/*
* Spin through the list of static fields, find all object references,
* and list ourselves as a reference holder. Also add them to
for (int i = 0; i < N; i++) {
int type = types[i];
int size = Types.getTypeSize(type);
-
+
if (type == Types.OBJECT) {
long id;
-
+
if (size == 4) {
id = dis.readInt();
} else {
id = dis.readLong();
}
-
+
RootObj root = new RootObj(RootType.JAVA_STATIC, id);
-
+
if (id == 0) {
root.mComment = String.format(
"Static field %s:%s null",
mStaticFieldNames[i]);
} else {
Instance instance = state.findReference(id);
-
+
instance.addParent(this);
-
+
root.mComment = String.format(
"Static field %s:%s %s [%s] 0x%08x",
mClassName,
// Lastly, add ourself as a subclass of our superclass
if (mSuperclassId != 0) {
ClassObj superclass = state.findClass(mSuperclassId);
-
+
superclass.addSubclass(this);
}
}
public final void setFieldNames(String[] names) {
mFieldNames = names;
}
-
+
public final void setFieldTypes(int[] types) {
mFieldTypes = types;
}
public final void setStaticFieldNames(String[] names) {
mStaticFieldNames = names;
}
-
+
public final void setStaticFieldTypes(int[] types) {
mStaticFieldTypes = types;
}
-
+
public final void setStaticFieldValues(byte[] values) {
mStaticFieldValues = values;
}
System.out.println("+---------- ClassObj dump for: " + mClassName);
System.out.println("+----- Static fields");
-
+
for (int i = 0; i < mStaticFieldNames.length; i++) {
- System.out.println(mStaticFieldNames[i] + ": "
+ System.out.println(mStaticFieldNames[i] + ": "
+ mStaticFieldTypes[i]);
}
System.out.println("+----- Instance fields");
-
+
for (int i = 0; i < mFieldNames.length; i++) {
System.out.println(mFieldNames[i] + ": " + mFieldTypes[i]);
}
if (resultSet.contains(this)) {
return;
}
-
+
if (filter != null) {
if (filter.accept(this)) {
resultSet.add(this);
} else {
resultSet.add(this);
}
-
+
ByteArrayInputStream bais =
new ByteArrayInputStream(mStaticFieldValues);
DataInputStream dis = new DataInputStream(bais);
int[] types = mStaticFieldTypes;
final int N = types.length;
State state = mHeap.mState;
-
+
/*
* Spin through the list of static fields, find all object references,
* and visit them.
for (int i = 0; i < N; i++) {
int type = types[i];
int size = Types.getTypeSize(type);
-
+
if (type == Types.OBJECT) {
long id;
-
+
if (size == 4) {
id = dis.readInt();
} else {
id = dis.readLong();
}
-
+
Instance instance = state.findReference(id);
-
+
if (instance != null) {
instance.visit(resultSet, filter);
}
if (! (o instanceof ClassObj)) {
return false;
}
-
+
return 0 == compareTo((ClassObj) o);
}
}
public class Heap {
String mName;
-
+
// List of individual stack frames
HashMap<Long, StackFrame> mFrames = new HashMap<Long, StackFrame>();
-
+
// List stack traces, which are lists of stack frames
HashMap<Integer, StackTrace> mTraces = new HashMap<Integer, StackTrace>();
-
+
// Root objects such as interned strings, jni locals, etc
ArrayList<RootObj> mRoots = new ArrayList<RootObj>();
-
+
// List of threads
HashMap<Integer, ThreadObj> mThreads = new HashMap<Integer, ThreadObj>();
public Heap(String name) {
mName = name;
}
-
+
public final void addStackFrame(StackFrame theFrame) {
mFrames.put(theFrame.mId, theFrame);
}
return mTraces.get(traceSerialNumber);
}
- public final StackTrace getStackTraceAtDepth(int traceSerialNumber,
+ public final StackTrace getStackTraceAtDepth(int traceSerialNumber,
int depth) {
StackTrace trace = mTraces.get(traceSerialNumber);
-
+
if (trace != null) {
trace = trace.fromDepth(depth);
}
-
+
return trace;
}
public final void addThread(ThreadObj thread, int serialNumber) {
mThreads.put(serialNumber, thread);
}
-
+
public final ThreadObj getThread(int serialNumber) {
return mThreads.get(serialNumber);
}
public final void addInstance(long id, Instance instance) {
mInstances.put(id, instance);
}
-
+
public final Instance getInstance(long id) {
return mInstances.get(id);
}
mClassesById.put(id, theClass);
mClassesByName.put(theClass.mClassName, theClass);
}
-
+
public final ClassObj getClass(long id) {
return mClassesById.get(id);
}
public final void dumpInstanceCounts() {
for (ClassObj theClass: mClassesById.values()) {
int count = theClass.mInstances.size();
-
+
if (count > 0) {
System.out.println(theClass + ": " + count);
}
public final void dumpSubclasses() {
for (ClassObj theClass: mClassesById.values()) {
int count = theClass.mSubclasses.size();
-
+
if (count > 0) {
System.out.println(theClass);
theClass.dumpSubclasses();
}
}
}
-
+
public final void dumpSizes() {
for (ClassObj theClass: mClassesById.values()) {
int size = 0;
-
+
for (Instance instance: theClass.mInstances) {
size += instance.getCompositeSize();
}
}
}
}
-
+
/*
* Spin through all of the class instances and link them to their
* parent class definition objects. Then have each instance resolve
String name = theClass.mClassName;
String superclassName = "none";
ClassObj superClass = mClassesById.get(theClass.mSuperclassId);
-
+
if (superClass != null) {
superclassName = superClass.mClassName;
}
-
+
theClass.addInstance(instance);
instance.resolveReferences(state);
}
private static final int ROOT_INSTANCE_DUMP = 0x21;
private static final int ROOT_OBJECT_ARRAY_DUMP = 0x22;
private static final int ROOT_PRIMITIVE_ARRAY_DUMP = 0x23;
-
+
/**
* Android format addition
*
* associated with the specified heap. The HEAP_DUMP_INFO data is reset
* at the end of the HEAP_DUMP[_SEGMENT]. Multiple HEAP_DUMP_INFO entries
* may appear in a single HEAP_DUMP[_SEGMENT].
- *
+ *
* Format:
* u1: Tag value (0xFE)
* u4: heap ID
try {
String s = readNullTerminatedString();
DataInputStream in = mInput;
-
+
mIdSize = in.readInt();
Types.setIdSize(mIdSize);
-
+
in.readLong(); // Timestamp, ignored for now
-
+
while (true) {
int tag = in.readUnsignedByte();
int timestamp = in.readInt();
case STRING_IN_UTF8:
loadString(length - 4);
break;
-
+
case LOAD_CLASS:
loadClass();
break;
loadHeapDump(length);
mState.setToDefaultHeap();
break;
-
+
case HEAP_DUMP_SEGMENT:
loadHeapDump(length);
mState.setToDefaultHeap();
}
mState.resolveReferences();
-
+
return state;
}
for (int c = in.read(); c != 0; c = in.read()) {
s.append((char) c);
}
-
+
return s.toString();
}
case 4: return ((long) mInput.readInt()) & 0x00000000ffffffffL;
case 8: return mInput.readLong();
}
-
+
throw new IllegalArgumentException("ID Length must be 1, 2, 4, or 8");
}
private String readUTF8(int length) throws IOException {
byte[] b = new byte[length];
-
+
mInput.read(b);
return new String(b, "utf-8");
private void loadString(int length) throws IOException {
long id = readId();
String string = readUTF8(length);
-
+
mStrings.put(id, string);
}
long id = readId();
int stackTrace = in.readInt(); // unused
String name = mStrings.get(readId());
-
+
mClassNames.put(id, name);
}
String sourceFile = mStrings.get(readId());
int serial = mInput.readInt();
int lineNumber = mInput.readInt();
-
- StackFrame frame = new StackFrame(id, methodName, methodSignature,
+
+ StackFrame frame = new StackFrame(id, methodName, methodSignature,
sourceFile, serial, lineNumber);
mState.addStackFrame(frame);
int threadSerialNumber = mInput.readInt();
final int numFrames = mInput.readInt();
StackFrame[] frames = new StackFrame[numFrames];
-
+
for (int i = 0; i < numFrames; i++) {
frames[i] = mState.getStackFrame(readId());
}
-
- StackTrace trace = new StackTrace(serialNumber, threadSerialNumber,
+
+ StackTrace trace = new StackTrace(serialNumber, threadSerialNumber,
frames);
mState.addStackTrace(trace);
private void loadHeapDump(int length) throws IOException {
DataInputStream in = mInput;
-
+
while (length > 0) {
int tag = in.readUnsignedByte();
length--;
-
+
switch (tag) {
case ROOT_UNKNOWN:
length -= loadBasicObj(RootType.UNKNOWN);
break;
-
+
case ROOT_JNI_GLOBAL:
length -= loadBasicObj(RootType.NATIVE_STATIC);
readId(); // ignored
length -= mIdSize;
break;
-
+
case ROOT_JNI_LOCAL:
length -= loadJniLocal();
break;
-
+
case ROOT_JAVA_FRAME:
length -= loadJavaFrame();
break;
-
+
case ROOT_NATIVE_STACK:
length -= loadNativeStack();
break;
-
+
case ROOT_STICKY_CLASS:
length -= loadBasicObj(RootType.SYSTEM_CLASS);
break;
-
+
case ROOT_THREAD_BLOCK:
length -= loadThreadBlock();
break;
-
+
case ROOT_MONITOR_USED:
length -= loadBasicObj(RootType.BUSY_MONITOR);
break;
-
+
case ROOT_THREAD_OBJECT:
length -= loadThreadObject();
break;
-
+
case ROOT_CLASS_DUMP:
length -= loadClassDump();
break;
-
+
case ROOT_INSTANCE_DUMP:
length -= loadInstanceDump();
break;
-
+
case ROOT_OBJECT_ARRAY_DUMP:
length -= loadObjectArrayDump();
break;
-
+
case ROOT_PRIMITIVE_ARRAY_DUMP:
length -= loadPrimitiveArrayDump();
break;
throw new IllegalArgumentException(
"Don't know how to load a nodata array");
-
+
case ROOT_HEAP_DUMP_INFO:
int heapId = mInput.readInt();
long heapNameId = readId();
String heapName = mStrings.get(heapNameId);
-
+
mState.setHeapTo(heapId, heapName);
length -= 4 + mIdSize;
break;
-
+
case ROOT_INTERNED_STRING:
length -= loadBasicObj(RootType.INTERNED_STRING);
break;
-
+
case ROOT_FINALIZING:
length -= loadBasicObj(RootType.FINALIZING);
break;
-
+
case ROOT_DEBUGGER:
length -= loadBasicObj(RootType.DEBUGGER);
break;
-
+
case ROOT_REFERENCE_CLEANUP:
length -= loadBasicObj(RootType.REFERENCE_CLEANUP);
break;
-
+
case ROOT_VM_INTERNAL:
length -= loadBasicObj(RootType.VM_INTERNAL);
break;
-
+
case ROOT_JNI_MONITOR:
length -= loadJniMonitor();
break;
-
+
case ROOT_UNREACHABLE:
length -= loadBasicObj(RootType.UNREACHABLE);
break;
-
+
default:
throw new IllegalArgumentException(
- "loadHeapDump loop with unknown tag " + tag
- + " with " + mInput.available()
+ "loadHeapDump loop with unknown tag " + tag
+ + " with " + mInput.available()
+ " bytes possibly remaining");
}
}
}
-
+
private int loadJniLocal() throws IOException {
long id = readId();
int threadSerialNumber = mInput.readInt();
int stackFrameNumber = mInput.readInt();
ThreadObj thread = mState.getThread(threadSerialNumber);
- StackTrace trace = mState.getStackTraceAtDepth(thread.mStackTrace,
+ StackTrace trace = mState.getStackTraceAtDepth(thread.mStackTrace,
stackFrameNumber);
- RootObj root = new RootObj(RootType.NATIVE_LOCAL, id,
+ RootObj root = new RootObj(RootType.NATIVE_LOCAL, id,
threadSerialNumber, trace);
-
+
root.setHeap(mState.mCurrentHeap);
mState.addRoot(root);
-
+
return mIdSize + 4 + 4;
}
int threadSerialNumber = mInput.readInt();
int stackFrameNumber = mInput.readInt();
ThreadObj thread = mState.getThread(threadSerialNumber);
- StackTrace trace = mState.getStackTraceAtDepth(thread.mStackTrace,
+ StackTrace trace = mState.getStackTraceAtDepth(thread.mStackTrace,
stackFrameNumber);
- RootObj root = new RootObj(RootType.JAVA_LOCAL, id, threadSerialNumber,
+ RootObj root = new RootObj(RootType.JAVA_LOCAL, id, threadSerialNumber,
trace);
-
+
root.setHeap(mState.mCurrentHeap);
mState.addRoot(root);
-
+
return mIdSize + 4 + 4;
}
-
+
private int loadNativeStack() throws IOException {
long id = readId();
int threadSerialNumber = mInput.readInt();
ThreadObj thread = mState.getThread(threadSerialNumber);
StackTrace trace = mState.getStackTrace(thread.mStackTrace);
- RootObj root = new RootObj(RootType.NATIVE_STACK, id,
+ RootObj root = new RootObj(RootType.NATIVE_STACK, id,
threadSerialNumber, trace);
-
+
root.setHeap(mState.mCurrentHeap);
mState.addRoot(root);
-
+
return mIdSize + 4;
}
private int loadBasicObj(RootType type) throws IOException {
long id = readId();
RootObj root = new RootObj(type, id);
-
+
root.setHeap(mState.mCurrentHeap);
mState.addRoot(root);
-
+
return mIdSize;
}
int threadSerialNumber = mInput.readInt();
ThreadObj thread = mState.getThread(threadSerialNumber);
StackTrace stack = mState.getStackTrace(thread.mStackTrace);
- RootObj root = new RootObj(RootType.THREAD_BLOCK, id,
+ RootObj root = new RootObj(RootType.THREAD_BLOCK, id,
threadSerialNumber, stack);
-
+
root.setHeap(mState.mCurrentHeap);
mState.addRoot(root);
-
+
return mIdSize + 4;
}
int threadSerialNumber = mInput.readInt();
int stackSerialNumber = mInput.readInt();
ThreadObj thread = new ThreadObj(id, stackSerialNumber);
-
+
mState.addThread(thread, threadSerialNumber);
-
+
return mIdSize + 4 + 4;
}
// Skip over the constant pool
int numEntries = in.readUnsignedShort();
bytesRead += 2;
-
+
for (int i = 0; i < numEntries; i++) {
in.readUnsignedShort();
bytesRead += 2 + skipValue();
int[] staticFieldTypes = new int[numEntries];
ByteArrayOutputStream staticFieldValues = new ByteArrayOutputStream();
byte[] buffer = mFieldBuffer;
-
+
for (int i = 0; i < numEntries; i++) {
staticFieldNames[i] = mStrings.get(readId());
bytesRead += mIdSize + 1 + fieldSize;
}
-
+
// Instance fields
numEntries = in.readUnsignedShort();
bytesRead += 2;
-
+
String[] names = new String[numEntries];
int[] types = new int[numEntries];
-
+
for (int i = 0; i < numEntries; i++) {
long fieldName = readId();
int type = in.readUnsignedByte();
bytesRead += mIdSize + 1;
}
-
+
ClassObj theClass = new ClassObj(id, stack, mClassNames.get(id));
theClass.setStaticFieldNames(staticFieldNames);
theClass.setFieldNames(names);
theClass.setFieldTypes(types);
theClass.setSize(instanceSize);
-
+
theClass.setHeap(mState.mCurrentHeap);
mState.addClass(id, theClass);
-
+
return bytesRead;
}
instance.loadFieldData(mInput, remaining);
instance.setHeap(mState.mCurrentHeap);
mState.addInstance(id, instance);
-
+
return mIdSize + 4 + mIdSize + 4 + remaining;
}
int totalBytes = numElements * mIdSize;
byte[] data = new byte[totalBytes];
String className = mClassNames.get(classId);
-
+
mInput.readFully(data);
- ArrayInstance array = new ArrayInstance(id, stack, Types.OBJECT,
+ ArrayInstance array = new ArrayInstance(id, stack, Types.OBJECT,
numElements, data);
-
+
array.mClassId = classId;
array.setHeap(mState.mCurrentHeap);
mState.addInstance(id, array);
return mIdSize + 4 + 4 + mIdSize + totalBytes;
}
-
+
private int loadPrimitiveArrayDump() throws IOException {
long id = readId();
int stackId = mInput.readInt();
int size = Types.getTypeSize(type);
int totalBytes = numElements * size;
byte[] data = new byte[totalBytes];
-
+
mInput.readFully(data);
- ArrayInstance array = new ArrayInstance(id, stack, type, numElements,
+ ArrayInstance array = new ArrayInstance(id, stack, type, numElements,
data);
-
+
array.setHeap(mState.mCurrentHeap);
mState.addInstance(id, array);
-
+
return mIdSize + 4 + 4 + 1 + totalBytes;
}
int threadSerialNumber = mInput.readInt();
int stackDepth = mInput.readInt();
ThreadObj thread = mState.getThread(threadSerialNumber);
- StackTrace trace = mState.getStackTraceAtDepth(thread.mStackTrace,
+ StackTrace trace = mState.getStackTraceAtDepth(thread.mStackTrace,
stackDepth);
- RootObj root = new RootObj(RootType.NATIVE_MONITOR, id,
+ RootObj root = new RootObj(RootType.NATIVE_MONITOR, id,
threadSerialNumber, trace);
-
+
root.setHeap(mState.mCurrentHeap);
mState.addRoot(root);
-
+
return mIdSize + 4 + 4;
}
private int skipValue() throws IOException {
int type = mInput.readUnsignedByte();
int size = Types.getTypeSize(type);
-
+
skipFully(size);
return size + 1;
private void skipFully(long numBytes) throws IOException {
while (numBytes > 0) {
long skipped = mInput.skip(numBytes);
-
+
numBytes -= skipped;
}
}
// Id of the ClassObj of which this object is an instance
long mClassId;
-
+
// The stack in which this object was allocated
StackTrace mStack;
-
+
// The heap in which this object was allocated (app, zygote, etc)
Heap mHeap;
// List of all objects that hold a live reference to this object
private ArrayList<Instance> mParents;
-
+
/*
* After the whole HPROF file is read and parsed this method will be
* called on all heap objects so that they can resolve their internal
public final int getCompositeSize() {
HashSet<Instance> set = new HashSet<Instance>();
-
+
visit(set, null);
-
+
int size = 0;
-
+
for (Instance instance: set) {
size += instance.getSize();
}
-
+
return size;
}
public void setHeap(Heap heap) {
mHeap = heap;
}
-
+
// Add to the list of objects that have a hard reference to this Instance
public void addParent(Instance parent) {
if (mParents == null) {
mParents = new ArrayList<Instance>();
}
-
+
mParents.add(parent);
}
-
+
public ArrayList<Instance> getParents() {
if (mParents == null) {
mParents = new ArrayList<Instance>();
}
-
+
return mParents;
}
* a String describing the reference in detail.
*/
public String describeReferenceTo(long id) {
- return "No reference to 0x" + Long.toHexString(id);
+ return "No reference to 0x" + Long.toHexString(id);
}
}
FileInputStream fis;
BufferedInputStream bis;
DataInputStream dis;
-
+
try {
fis = new FileInputStream(argv[0]);
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
-
+
State state = (new HprofParser(dis)).parse();
dis.close();
-
+
testClassesQuery(state);
testAllClassesQuery(state);
testFindInstancesOf(state);
"javax.",
"org.xml.sax"
};
-
+
Map<String, Set<ClassObj>> someClasses = Queries.classes(state, x);
-
+
for (String thePackage: someClasses.keySet()) {
System.out.println("------------------- " + thePackage);
-
+
Set<ClassObj> classes = someClasses.get(thePackage);
-
+
for (ClassObj theClass: classes) {
System.out.println(" " + theClass.mClassName);
}
}
}
-
+
private static void testAllClassesQuery(State state) {
Map<String, Set<ClassObj>> allClasses = Queries.allClasses(state);
-
+
for (String thePackage: allClasses.keySet()) {
System.out.println("------------------- " + thePackage);
-
+
Set<ClassObj> classes = allClasses.get(thePackage);
-
+
for (ClassObj theClass: classes) {
System.out.println(" " + theClass.mClassName);
}
private static void testFindInstancesOf(State state) {
Instance[] instances = Queries.instancesOf(state, "java.lang.String");
-
+
System.out.println("There are " + instances.length + " Strings.");
}
private static void testFindAllInstancesOf(State state) {
- Instance[] instances = Queries.allInstancesOf(state,
+ Instance[] instances = Queries.allInstancesOf(state,
"android.graphics.drawable.Drawable");
-
+
System.out.println("There are " + instances.length
+ " instances of Drawables and its subclasses.");
}
public class Queries {
/*
- * NOTES: Here's a list of the queries that can be done in hat and
+ * NOTES: Here's a list of the queries that can be done in hat and
* how you'd perform a similar query here in hit:
*
* hat hit
return classes(state, null);
}
- public static Map<String, Set<ClassObj>> classes(State state,
+ public static Map<String, Set<ClassObj>> classes(State state,
String[] excludedPrefixes) {
TreeMap<String, Set<ClassObj>> result =
new TreeMap<String, Set<ClassObj>>();
for (Heap heap: state.mHeaps.values()) {
classes.addAll(heap.mClassesById.values());
}
-
+
// Filter it if needed
if (excludedPrefixes != null) {
final int N = excludedPrefixes.length;
Iterator<ClassObj> iter = classes.iterator();
-
+
while (iter.hasNext()) {
ClassObj theClass = iter.next();
String classPath = theClass.toString();
-
+
for (int i = 0; i < N; i++) {
if (classPath.startsWith(excludedPrefixes[i])) {
iter.remove();
}
}
}
-
+
// Now that we have a final list of classes, group them by package
for (ClassObj theClass: classes) {
String packageName = DEFAULT_PACKAGE;
int lastDot = theClass.mClassName.lastIndexOf('.');
-
+
if (lastDot != -1) {
packageName = theClass.mClassName.substring(0, lastDot);
}
-
+
Set<ClassObj> classSet = result.get(packageName);
-
+
if (classSet == null) {
classSet = new TreeSet<ClassObj>();
result.put(packageName, classSet);
}
-
+
classSet.add(theClass);
}
-
+
return result;
}
-
+
/*
* It's sorta sad that this is a pass-through call, but it seems like
* having all of the hat-like query methods in one place is a good thing
*/
public static Instance[] instancesOf(State state, String baseClassName) {
ClassObj theClass = state.findClass(baseClassName);
-
+
if (theClass == null) {
throw new IllegalArgumentException("Class not found: "
+ baseClassName);
}
-
+
Instance[] instances = new Instance[theClass.mInstances.size()];
-
+
return theClass.mInstances.toArray(instances);
}
*/
public static Instance[] allInstancesOf(State state, String baseClassName) {
ClassObj theClass = state.findClass(baseClassName);
-
+
if (theClass == null) {
throw new IllegalArgumentException("Class not found: "
+ baseClassName);
}
ArrayList<ClassObj> classList = new ArrayList<ClassObj>();
-
+
classList.add(theClass);
classList.addAll(traverseSubclasses(theClass));
-
+
ArrayList<Instance> instanceList = new ArrayList<Instance>();
-
+
for (ClassObj someClass: classList) {
instanceList.addAll(someClass.mInstances);
}
-
+
Instance[] result = new Instance[instanceList.size()];
-
+
instanceList.toArray(result);
-
+
return result;
}
-
+
private static ArrayList<ClassObj> traverseSubclasses(ClassObj base) {
ArrayList<ClassObj> result = new ArrayList<ClassObj>();
-
+
for (ClassObj subclass: base.mSubclasses) {
result.add(subclass);
result.addAll(traverseSubclasses(subclass));
}
-
+
return result;
}
*/
public static Instance findObject(State state, String id) {
long id2 = Long.parseLong(id, 16);
-
+
return state.findReference(id2);
}
public static Collection<RootObj> getRoots(State state) {
HashSet<RootObj> result = new HashSet<RootObj>();
-
+
for (Heap heap: state.mHeaps.values()) {
result.addAll(heap.mRoots);
}
-
+
return result;
}
public static final Instance[] newInstances(State older, State newer) {
ArrayList<Instance> resultList = new ArrayList<Instance>();
-
+
for (Heap newHeap: newer.mHeaps.values()) {
Heap oldHeap = older.getHeap(newHeap.mName);
-
+
if (oldHeap == null) {
continue;
}
-
+
for (Instance instance: newHeap.mInstances.values()) {
Instance oldInstance = oldHeap.getInstance(instance.mId);
-
+
/*
* If this instance wasn't in the old heap, or was there,
* but that ID was for an obj of a different type, then we have
}
}
}
-
+
Instance[] resultArray = new Instance[resultList.size()];
-
+
return resultList.toArray(resultArray);
}
}
public RootObj(RootType type, long id) {
this(type, id, 0, null);
}
-
+
public RootObj(RootType type, long id, int thread, StackTrace stack) {
mType = type;
mId = id;
public final String getClassName(State state) {
ClassObj theClass;
-
+
if (mType == RootType.SYSTEM_CLASS) {
theClass = state.findClass(mId);
} else {
if (theClass == null) {
return "no class defined!!";
}
-
+
return theClass.mClassName;
}
@Override
public final int getSize() {
Instance instance = null;
-
+
if (mType == RootType.SYSTEM_CLASS) {
instance = mHeap.mState.findClass(mId);
} else {
instance = mHeap.mState.findReference(mId);
}
-
+
if (instance == null) {
return 0;
}
-
+
return instance.getSize();
}
if (resultSet.contains(this)) {
return;
}
-
+
if (filter != null) {
if (filter.accept(this)) {
resultSet.add(this);
JAVA_LOCAL (14, "java local"),
NATIVE_STACK (15, "native stack"),
JAVA_STATIC (16, "java static");
-
+
private final int mType;
private final String mName;
-
+
RootType(int type, String name) {
mType = type;
mName = name;
}
-
+
public final int getType() {
return mType;
}
-
+
public final String getName() {
return mName;
}
public static final int UNKNOWN_LOCATION = -1;
public static final int COMPILED_METHOD = -2;
public static final int NATIVE_METHOD = -3;
-
+
long mId;
String mMethodName;
String mSignature;
int mSerialNumber;
int mLineNumber;
- public StackFrame(long id, String method, String sig, String file,
+ public StackFrame(long id, String method, String sig, String file,
int serial, int line) {
mId = id;
mMethodName = method;
case UNKNOWN_LOCATION: return "Unknown line number";
case COMPILED_METHOD: return "Compiled method";
case NATIVE_METHOD: return "Native method";
-
+
default: return String.valueOf(mLineNumber);
}
}
public final String toString() {
- return mMethodName
- + mSignature.replace('/', '.')
- + " - "
- + mFilename + ":"
+ return mMethodName
+ + mSignature.replace('/', '.')
+ + " - "
+ + mFilename + ":"
+ lineNumberString();
}
}
int mOffset = 0;
private StackTrace() {
-
+
}
-
+
public StackTrace(int serial, int thread, StackFrame[] frames) {
mSerialNumber = serial;
mThreadSerialNumber = thread;
public final StackTrace fromDepth(int startingDepth) {
StackTrace result = new StackTrace();
-
+
if (mParent != null) {
result.mParent = mParent;
} else {
result.mParent = this;
}
-
+
result.mOffset = startingDepth + mOffset;
-
+
return result;
}
-
+
public final void dump() {
final int N = mFrames.length;
-
+
for (int i = 0; i < N; i++) {
System.out.println(mFrames[i].toString());
}
public Heap setHeapTo(int id, String name) {
Heap heap = mHeaps.get(id);
-
+
if (heap == null) {
heap = new Heap(name);
heap.mState = this;
mHeaps.put(id, heap);
}
-
+
mCurrentHeap = heap;
return mCurrentHeap;
public Heap getHeap(int id) {
return mHeaps.get(id);
}
-
+
public Heap getHeap(String name) {
for (Heap heap: mHeaps.values()) {
if (heap.mName.equals(name)) {
return heap;
}
}
-
+
return null;
}
public final void addStackFrame(StackFrame theFrame) {
mCurrentHeap.addStackFrame(theFrame);
}
-
+
public final StackFrame getStackFrame(long id) {
return mCurrentHeap.getStackFrame(id);
}
-
+
public final void addStackTrace(StackTrace theTrace) {
mCurrentHeap.addStackTrace(theTrace);
}
-
+
public final StackTrace getStackTrace(int traceSerialNumber) {
return mCurrentHeap.getStackTrace(traceSerialNumber);
}
-
- public final StackTrace getStackTraceAtDepth(int traceSerialNumber,
+
+ public final StackTrace getStackTraceAtDepth(int traceSerialNumber,
int depth) {
return mCurrentHeap.getStackTraceAtDepth(traceSerialNumber, depth);
}
-
+
public final void addRoot(RootObj root) {
mCurrentHeap.addRoot(root);
}
-
+
public final void addThread(ThreadObj thread, int serialNumber) {
mCurrentHeap.addThread(thread, serialNumber);
}
-
+
public final ThreadObj getThread(int serialNumber) {
return mCurrentHeap.getThread(serialNumber);
}
-
+
public final void addInstance(long id, Instance instance) {
mCurrentHeap.addInstance(id, instance);
}
-
+
public final void addClass(long id, ClassObj theClass) {
mCurrentHeap.addClass(id, theClass);
}
public final Instance findReference(long id) {
for (Heap heap: mHeaps.values()) {
Instance instance = heap.getInstance(id);
-
+
if (instance != null) {
return instance;
}
}
-
+
// Couldn't find an instance of a class, look for a class object
return findClass(id);
}
-
+
public final ClassObj findClass(long id) {
for (Heap heap: mHeaps.values()) {
ClassObj theClass = heap.getClass(id);
-
+
if (theClass != null) {
return theClass;
}
}
-
+
return null;
}
-
+
public final ClassObj findClass(String name) {
for (Heap heap: mHeaps.values()) {
ClassObj theClass = heap.getClass(name);
-
+
if (theClass != null) {
return theClass;
}
}
-
+
return null;
}
-
+
public final void dumpInstanceCounts() {
for (Heap heap: mHeaps.values()) {
System.out.println(
heap.dumpInstanceCounts();
}
}
-
+
public final void dumpSizes() {
for (Heap heap: mHeaps.values()) {
System.out.println(
heap.dumpSubclasses();
}
}
-
+
public final void resolveReferences() {
for (Heap heap: mHeaps.values()) {
heap.resolveInstanceRefs(this);
case 'S': return 2; // short
case 'I': return 4; // int
case 'J': return 8; // long
-
+
case OBJECT: return mIdSize;
case BOOLEAN: return 1;
case CHAR: return 2;
case INT: return 4;
case LONG: return 8;
}
-
+
throw new IllegalArgumentException("Illegal type signature: " + type);
}
-
+
public static final String getTypeName(int type) {
switch (type) {
case '[': return "array";
case 'S': return "short";
case 'I': return "int";
case 'J': return "long";
-
+
case OBJECT: return "object";
case BOOLEAN: return "boolean";
case CHAR: return "char";
case INT: return "int";
case LONG: return "long";
}
-
+
throw new IllegalArgumentException("Illegal type signature: " + type);
}
}
if (len < 5) {
if (!quiet) {
- fprintf(stderr,
+ fprintf(stderr,
"ERROR: filename must end in .dex, .zip, .jar, or .apk\n");
}
result = kUTFRBadArgs;
}
result = dexUnzipToFile(fileName, tempFileName, quiet);
-
+
if (result == kUTFRSuccess) {
//printf("+++ Good unzip to '%s'\n", tempFileName);
fileName = tempFileName;
#include "DexCatch.h"
-/* Get the first handler offset for the given DexCode.
+/* Get the first handler offset for the given DexCode.
* It's not 0 because the handlers list is prefixed with its size
* (in entries) as a uleb128. */
u4 dexGetFirstHandlerOffset(const DexCode* pCode) {
if (pCode->triesSize == 0) {
return 0;
}
-
+
const u1* baseData = dexGetCatchHandlerData(pCode);
const u1* data = baseData;
u4 address; /* handler address */
} DexCatchHandler;
-/* Get the first handler offset for the given DexCode.
+/* Get the first handler offset for the given DexCode.
* It's not 0 because the handlers list is prefixed with its size
* (in entries) as a uleb128. */
u4 dexGetFirstHandlerOffset(const DexCode* pCode);
{
dexCatchIteratorInitToPointer(pIterator,
dexGetCatchHandlerData(pCode) + offset);
-}
+}
/* Get the next item from a DexCatchIterator. Returns NULL if at end. */
DEX_INLINE DexCatchHandler* dexCatchIteratorNext(DexCatchIterator* pIterator) {
* found. Returns false if there is no applicable handler. */
DEX_INLINE bool dexFindCatchHandler(DexCatchIterator *pIterator,
const DexCode* pCode, u4 address) {
- u2 triesSize = pCode->triesSize;
+ u2 triesSize = pCode->triesSize;
int offset = -1;
// Short-circuit the overwhelmingly common cases.
if (address < start) {
break;
}
-
+
u4 end = start + tries[0].insnCount;
if (address >= end) {
break;
}
-
+
offset = tries[0].handlerOff;
break;
}
dexCatchIteratorInit(pIterator, pCode, offset);
return true;
}
-}
+}
#endif
/* Read and verify an encoded_field. This updates the
* given data pointer to point past the end of the read data and
* returns an "okay" flag (that is, false == failure).
- *
+ *
* The lastIndex value should be set to 0 before the first field in
* a list is read. It is updated as fields are read and used in the
* decode process.
- *
+ *
* The verification done by this function is of the raw data format
* only; it does not verify that access flags or indices
* are valid. */
/* Read and verify an encoded_method. This updates the
* given data pointer to point past the end of the read data and
* returns an "okay" flag (that is, false == failure).
- *
+ *
* The lastIndex value should be set to 0 before the first method in
* a list is read. It is updated as fields are read and used in the
* decode process.
* must subsequently be free()d. This function returns NULL if there
* was trouble parsing the data. If this function is passed NULL, it
* returns an initialized empty DexClassData structure.
- *
+ *
* The verification done by this function is of the raw data format
* only; it does not verify that access flags, indices, or offsets
* are valid. */
memset(result, 0, sizeof(*result));
return result;
}
-
+
if (! dexReadAndVerifyClassDataHeader(pData, pLimit, &header)) {
return NULL;
}
} else {
result->staticFields = NULL;
}
-
+
if (header.instanceFieldsSize != 0) {
result->instanceFields = (DexField*) ptr;
ptr += header.instanceFieldsSize * sizeof(DexField);
} else {
result->instanceFields = NULL;
}
-
+
if (header.directMethodsSize != 0) {
result->directMethods = (DexMethod*) ptr;
ptr += header.directMethodsSize * sizeof(DexMethod);
} else {
result->directMethods = NULL;
}
-
+
if (header.virtualMethodsSize != 0) {
result->virtualMethods = (DexMethod*) ptr;
} else {
okay = dexReadAndVerifyClassDataMethod(pData, pLimit,
&result->directMethods[i], &lastIndex);
}
-
+
lastIndex = 0;
for (i = 0; okay && (i < header.virtualMethodsSize); i++) {
okay = dexReadAndVerifyClassDataMethod(pData, pLimit,
/* Read and verify an encoded_field. This updates the
* given data pointer to point past the end of the read data and
* returns an "okay" flag (that is, false == failure).
- *
+ *
* The lastIndex value should be set to 0 before the first field in
* a list is read. It is updated as fields are read and used in the
* decode process.
- *
+ *
* The verification done by this function is of the raw data format
* only; it does not verify that access flags or indices
* are valid. */
/* Read and verify an encoded_method. This updates the
* given data pointer to point past the end of the read data and
* returns an "okay" flag (that is, false == failure).
- *
+ *
* The lastIndex value should be set to 0 before the first method in
* a list is read. It is updated as fields are read and used in the
* decode process.
* must subsequently be free()d. This function returns NULL if there
* was trouble parsing the data. If this function is passed NULL, it
* returns an initialized empty DexClassData structure.
- *
+ *
* The verification done by this function is of the raw data format
* only; it does not verify that access flags, indices, or offsets
* are valid. */
}
/* Read an encoded_field without verification. This updates the
- * given data pointer to point past the end of the read data.
- *
+ * given data pointer to point past the end of the read data.
+ *
* The lastIndex value should be set to 0 before the first field in
* a list is read. It is updated as fields are read and used in the
* decode process.
}
/* Read an encoded_method without verification. This updates the
- * given data pointer to point past the end of the read data.
- *
+ * given data pointer to point past the end of the read data.
+ *
* The lastIndex value should be set to 0 before the first method in
* a list is read. It is updated as fields are read and used in the
* decode process.
* character (U+00a0, U+2000..U+200f, U+2028..U+202f,
* U+fff0..U+ffff).
*/
-
+
u2 utf16 = dexGetUtf16FromUtf8(pUtf8Ptr);
// Perform follow-up tests based on the high 8 bits.
/* Return whether the given string is a valid field or method name. */
bool dexIsValidMemberName(const char* s) {
bool angleName = false;
-
+
switch (*s) {
case '\0': {
// The empty string is not a valid name.
// Arrays may have no more than 255 dimensions.
return false;
}
-
+
switch (*(s++)) {
- case 'B':
+ case 'B':
case 'C':
case 'D':
case 'F':
pClassDef = dexGetClassDef(pDexFile, i);
pString = dexStringByTypeIdx(pDexFile, pClassDef->classIdx);
- classLookupAdd(pDexFile, pLookup,
+ classLookupAdd(pDexFile, pLookup,
(u1*)pString - pDexFile->baseAddr,
(u1*)pClassDef - pDexFile->baseAddr, &numProbes);
if (pLookup->table[idx].classDescriptorHash == hash) {
const char* str;
-
+
str = (const char*) (pDexFile->baseAddr + offset);
if (strcmp(str, descriptor) == 0) {
return (const DexClassDef*)
* Reads a string index as encoded for the debug info format,
* returning a string pointer or NULL as appropriate.
*/
-static const char* readStringIdx(const DexFile* pDexFile,
+static const char* readStringIdx(const DexFile* pDexFile,
const u1** pStream) {
u4 stringIdx = readUnsignedLeb128(pStream);
* Reads a type index as encoded for the debug info format, returning
* a string pointer for its descriptor or NULL as appropriate.
*/
-static const char* readTypeIdx(const DexFile* pDexFile,
+static const char* readTypeIdx(const DexFile* pDexFile,
const u1** pStream) {
u4 typeIdx = readUnsignedLeb128(pStream);
bool live;
} LocalInfo;
-static void emitLocalCbIfLive (void *cnxt, int reg, u4 endAddress,
+static void emitLocalCbIfLive (void *cnxt, int reg, u4 endAddress,
LocalInfo *localInReg, DexDebugNewLocalCb localCb)
{
if (localCb != NULL && localInReg[reg].live) {
localCb(cnxt, reg, localInReg[reg].startAddress, endAddress,
- localInReg[reg].name,
- localInReg[reg].descriptor,
- localInReg[reg].signature == NULL
+ localInReg[reg].name,
+ localInReg[reg].descriptor,
+ localInReg[reg].signature == NULL
? "" : localInReg[reg].signature );
}
}
} else {
assert(pCode->insSize == dexProtoComputeArgsSize(&proto));
}
-
+
DexParameterIterator iterator;
dexParameterIteratorInit(&iterator, &proto);
const char* descriptor = dexParameterIteratorNextDescriptor(&iterator);
const char *name;
int reg;
-
+
if ((argReg >= pCode->registersSize) || (descriptor == NULL)) {
goto invalid_stream;
}
case DBG_ADVANCE_PC:
address += readUnsignedLeb128(&stream);
break;
-
+
case DBG_ADVANCE_LINE:
line += readSignedLeb128(&stream);
break;
if (reg > pCode->registersSize) goto invalid_stream;
// Emit what was previously there, if anything
- emitLocalCbIfLive (cnxt, reg, address,
+ emitLocalCbIfLive (cnxt, reg, address,
localInReg, localCb);
localInReg[reg].name = readStringIdx(pDexFile, &stream);
localInReg[reg].descriptor = readTypeIdx(pDexFile, &stream);
if (opcode == DBG_START_LOCAL_EXTENDED) {
- localInReg[reg].signature
+ localInReg[reg].signature
= readStringIdx(pDexFile, &stream);
} else {
localInReg[reg].signature = NULL;
reg = readUnsignedLeb128(&stream);
if (reg > pCode->registersSize) goto invalid_stream;
- if (localInReg[reg].name == NULL
+ if (localInReg[reg].name == NULL
|| localInReg[reg].descriptor == NULL) {
goto invalid_stream;
}
line += DBG_LINE_BASE + (adjopcode % DBG_LINE_RANGE);
if (posCb != NULL) {
- int done;
+ int done;
done = posCb(cnxt, address, line);
if (done) {
/*
* access flags and masks; the "standard" ones are all <= 0x4000
- *
+ *
* Note: There are related declarations in vm/oo/Object.h in the ClassFlags
* enum.
*/
ACC_CONSTRUCTOR = 0x00010000, // method (Dalvik only)
ACC_DECLARED_SYNCHRONIZED =
0x00020000, // method (Dalvik only)
- ACC_CLASS_MASK =
+ ACC_CLASS_MASK =
(ACC_PUBLIC | ACC_FINAL | ACC_INTERFACE | ACC_ABSTRACT
| ACC_SYNTHETIC | ACC_ANNOTATION | ACC_ENUM),
ACC_INNER_CLASS_MASK =
if ((((u4) insnsEnd) & 3) != 0) {
insnsEnd++;
}
-
+
return (const DexTry*) insnsEnd;
}
/*
* Decode debug info for method.
- *
+ *
* posCb is called in ascending address order.
* localCb is called in order of ascending end address.
*/
* ===========================================================================
* Method Prototypes
* ===========================================================================
- */
+ */
/*
* Return the DexProtoId from the given DexProto. The DexProto must
}
length += strlen(dexStringByTypeIdx(dexFile, protoId->returnTypeIdx));
-
+
dexStringCacheAlloc(pCache, length);
char *at = (char*) pCache->value;
length += strlen(descriptor);
}
-
+
dexParameterIteratorInit(&iterator, pProto);
dexStringCacheAlloc(pCache, length);
// Compare return types.
if (compareReturnType) {
- int result =
+ int result =
strcmp(dexStringByTypeIdx(dexFile1, protoId1->returnTypeIdx),
dexStringByTypeIdx(dexFile2, protoId2->returnTypeIdx));
}
// Compare parameters.
-
+
int minParam = (paramCount1 > paramCount2) ? paramCount2 : paramCount1;
int i;
for (i = 0; i < minParam; i++) {
u4 idx1 = dexTypeListGetIdx(typeList1, i);
u4 idx2 = dexTypeListGetIdx(typeList2, i);
- int result =
+ int result =
strcmp(dexStringByTypeIdx(dexFile1, idx1),
dexStringByTypeIdx(dexFile2, idx2));
if (result == NULL) {
return NULL;
}
-
+
// The return type is the character just past the ')'.
return result + 1;
}
while (*descriptor == '[') {
descriptor++;
}
-
+
switch (*descriptor) {
case 'B': case 'C': case 'D': case 'F':
case 'I': case 'J': case 'S': case 'Z': {
const char* descriptor) {
// First compare the return types.
- int result = strcmp(dexProtoGetReturnType(proto),
+ int result = strcmp(dexProtoGetReturnType(proto),
methodDescriptorReturnType(descriptor));
if (result != 0) {
// Skip the '('.
assert (*descriptor == '(');
descriptor++;
-
+
for (;;) {
const char* protoDesc = dexParameterIteratorNextDescriptor(&iterator);
}
// Both prototype and descriptor have arguments. Compare them.
-
+
const char* nextDesc = methodDescriptorNextType(descriptor);
for (;;) {
break;
}
}
-
+
/*
* If we made it here, the two arguments matched, and
* descriptor == nextDesc.
* ===========================================================================
* Parameter Iterators
* ===========================================================================
- */
+ */
/*
* Initialize the given DexParameterIterator to be at the start of the
pDec->vB = INST_B(inst);
break;
case kFmt11n: // op vA, #+B
- pDec->vA = INST_A(inst);
+ pDec->vA = INST_A(inst);
pDec->vB = (s4) (INST_B(inst) << 28) >> 28; // sign extend 4-bit value
break;
case kFmt11x: // op vAA
* (This defines InstructionFormat as an unsigned char to reduce the size
* of the table. This isn't necessary with some compilers, which use an
* integer width appropriate for the number of enum values.)
- *
+ *
* If you add or delete a format, you have to change some or all of:
* - this enum
* - the switch inside dexDecodeInstruction() in InstrUtils.c
* and running int:fast as above
* - repeat for other platforms (x86, ...)
* (see notes in mterp/ReadMe.txt for rebuilding instructions)
- *
+ *
* Verifier / optimizer:
* - update some stuff in analysis/DexOptimize.c, analysis/DexVerify.c,
* and/or analysis/CodeVerify.c as needed
* - verify by running with verifier enabled (it's on by default)
- *
+ *
* Tools:
* - update the OpCodeNames table in dexdump/OpCodeNames.c
* - update dexdump/DexDump.c if an instruction format has changed
- *
+ *
* Note: The Dalvik VM tests (in the tests subdirectory) provide a convenient
* way to test most of the above without doing any rebuilds. In particular,
* test 003-omnibus-opcodes will exercise most of the opcodes.
OP_NEW_INSTANCE = 0x22,
OP_NEW_ARRAY = 0x23,
-
+
OP_FILLED_NEW_ARRAY = 0x24,
OP_FILLED_NEW_ARRAY_RANGE = 0x25,
OP_FILL_ARRAY_DATA = 0x26,
-
+
OP_THROW = 0x27,
OP_GOTO = 0x28,
OP_GOTO_16 = 0x29,
OP_GOTO_32 = 0x2a,
OP_PACKED_SWITCH = 0x2b,
OP_SPARSE_SWITCH = 0x2c,
-
+
OP_CMPL_FLOAT = 0x2d,
OP_CMPG_FLOAT = 0x2e,
OP_CMPL_DOUBLE = 0x2f,
OP_UNUSED_41 = 0x41,
OP_UNUSED_42 = 0x42,
OP_UNUSED_43 = 0x43,
-
+
OP_AGET = 0x44,
OP_AGET_WIDE = 0x45,
OP_AGET_OBJECT = 0x46,
OP_INVOKE_INTERFACE = 0x72,
OP_UNUSED_73 = 0x73,
-
+
OP_INVOKE_VIRTUAL_RANGE = 0x74,
OP_INVOKE_SUPER_RANGE = 0x75,
OP_INVOKE_DIRECT_RANGE = 0x76,
*/
static u2 get2LE(unsigned char const* pSrc)
{
- return pSrc[0] | (pSrc[1] << 8);
+ return pSrc[0] | (pSrc[1] << 8);
}
/*
100% Public Domain
-----------------
-Modified 7/98
+Modified 7/98
By James H. Brown <jbrown@burgoyne.com>
Still 100% Public Domain
*/
jobject jniCreateFileDescriptor(C_JNIEnv* env, int fd);
-/*
+/*
* Get an int file descriptor from a java.io.FileDescriptor
*/
int jniGetFDFromFileDescriptor(C_JNIEnv* env, jobject fileDescriptor);
JNIWeakGlobalRefType = 3
} jobjectRefType;
-typedef struct {
- const char* name;
- const char* signature;
- void* fnPtr;
+typedef struct {
+ const char* name;
+ const char* signature;
+ void* fnPtr;
} JNINativeMethod;
struct _JNIEnv;
void* reserved0;
void* reserved1;
void* reserved2;
-
+
jint (*DestroyJavaVM)(JavaVM*);
jint (*AttachCurrentThread)(JavaVM*, JNIEnv**, void*);
jint (*DetachCurrentThread)(JavaVM*);
# (1) The IO tests create lots of files in the current directory, so we change
# to /tmp first.
# (2) Some of the core tests need a hell of a lot of memory, so we use a
-# large value for both heap and stack.
+# large value for both heap and stack.
rm -rf ${datadir}/xml_source
mkdir -p ${datadir}/xml_source
if (args.length != 0) {
millis = Integer.parseInt(args[0]);
}
-
+
System.out.println("Sleeping " + millis + " msec...");
long start = System.currentTimeMillis();
} catch (VerifyError ve) {
System.out.println("Caught (retry): " + ve);
}
-
+
try {
UnresTest2.run();
} catch (VerifyError ve) {
static private void printAnnotationArray(String prefix, Annotation[] arr) {
TreeMap<String, Annotation> sorted =
new TreeMap<String, Annotation>();
-
+
for (Annotation a : arr) {
sorted.put(a.annotationType().getName(), a);
}
System.out.println(prefix + " " + a.annotationType());
}
}
-
+
static void printAnnotations(Class clazz) {
Annotation[] annos;
Annotation[][] parAnnos;
Method meth;
ExportedProperty property;
final IntToString[] mapping;
-
+
try {
meth = TestAnnotations.class.getMethod("getFocusType",
(Class[])null);
assertEquals(null, expected, actual);
}
/**
- * Asserts that two Strings are equal.
+ * Asserts that two Strings are equal.
*/
static public void assertEquals(String message, String expected, String actual) {
if (expected == null && actual == null)
throw new ComparisonFailure(message, expected, actual);
}
/**
- * Asserts that two Strings are equal.
+ * Asserts that two Strings are equal.
*/
static public void assertEquals(String expected, String actual) {
assertEquals(null, expected, actual);
/**
* Thrown when an assert equals for Strings failed.
- *
+ *
* Inspired by a patch from Alex Chaffee mailto:alex@purpletech.com
*/
public class ComparisonFailure extends AssertionFailedError {
fExpected= expected;
fActual= actual;
}
-
+
/**
* Returns "..." in place of common prefix and "..." in
* place of common suffix between expected and actual.
- *
+ *
* @see java.lang.Throwable#getMessage()
*/
public String getMessage() {
if (fExpected == null || fActual == null)
return Assert.format(super.getMessage(), fExpected, fActual);
-
+
int end= Math.min(fExpected.length(), fActual.length());
-
+
int i= 0;
for(; i < end; i++) {
if (fExpected.charAt(i) != fActual.charAt(i))
break;
}
String actual, expected;
-
+
// equal strings
if (j < i && k < i) {
expected= fExpected;
expected= "..."+expected;
actual= "..."+actual;
}
-
+
if (j < fExpected.length()-1)
expected= expected+"...";
if (k < fActual.length()-1)
actual= actual+"...";
- }
+ }
return Assert.format(super.getMessage(), expected, actual);
}
}
{
/** whether to report timing information */
private static boolean timing = false;
-
+
/**
* Report on a section.
*/
/**
* Run tests.
- *
+ *
* @param timing whether to print out timing info
*/
public static void run(boolean timing) {
end = System.nanoTime();
report("testInst099", start, end, iter, rept);
}
-
+
public int func001() { return 1; }
public int func003() { return 3; }
public int func005() { return 5; }
public class Main {
/** whether to report times */
static boolean timing = false;
-
+
static final int STORAGE_SIZE = 128*1024;
static int[] mStorage = new int[STORAGE_SIZE];
if ((args.length >= 1) && args[0].equals("--timing")) {
timing = true;
}
-
+
writeTest();
copyTest();
System.out.println("Done!");
${RUN} "$@" > original-output.txt
cat original-output.txt | awk '
-/Segmentation fault/ {
+/Segmentation fault/ {
# ignore the details of the line
print "(segfault)"
next;
}
-{
+{
print;
}'
System.out.println("Requesting another GC.");
System.gc();
}
-
+
System.out.println("Done waiting.");
System.exit(0);
}
meth = MemberClass.class.getMethod("foo", (Class[]) null);
System.out.println("method signature: "
+ getSignatureAttribute(meth));
-
+
Field field;
field = MemberClass.class.getField("mWha");
System.out.println("field signature: "
System.out.println("calling abs.doStuff()");
abs.doStuff();
}
-
+
public static void main() {
ConcreteSub sub = new ConcreteSub();
static public void main(String[] args) {
Thread thread1, thread2;
-
+
System.out.println("Deadlock test starting.");
thread1 = new Thread() { public void run() { new A(); } };
thread2 = new Thread() { public void run() { new B(); } };
thread1.start();
thread2.start();
-
+
try { Thread.sleep(6000); } catch (InterruptedException ie) { }
-
+
System.out.println("Deadlock test interupting threads.");
thread1.interrupt();
thread2.interrupt();
} catch (InterruptedException ie) {
throw new RuntimeException(ie);
}
-
+
return wimp[0];
}
/* this will try to collect and finalize ft */
System.out.println("gc");
System.gc();
-
+
System.out.println("wimp: " + wimpString(wimp));
System.out.println("finalize");
System.runFinalization();
public class Main {
public static void main(String[] args) {
Thread t;
-
+
t = new Thread(new JoinMainSub(Thread.currentThread()), "Joiner");
System.out.print("Starting thread '" + t.getName() + "'\n");
t.start();
try {
Thread.sleep(100);
- }
+ }
catch (InterruptedException ie) {
System.out.println("INTERRUPT!");
ie.printStackTrace();
}
catch (InterruptedException ie) {
// Expecting this; interrupted should be false.
- System.out.println(Thread.currentThread().getName() +
+ System.out.println(Thread.currentThread().getName() +
" interrupted, flag=" + Thread.interrupted());
intr = true;
}
} catch (InterruptedException ex) {
ex.printStackTrace();
}
-
+
System.out.print("Thread starter returning\n");
}
boolean timing = (args.length >= 1) && args[0].equals("--timing");
doit(timing);
}
-
+
public static void doit(boolean timing) {
Object sleepy = new Object();
long start, end;
if (epsilon > 50) {
epsilon = 50;
}
-
+
long min = delay - epsilon;
long max = delay + epsilon;
-
+
if (elapsed < min) {
System.out.println(" Elapsed time was too short");
showTime = true;
showTime = true;
}
}
-
+
if (showTime) {
System.out.println(" Wall clock elapsed "
+ elapsed + "ms");
testThread(1);
testThread(2);
testThread(3);
-
+
catchTheUncaught(1);
}
ex.printStackTrace();
}
}
-
+
static void catchTheUncaught(int which) {
ThreadDeathHandler defHandler = new ThreadDeathHandler("DEFAULT");
ThreadDeathHandler threadHandler = new ThreadDeathHandler("THREAD");
public Helper(int which) {
this.which = which;
}
-
+
public void run() {
catchTheUncaught(which);
}
public class Main {
/** used by {@link #basisCall} */
static private int basisTestValue = 12;
-
+
static public void main(String[] args) throws Exception {
boolean timing = (args.length >= 1) && args[0].equals("--timing");
run(timing);
static public void run(boolean timing) {
preTest();
-
+
long time0 = System.nanoTime();
int count1 = test1(500);
long time1 = System.nanoTime();
static public int basisCall(int i, String name) {
int compare = name.compareTo("fuzzbot");
-
+
if (i < (basisTestValue * compare)) {
return basisTestValue;
} else {
/**
* The matrix of tests includes the A-E axis for loop body contents and
* the 0-5 axis for iterator style.
- *
+ *
* <ul>
* <li>A: empty body</li>
* <li>B: array element access and update</li>
* <li>G: one small object allocation (empty constructor)</li>
* <li>H: copy 8k of bytes from one array to another</li>
* </ul>
- *
+ *
* <ul>
* <li>0: for() loop backward to 0</li>
* <li>1: for() loop forward to local variable</li>
public class Main {
static public final int BODIES = 8;
static public final int LOOPS = 7;
-
+
static public void main(String[] args) throws Exception {
boolean timing = (args.length >= 1) && args[0].equals("--timing");
if (timing) {
System.out.println("iters = " + iters);
}
-
+
run(timing, iters);
}
static private enum Normalization {
NONE, PER_COLUMN, TOP_LEFT;
}
-
+
static public void printTimings(double[][] timings, Normalization norm) {
System.out.println();
System.out.printf("%-7s A B C D E" +
} else {
combineTimings(timings, newTimings, i);
}
-
+
if (checkTimes(timings, timing)) {
break;
}
if (! goodTimes) {
timing = true;
}
-
+
if (timing) {
printTimings(timings, Normalization.NONE);
printTimings(timings, Normalization.TOP_LEFT);
int oldWeight) {
for (int i = 0; i < target.length; i++) {
for (int j = 0; j < target[i].length; j++) {
- target[i][j] =
+ target[i][j] =
((target[i][j] * oldWeight) + newTimes[i][j])
/ (oldWeight + 1);
}
}
}
-
+
static public boolean checkTimes(double[][] timings, boolean print) {
// expected increase over A1
double[][] expected = {
{ 1.6, 2.8, 2.9, 3.6, 6.8, 12.6, 63.5, 97.0 },
{ 1.7, 3.0, 2.9, 3.7, 6.9, 12.8, 64.0, 98.0 },
{ 6.0, 6.0, 6.0, 7.0, 10.0, 15.0, 64.5, 105.0 },
- { 31.0, 31.2, 31.5, 34.0, 41.0, 43.0, 91.0, 135.0 },
+ { 31.0, 31.2, 31.5, 34.0, 41.0, 43.0, 91.0, 135.0 },
};
boolean good = true;
-
+
for (int x = 0; x < BODIES; x++) {
for (int y = 0; y < LOOPS; y++) {
double ratio = timings[x][y] / timings[0][0];
return good;
}
-
+
static public double[][] runAllTests(int iters, boolean print) {
// diters is used to get usec, not nanosec; hence the extra 1000.
double diters = (double) iters * INNER_COUNT * 1000;
if (print) {
System.out.println("Running A...");
}
-
+
t0 = System.nanoTime();
testA0(iters);
t1 = System.nanoTime();
timings[0][6] = (t7 - t6) / diters;
// Column B
-
+
if (print) {
System.out.println("Running B...");
}
-
+
t0 = System.nanoTime();
testB0(iters);
t1 = System.nanoTime();
timings[1][6] = (t7 - t6) / diters;
// Column C
-
+
if (print) {
System.out.println("Running C...");
}
-
+
t0 = System.nanoTime();
testC0(iters);
t1 = System.nanoTime();
timings[2][4] = (t5 - t4) / diters;
timings[2][5] = (t6 - t5) / diters;
timings[2][6] = (t7 - t6) / diters;
-
+
// Column D
-
+
if (print) {
System.out.println("Running D...");
}
timings[3][4] = (t5 - t4) / diters;
timings[3][5] = (t6 - t5) / diters;
timings[3][6] = (t7 - t6) / diters;
-
+
// Column E
-
+
if (print) {
System.out.println("Running E...");
}
timings[4][4] = (t5 - t4) / diters;
timings[4][5] = (t6 - t5) / diters;
timings[4][6] = (t7 - t6) / diters;
-
+
// Column F
-
+
if (print) {
System.out.println("Running F...");
}
iters /= 5;
diters /= 5;
-
+
// Column G
-
+
if (print) {
System.out.println("Running G...");
}
timings[6][4] = (t5 - t4) / diters;
timings[6][5] = (t6 - t5) / diters;
timings[6][6] = (t7 - t6) / diters;
-
+
// Column H
-
+
if (print) {
System.out.println("Running H...");
}
return size;
}
}
-
+
// The tests themselves
-
+
static public void testA0(int iters) {
for (int outer = iters; outer > 0; outer--) {
for (int i = INNER_COUNT; i > 0; i--) {
static public void testA2(int iters) {
int[] array = INNER_ARRAY;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < array.length; i++) {
// empty
static public void testA3(int iters) {
int[] array = INNER_ARRAY;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i : array) {
// empty
static public void testA4(int iters) {
Target target = TARGET;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < target.size; i++) {
// empty
static public void testA5(int iters) {
Target target = TARGET;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < target.size(); i++) {
// empty
static public void testA6(int iters) {
ArrayList<Object> list = INNER_LIST;
-
+
for (int outer = iters; outer > 0; outer--) {
for (Object o : list) {
// empty
static public void testB0(int iters) {
Target target = TARGET;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = INNER_COUNT; i > 0; i--) {
target.value++;
static public void testB2(int iters) {
Target target = TARGET;
int[] array = INNER_ARRAY;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < array.length; i++) {
target.value++;
static public void testB3(int iters) {
Target target = TARGET;
int[] array = INNER_ARRAY;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i : array) {
target.value++;
static public void testB4(int iters) {
Target target = TARGET;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < target.size; i++) {
target.value++;
static public void testB5(int iters) {
Target target = TARGET;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < target.size(); i++) {
target.value++;
static public void testB6(int iters) {
Target target = TARGET;
ArrayList<Object> list = INNER_LIST;
-
+
for (int outer = iters; outer > 0; outer--) {
for (Object o : list) {
target.value++;
static public void testC2(int iters) {
int[] array = INNER_ARRAY;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < array.length; i++) {
array[i]++;
static public void testC3(int iters) {
int[] array = INNER_ARRAY;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i : array) {
array[0] = i + 1;
static public void testC4(int iters) {
Target target = TARGET;
int[] array = INNER_ARRAY;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < target.size; i++) {
array[i]++;
static public void testC5(int iters) {
int[] array = INNER_ARRAY;
Target target = TARGET;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < target.size(); i++) {
array[i]++;
static public void testC6(int iters) {
int[] array = INNER_ARRAY;
ArrayList<Object> list = INNER_LIST;
-
+
for (int outer = iters; outer > 0; outer--) {
for (Object o : list) {
array[0]++;
static public void testD2(int iters) {
Target target = TARGET;
int[] array = INNER_ARRAY;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < array.length; i++) {
target.simple();
static public void testD3(int iters) {
Target target = TARGET;
int[] array = INNER_ARRAY;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i : array) {
target.simple();
static public void testD4(int iters) {
Target target = TARGET;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < target.size; i++) {
target.simple();
static public void testD5(int iters) {
Target target = TARGET;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < target.size(); i++) {
target.simple();
static public void testD6(int iters) {
Target target = TARGET;
ArrayList<Object> list = INNER_LIST;
-
+
for (int outer = iters; outer > 0; outer--) {
for (Object o : list) {
target.simple();
}
}
- }
+ }
static public void testE0(int iters) {
Target target = TARGET;
static public void testE2(int iters) {
Target target = TARGET;
int[] array = INNER_ARRAY;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < array.length; i++) {
synchronized (target) {
static public void testE3(int iters) {
Target target = TARGET;
int[] array = INNER_ARRAY;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i : array) {
synchronized (target) {
static public void testE4(int iters) {
Target target = TARGET;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < target.size; i++) {
synchronized (target) {
static public void testE5(int iters) {
Target target = TARGET;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < target.size(); i++) {
synchronized (target) {
static public void testE6(int iters) {
Target target = TARGET;
ArrayList<Object> list = INNER_LIST;
-
+
for (int outer = iters; outer > 0; outer--) {
for (Object o : list) {
synchronized (target) {
}
}
}
- }
+ }
static public void testF0(int iters) {
Target target = TARGET;
static public void testF2(int iters) {
Target target = TARGET;
int[] array = INNER_ARRAY;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < array.length; i++) {
target.simple();
static public void testF3(int iters) {
Target target = TARGET;
int[] array = INNER_ARRAY;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i : array) {
target.simple();
static public void testF4(int iters) {
Target target = TARGET;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < target.size; i++) {
target.simple();
static public void testF5(int iters) {
Target target = TARGET;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < target.size(); i++) {
target.simple();
static public void testF6(int iters) {
Target target = TARGET;
ArrayList<Object> list = INNER_LIST;
-
+
for (int outer = iters; outer > 0; outer--) {
for (Object o : list) {
target.simple();
static public void testG2(int iters) {
int[] array = INNER_ARRAY;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < array.length; i++) {
new Target();
static public void testG3(int iters) {
int[] array = INNER_ARRAY;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i : array) {
new Target();
static public void testG4(int iters) {
Target target = TARGET;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < target.size; i++) {
new Target();
static public void testG5(int iters) {
Target target = TARGET;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < target.size(); i++) {
new Target();
static public void testG6(int iters) {
ArrayList<Object> list = INNER_LIST;
-
+
for (int outer = iters; outer > 0; outer--) {
for (Object o : list) {
new Target();
static public void testH0(int iters) {
byte[] b1 = BYTES_1;
byte[] b2 = BYTES_2;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = INNER_COUNT; i > 0; i--) {
System.arraycopy(b1, 0, b2, 0, ARRAY_BYTES);
byte[] b1 = BYTES_1;
byte[] b2 = BYTES_2;
int[] array = INNER_ARRAY;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < array.length; i++) {
System.arraycopy(b1, 0, b2, 0, ARRAY_BYTES);
byte[] b1 = BYTES_1;
byte[] b2 = BYTES_2;
int[] array = INNER_ARRAY;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i : array) {
System.arraycopy(b1, 0, b2, 0, ARRAY_BYTES);
Target target = TARGET;
byte[] b1 = BYTES_1;
byte[] b2 = BYTES_2;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < target.size; i++) {
System.arraycopy(b1, 0, b2, 0, ARRAY_BYTES);
Target target = TARGET;
byte[] b1 = BYTES_1;
byte[] b2 = BYTES_2;
-
+
for (int outer = iters; outer > 0; outer--) {
for (int i = 0; i < target.size(); i++) {
System.arraycopy(b1, 0, b2, 0, ARRAY_BYTES);
byte[] b1 = BYTES_1;
byte[] b2 = BYTES_2;
ArrayList<Object> list = INNER_LIST;
-
+
for (int outer = iters; outer > 0; outer--) {
for (Object o : list) {
System.arraycopy(b1, 0, b2, 0, ARRAY_BYTES);
public static enum Muffin {
CORN, BLUEBERRY, CRANBERRY, BRAN, BLACKBERRY;
}
-
+
public static void main(String args[]) {
Muffin[] array = Muffin.class.getEnumConstants();
for (Muffin m : array) {
case Member.PUBLIC: member = "PUBLIC"; break;
default: member = "<" + which + ">?"; break;
}
-
+
System.out.println("checkMemberAccess: " + c.getName() + ", " +
member);
denyIfAppropriate();
public class Main {
static public boolean VERBOSE = false;
-
+
static public void main(String[] args) {
if (args.length > 0) {
if (args[0].equals("--verbose")) {
VERBOSE = true;
}
}
-
+
System.out.println("Setting SecurityManager.");
System.setSecurityManager(Enforcer.THE_ONE);
System.out.println("Running tests.");
/*package*/ int packageField;
protected int protectedField;
public int publicField;
-
+
private void privateMethod() {
// This space intentionally left blank.
}
public static void main(String[] args) throws Exception {
setUp();
-
+
ParkTester test = new ParkTester();
System.out.println("Test starting");
-
+
test.start();
UNSAFE.unpark(test);
clearStack(10);
private static class ParkTester extends Thread {
public volatile boolean parkNow = false;
public volatile boolean success = false;
-
+
public void run() {
while (!parkNow) {
try {
throws ClassNotFoundException
{
Class res;
-
+
/*
* 1. Invoke findLoadedClass(String) to check if the class has
* already been loaded.
int1.clear ();
int1.put (data);
int1.position (0);
-
+
int1.clear ();
int1.put (data);
int1.position (0);
for i in $failNames; do
echo "failed: $i"
done
-
+
When found, the name of the section is extracted. The entire contents
of that section is added to a result hashmap with the section name
as the key"""
-
+
# Match lines like
# |section_name:
# capturing section_name
start = 0
anchor = -1
sectionName = ''
-
+
while True:
# Look for a section header
result = headerPattern.search(buffer, start)
-
+
# If there are no more, add a section from the last header to EOF
if result is None:
if anchor is not -1:
# map indexed by the section name
if anchor is not -1:
sections[sectionName] = buffer[anchor:result.start()]
-
+
sectionName = result.group(1)
start = result.end()
anchor = start
-
+
return sections
def FindMethods(section):
"""Spin through the 'method code index' section and extract all
method signatures. When found, they are added to a result list."""
-
+
# Match lines like:
# |[abcd] com/example/app/Class.method:(args)return
# capturing the method signature
while True:
# Look for a method name
result = methodPattern.search(section, start)
-
+
if result is None:
return methods
"""Spin through all the input method signatures. For each one, return
whether or not there is method invokation line in the codes section that
lists the method as the target."""
-
+
start = 0
-
+
while True:
# Find the next reference to the method signature
match = codes.find(method, start)
-
+
if match is -1:
break;
-
+
# Find the beginning of the line the method reference is on
startOfLine = codes.rfind("\n", 0, match) + 1
# than the beginning of the code section for that method.
if codes.find("invoke", startOfLine, match) is not -1:
return True
-
+
start = match + len(method)
-
+
return False
if not CallsMethod(codes, method):
print "\t", method
count += 1
-
+
if count is 0:
print "\tNone"
-#
+#
# Copyright 2006 The Android Open Source Project
#
# Java method trace dump tool
**
** Copyright 2006, The Android Open Source Project
**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
**
-** http://www.apache.org/licenses/LICENSE-2.0
+** http://www.apache.org/licenses/LICENSE-2.0
**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
** limitations under the License.
*/
save_cp = cp;
while (*cp != '\n')
cp += 1;
-
+
/* Remove trailing spaces */
cp -= 1;
while (isspace(*cp))
**
** Copyright 2006, The Android Open Source Project
**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
**
-** http://www.apache.org/licenses/LICENSE-2.0
+** http://www.apache.org/licenses/LICENSE-2.0
**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
** limitations under the License.
*/
#define DEFAULT_ACTIVE_THREADS 8
-char *htmlHeader =
+char *htmlHeader =
"<html>\n<head>\n<script type=\"text/javascript\" src=\"%ssortable.js\"></script>\n"
"<script langugage=\"javascript\">\n"
"function toggle(item) {\n"
"</head><body>\n\n";
char *htmlFooter = "\n</body>\n</html>\n";
-char *profileSeparator =
+char *profileSeparator =
"======================================================================";
-
-const char* tableHeader =
+
+const char* tableHeader =
"<table class='sortable' id='%s'><tr>\n"
"<th>Method</th>\n"
"<th>Run 1 (us)</th>\n"
"<th>Diff (%%)</th>\n"
"<th>1: # calls</th>\n"
"<th>2: # calls</th>\n"
- "</tr>\n";
-
-const char* tableHeaderMissing =
+ "</tr>\n";
+
+const char* tableHeaderMissing =
"<table class='sortable' id='%s'>\n"
"<th>Method</th>\n"
"<th>Exclusive</th>\n"
"<th>Inclusive</th>\n"
"<th># calls</th>\n";
-
-#define GRAPH_LABEL_VISITED 0x0001
+
+#define GRAPH_LABEL_VISITED 0x0001
#define GRAPH_NODE_VISITED 0x0002
-
+
/*
* Values from the header of the data file.
*/
if (id == EOF)
return 1;
*threadId = id;
-
+
*methodVal = read4LE(dataFp);
*elapsedTime = read4LE(dataFp);
if (feof(dataFp)) {
for (ii = 0; ii < num_entries - 1; ++ii)
sorted[ii].next = &sorted[ii + 1];
sorted[num_entries - 1].next = NULL;
-
+
return sorted;
}
char *className, *methodName, *signature;
char classBuf[HTML_BUFSIZE], methodBuf[HTML_BUFSIZE];
char signatureBuf[HTML_BUFSIZE];
-
+
anchor_close = "";
if (gOptions.outputHtml)
anchor_close = "</a>";
}
/* check to make sure that the child method meets the threshold of the parent */
-int checkThreshold(MethodEntry* parent, MethodEntry* child)
+int checkThreshold(MethodEntry* parent, MethodEntry* child)
{
double parentTime = parent->elapsedInclusive;
double childTime = child->elapsedInclusive;
void createLabels(FILE* file, MethodEntry* method)
{
- fprintf(file, "node%d[label = \"[%d] %s.%s (%llu, %llu, %d)\"]\n",
- method->index, method->index, method->className, method->methodName,
+ fprintf(file, "node%d[label = \"[%d] %s.%s (%llu, %llu, %d)\"]\n",
+ method->index, method->index, method->className, method->methodName,
method->elapsedInclusive / 1000,
method->elapsedExclusive / 1000,
method->numCalls[0]);
- method->graphState = GRAPH_LABEL_VISITED;
+ method->graphState = GRAPH_LABEL_VISITED;
TimedMethod* child;
for (child = method->children[0] ; child ; child = child->next) {
MethodEntry* childMethod = child->method;
-
+
if ((childMethod->graphState & GRAPH_LABEL_VISITED) == 0 && checkThreshold(method, childMethod)) {
createLabels(file, child->method);
}
void createLinks(FILE* file, MethodEntry* method)
{
method->graphState |= GRAPH_NODE_VISITED;
-
+
TimedMethod* child;
for (child = method->children[0] ; child ; child = child->next) {
MethodEntry* childMethod = child->method;
}
FILE* file = fopen(path, "w+");
-
+
fprintf(file, "digraph g {\nnode [shape = record,height=.1];\n");
-
+
createLabels(file, dataKeys->methods);
createLinks(file, dataKeys->methods);
-
+
fprintf(file, "}");
fclose(file);
-
+
// now that we have the dot file generate the image
char command[1024];
snprintf(command, 1024, "dot -Tpng -o '%s' '%s'", gOptions.graphFileName, path);
-
+
system(command);
if (! gOptions.keepDotFile) {
*/
DataKeys* parseDataKeys(TraceData* traceData, const char* traceFileName,
uint64_t* threadTime, Filter** filters)
-{
+{
DataKeys* dataKeys = NULL;
MethodEntry **pMethods = NULL;
MethodEntry* method;
int ii, jj, numThreads;
uint64_t currentTime;
MethodEntry* caller;
-
+
dataFp = fopen(traceFileName, "r");
if (dataFp == NULL)
goto bail;
}
caller = &dataKeys->methods[TOPLEVEL_INDEX];
caller->elapsedInclusive = sumThreadTime;
-
+
#if 0
fclose(dumpStream);
#endif
bail:
if (dataFp != NULL)
fclose(dataFp);
-
+
return dataKeys;
}
MethodEntry* entry = &dataKeys->methods[ii];
pMethods[ii] = entry;
}
-
+
return pMethods;
}
if (result == 0) {
result = strcmp(methodA->signature, methodB->signature);
if (result == 0) {
- return strcmp(methodA->className, methodB->className);
+ return strcmp(methodA->className, methodB->className);
}
}
return result;
int findMatch(MethodEntry** methods, int size, MethodEntry* matchThis)
{
int i;
-
+
for (i = 0 ; i < size ; i++) {
MethodEntry* method = methods[i];
-
+
if (method != NULL && !compareMethodNamesForDiff(&method, &matchThis)) {
-// printf("%s.%s == %s.%s<br>\n", matchThis->className, matchThis->methodName,
+// printf("%s.%s == %s.%s<br>\n", matchThis->className, matchThis->methodName,
// method->className, method->methodName);
-
+
return i;
/* if (!compareMethodNames(&method, &matchThis)) {
return i;
}
*/ }
}
-
+
return -1;
}
const DiffEntry* entryA = (const DiffEntry*)a;
const DiffEntry* entryB = (const DiffEntry*)b;
-
+
if (entryA->differenceExclusive < entryB->differenceExclusive) {
return 1;
} else if (entryA->differenceExclusive > entryB->differenceExclusive) {
return -1;
}
-
+
return 0;
}
const DiffEntry* entryA = (const DiffEntry*)a;
const DiffEntry* entryB = (const DiffEntry*)b;
-
+
if (entryA->differenceInclusive < entryB->differenceInclusive) {
return 1;
} else if (entryA->differenceInclusive > entryB->differenceInclusive) {
return -1;
}
-
+
return 0;
}
-void printMissingMethod(MethodEntry* method)
+void printMissingMethod(MethodEntry* method)
{
char classBuf[HTML_BUFSIZE];
char methodBuf[HTML_BUFSIZE];
char* className;
char* methodName;
-
+
className = htmlEscape(method->className, classBuf, HTML_BUFSIZE);
methodName = htmlEscape(method->methodName, methodBuf, HTML_BUFSIZE);
-
- if (gOptions.outputHtml) printf("<tr><td>\n");
-
+
+ if (gOptions.outputHtml) printf("<tr><td>\n");
+
printf("%s.%s ", className, methodName);
if (gOptions.outputHtml) printf("</td><td>");
-
+
printf("%lld ", method->elapsedExclusive);
if (gOptions.outputHtml) printf("</td><td>");
-
+
printf("%lld ", method->elapsedInclusive);
if (gOptions.outputHtml) printf("</td><td>");
-
+
printf("%d\n", method->numCalls[0]);
if (gOptions.outputHtml) printf("</td><td>\n");
}
{
MethodEntry** methods1 = parseMethodEntries(d1);
MethodEntry** methods2 = parseMethodEntries(d2);
-
- // sort and assign the indicies
+
+ // sort and assign the indicies
int i;
qsort(methods1, d1->numMethods, sizeof(MethodEntry*), compareElapsedInclusive);
for (i = 0; i < d1->numMethods; ++i) {
for (i = 0; i < d2->numMethods; ++i) {
methods2[i]->index = i;
}
-
+
int max = (d1->numMethods < d2->numMethods) ? d2->numMethods : d1->numMethods;
max++;
DiffEntry* diffs = (DiffEntry*)malloc(max * sizeof(DiffEntry));
memset(diffs, 0, max * sizeof(DiffEntry));
DiffEntry* ptr = diffs;
-
+
// printf("<br>d1->numMethods: %d d1->numMethods: %d<br>\n", d1->numMethods, d2->numMethods);
-
+
int matches = 0;
-
+
for (i = 0 ; i < d1->numMethods ; i++) {
int match = findMatch(methods2, d2->numMethods, methods1[i]);
if (match >= 0) {
ptr->differenceInclusive = i2 - i1;
ptr->differenceInclusivePercentage = ((double)i2 / (double)i1) * 100.0;
}
-
+
// clear these out so we don't find them again and we know which ones
// we have left over
methods1[i] = NULL;
methods2[match] = NULL;
ptr++;
-
+
matches++;
}
}
qsort(diffs, matches, sizeof(DiffEntry), compareDiffEntriesExculsive);
ptr = diffs;
-
+
if (gOptions.outputHtml) {
printf(htmlHeader, gOptions.sortableUrl);
printf("<h3>Table of Contents</h3>\n");
printf("<a name=\"exclusive\"></a><h3 id=\"exclusive\">Exclusive</h3>\n");
printf(tableHeader, "exclusive_table");
}
-
+
char classBuf[HTML_BUFSIZE];
char methodBuf[HTML_BUFSIZE];
char* className;
char* methodName;
-
+
while (ptr->method1 != NULL && ptr->method2 != NULL) {
if (gOptions.outputHtml) printf("<tr><td>\n");
printf("%s.%s ", className, methodName);
if (gOptions.outputHtml) printf("</td><td>");
-
+
printf("%lld ", ptr->method1->elapsedExclusive);
if (gOptions.outputHtml) printf("</td><td>");
-
+
printf("%llu ", ptr->method2->elapsedExclusive);
if (gOptions.outputHtml) printf("</td><td>");
-
+
printf("%lld ", ptr->differenceExclusive);
if (gOptions.outputHtml) printf("</td><td>");
-
+
printf("%.2f\n", ptr->differenceExclusivePercentage);
if (gOptions.outputHtml) printf("</td><td>\n");
printf("%d\n", ptr->method2->numCalls[0]);
if (gOptions.outputHtml) printf("</td></tr>\n");
-
+
ptr++;
}
-
+
if (gOptions.outputHtml) printf("</table>\n");
-
+
if (gOptions.outputHtml) {
printf(htmlHeader, gOptions.sortableUrl);
printf("Run 1: %s<br>\n", gOptions.diffFileName);
printf("<a name=\"inclusive\"></a><h3 id=\"inculisve\">Inclusive</h3>\n");
printf(tableHeader, "inclusive_table");
}
-
+
qsort(diffs, matches, sizeof(DiffEntry), compareDiffEntriesInculsive);
ptr = diffs;
-
+
while (ptr->method1 != NULL && ptr->method2 != NULL) {
if (gOptions.outputHtml) printf("<tr><td>\n");
printf("<h3>Run 1 methods not found in Run 2</h3>");
printf(tableHeaderMissing);
}
-
+
for (i = 0; i < d1->numMethods; ++i) {
if (methods1[i] != NULL) {
printMissingMethod(methods1[i]);
}
}
-
+
if (gOptions.outputHtml) {
printf("</table>\n");
printf("<h3>Run 2 methods not found in Run 1</h3>");
printf(tableHeaderMissing);
}
-
+
for (i = 0; i < d2->numMethods; ++i) {
if (methods2[i] != NULL) {
printMissingMethod(methods2[i]);
}
}
-
+
if (gOptions.outputHtml) printf("</body></html\n");
}
uint64_t sum2;
TraceData data2;
DataKeys* d2 = parseDataKeys(&data2, gOptions.diffFileName, &sum2, filters);
-
+
createDiff(d2, sum2, dataKeys, sumThreadTime);
-
+
freeDataKeys(d2);
} else {
MethodEntry** methods = parseMethodEntries(dataKeys);
}
free(methods);
}
-
+
freeDataKeys(dataKeys);
return 0;
print("dmtracedump -h -p $input > $output\n");
system("dmtracedump -h -p '$input' > '$output'");
-
+
}
closedir DIR;
Step 2
-
+
Push $OUT/EXECUTABLES/gdbjithelper_intermediates/LINKED/gdbjithelper to
/system/bin on the device or emulator
* 463ba204 4191debc 01010000 4284aa74 68b00054
* 463ba214 045cf205 cc016468 0718f2a5 d0102800
* 463ba224 4c13c701 a20aa108 efb0f775 e008e010
- *
+ *
* code around lr:
* 463ba1a8 42e19e58 f2050050 cc01045c 0718f2a5
* 463ba1b8 d00f2800 4c13c701 a20aa108 efe4f775
*/
int idx = headIndex();
int count = gDvm.allocRecordCount;
-
+
LOGI("Tracked allocations, (head=%d count=%d)\n",
gDvm.allocRecordHead, count);
while (count--) {
* (4b) threadId
* (1b) thread status
* (4b) tid
- * (4b) utime
- * (4b) stime
+ * (4b) utime
+ * (4b) stime
* (1b) is daemon?
*
* The length fields exist in anticipation of adding additional fields
if (strcmp(type, "Ljava/lang/String;") == 0)
return JT_STRING;
else if (strcmp(type, "Ljava/lang/Class;") == 0)
- return JT_CLASS_OBJECT;
+ return JT_CLASS_OBJECT;
else if (strcmp(type, "Ljava/lang/Thread;") == 0)
return JT_THREAD;
else if (strcmp(type, "Ljava/lang/ThreadGroup;") == 0)
int i;
dexStringCacheInit(&stringCache);
-
+
clazz = refTypeIdToClassObject(refTypeId);
assert(clazz != NULL);
bool withGeneric;
} DebugCallbackContext;
-static int lineTablePositionsCb(void *cnxt, u4 address, u4 lineNum)
+static int lineTablePositionsCb(void *cnxt, u4 address, u4 lineNum)
{
DebugCallbackContext *pContext = (DebugCallbackContext *)cnxt;
DebugCallbackContext context;
memset (&context, 0, sizeof(DebugCallbackContext));
-
+
method = methodIdToMethod(refTypeId, methodId);
expandBufAdd4BE(pReply, method->insSize);
StaticField* sfield = (StaticField*) fieldIdToField(refTypeId, fieldId);
Object* objVal;
JValue value;
-
+
value.j = rawValue;
switch (sfield->field.signature[0]) {
Object* threadObj;
Thread* thread;
bool result = false;
-
+
threadObj = objectIdToObject(threadId);
assert(threadObj != NULL);
Object* threadObj;
Thread* thread;
u4 result = 0;
-
+
threadObj = objectIdToObject(threadId);
assert(threadObj != NULL);
Object* threadObj;
Thread* thread;
bool result;
-
+
threadObj = objectIdToObject(threadId);
assert(threadObj != NULL);
Object* threadObj;
Thread* thread;
bool result = false;
-
+
threadObj = objectIdToObject(threadId);
assert(threadObj != NULL);
{
Object* threadObj;
Thread* thread;
-
+
threadObj = objectIdToObject(threadId);
assert(threadObj != NULL);
excepClass->descriptor, msg, initKind);
assert(strcmp(excepClass->descriptor,
"Ljava/lang/RuntimeException;") != 0);
- dvmThrowChainedException("Ljava/lang/RuntimeException;",
+ dvmThrowChainedException("Ljava/lang/RuntimeException;",
"re-throw on exception class missing constructor", NULL);
goto bail;
}
if (handler == NULL) {
break;
}
-
+
if (handler->typeIdx == kDexNoIndex) {
/* catch-all */
LOGV("Match on catch-all block at 0x%02x in %s.%s for %s\n",
*intPtr++ = 0; /* no saved PC for native methods */
} else {
assert(saveArea->xtra.currentPc >= method->insns &&
- saveArea->xtra.currentPc <
+ saveArea->xtra.currentPc <
method->insns + dvmGetMethodInsnsSize(method));
*intPtr++ = (int) (saveArea->xtra.currentPc - method->insns);
}
/*
* Scan every entry in the hash table and evaluate it with the specified
- * indirect function call. If the function returns 1, remove the entry from
- * the table.
+ * indirect function call. If the function returns 1, remove the entry from
+ * the table.
*
* Does NOT invoke the "free" function on the item.
*
{
const void* data = (const void*)dvmHashIterData(&iter);
int count;
-
+
count = countProbes(pHashTable, (*calcFunc)(data), data, cmpFunc);
numEntries++;
{
dvmFprintf(stdout, "DalvikVM version %d.%d.%d\n",
DALVIK_MAJOR_VERSION, DALVIK_MINOR_VERSION, DALVIK_BUG_VERSION);
- dvmFprintf(stdout,
+ dvmFprintf(stdout,
"Copyright (C) 2007 The Android Open Source Project\n\n"
"This software is built from source code licensed under the "
"Apache License,\n"
gDvmJit.methodTable = dvmHashTableCreate(8, NULL);
start = buf;
- /*
+ /*
* Break comma-separated method signatures and enter them into the hash
* table individually.
*/
{
u8 startHeap, startQuit, startJdwp;
u8 endHeap, endQuit, endJdwp;
-
+
startHeap = dvmGetRelativeTimeUsec();
/*
Method* method = gDvm.inlinedMethods[opIndex];
if (method == NULL) {
ClassObject* clazz;
-
+
clazz = dvmFindClassNoInit(
gDvmInlineOpsTable[opIndex].classDescriptor, NULL);
if (clazz == NULL) {
setProperty(propObj, put, "file.separator", "/");
setProperty(propObj, put, "line.separator", "\n");
setProperty(propObj, put, "path.separator", ":");
-
+
/*
* These show up elsewhere, so do them here too.
*/
/*
* Chunk HPIF (client --> server)
- *
+ *
* Heap Info. General information about the heap,
* suitable for a summary display.
- *
+ *
* [u4]: number of heaps
- *
+ *
* For each heap:
* [u4]: heap ID
* [u8]: timestamp in ms since Unix epoch
state = HPSG_STATE(SOLIDITY_FREE, 0);
} else {
const Object *obj = userptr;
- /* If we're looking at the native heap, we'll just return
+ /* If we're looking at the native heap, we'll just return
* (SOLIDITY_HARD, KIND_NATIVE) for all allocated chunks
*/
bool native = ctx->type == CHUNK_TYPE("NHSG");
walkHeap(bool merge, bool native)
{
HeapChunkContext ctx;
-
+
memset(&ctx, 0, sizeof(ctx));
ctx.bufLen = HPSx_CHUNK_SIZE;
ctx.buf = (u1 *)malloc(ctx.bufLen);
/* Enough to quiet down gcc for unitialized variable check */
perHeapActualSize[0] = perHeapAllowedSize[0] = perHeapNumAllocated[0] =
perHeapSizeAllocated[0] = 0;
- actualSize = dvmHeapSourceGetValue(HS_FOOTPRINT, perHeapActualSize,
+ actualSize = dvmHeapSourceGetValue(HS_FOOTPRINT, perHeapActualSize,
HEAP_SOURCE_MAX_HEAP_COUNT);
- allowedSize = dvmHeapSourceGetValue(HS_ALLOWED_FOOTPRINT,
+ allowedSize = dvmHeapSourceGetValue(HS_ALLOWED_FOOTPRINT,
perHeapAllowedSize, HEAP_SOURCE_MAX_HEAP_COUNT);
numAllocated = dvmHeapSourceGetValue(HS_OBJECTS_ALLOCATED,
perHeapNumAllocated, HEAP_SOURCE_MAX_HEAP_COUNT);
sizeAllocated = dvmHeapSourceGetValue(HS_BYTES_ALLOCATED,
perHeapSizeAllocated, HEAP_SOURCE_MAX_HEAP_COUNT);
- /*
- * Construct the the first 64-bit value to write to the log.
+ /*
+ * Construct the the first 64-bit value to write to the log.
* Global information:
*
* [63 ] Must be zero
hs->targetUtilization =
(size_t)(newTarget * (float)HEAP_UTILIZATION_MAX);
- LOGV("Set heap target utilization to %zd/%d (%f)\n",
+ LOGV("Set heap target utilization to %zd/%d (%f)\n",
hs->targetUtilization, HEAP_UTILIZATION_MAX, newTarget);
}
/* Return any whole free pages to the system.
*/
bytesTrimmed[i] = 0;
- mspace_walk_free_pages(heap->msp, releasePagesInRange,
+ mspace_walk_free_pages(heap->msp, releasePagesInRange,
&bytesTrimmed[i]);
heapBytes += bytesTrimmed[i];
}
* Tries to update the internal count of externally-allocated memory.
* If there's enough room for that memory, returns true. If not, returns
* false and does not update the count.
- *
+ *
* The caller must ensure externalAllocPossible(hs, n) == true.
*/
static bool
HS_EXTERNAL_BYTES_ALLOCATED,
HS_EXTERNAL_LIMIT
};
-size_t dvmHeapSourceGetValue(enum HeapSourceValueSpec spec,
+size_t dvmHeapSourceGetValue(enum HeapSourceValueSpec spec,
size_t perHeapStats[], size_t arrayLen);
/*
#endif
if (trimtime.tv_sec < now.tv_sec ||
- (trimtime.tv_sec == now.tv_sec &&
+ (trimtime.tv_sec == now.tv_sec &&
trimtime.tv_nsec <= now.tv_nsec))
{
size_t madvisedSizes[HEAP_SOURCE_MAX_HEAP_COUNT];
vd.insnRegCount = meth->registersSize;
vd.insnFlags = insnFlags;
vd.addrRegs = regTable.addrRegs;
-
+
pMap = dvmGenerateRegisterMapV(&vd);
if (pMap != NULL) {
/*
* different class is already associated with the address (shouldn't
* happen either).
*/
-//int dvmSetUninitInstance(UninitInstanceMap* uninitMap, int addr,
+//int dvmSetUninitInstance(UninitInstanceMap* uninitMap, int addr,
// ClassObject* clazz);
/*
LOG_VFY_METH(meth,
"VFY: invalid array data end: at %d, data offset %d, end %d, "
"count %d\n",
- curOffset, offsetToArrayData,
+ curOffset, offsetToArrayData,
curOffset + offsetToArrayData + tableSize,
insnCount);
return false;
*/
/*
Output Formats
-
+
There are two possible output formats, from which we choose based on how
we plan to take advantage of the remapped constants. At most one of these
will appear in the DEX.
Function prototype:
void dvmPlatformInvoke(void* pEnv, ClassObject* clazz, int argInfo, int argc,
- const u4* argv, const char* signature, void* func, JValue* pReturn)
+ const u4* argv, const char* signature, void* func, JValue* pReturn)
The method we are calling has the form:
Function prototype:
void dvmPlatformInvoke(void* pEnv, ClassObject* clazz, int argInfo, int argc,
- const u4* argv, const char* signature, void* func, JValue* pReturn)
+ const u4* argv, const char* signature, void* func, JValue* pReturn)
The method we are calling has the form:
{
hprof_string_id classNameId;
char *dotName = dvmDescriptorToDot(descriptor);
-
+
/* Hprof suggests that array class names be converted from, e.g.,
* "[[[I" to "int[][][]" and "[Lorg.blort.Spaz;" to
* "org.blort.Spaz[]".
* ID: class object ID
* u4: stack trace serial number
* ID: class name string ID
- *
+ *
* We use the address of the class object structure as its ID.
*/
hprofAddU4ToRecord(rec, clazz->serialNumber);
hprof_record_t *rec = &ctx->curRec;
HprofHeapId desiredHeap;
- desiredHeap =
+ desiredHeap =
dvmHeapSourceGetPtrFlag(obj, HS_ALLOCATED_IN_ZYGOTE) ?
HPROF_HEAP_ZYGOTE : HPROF_HEAP_APP;
-
+
if (ctx->objectsInSegment >= OBJECTS_PER_SEGMENT ||
rec->length >= BYTES_PER_SEGMENT)
{
int i;
hprofStartNewRecord(ctx, HPROF_TAG_STACK_TRACE, HPROF_TIME);
-
+
stackTraceEntry = (const StackTraceEntry *) dvmHashIterData(&iter);
assert(stackTraceEntry != NULL);
*/
hprofAddU4ToRecord(rec, stackTraceEntry->trace.serialNumber);
hprofAddU4ToRecord(rec, stackTraceEntry->trace.threadSerialNumber);
-
+
count = 0;
while ((count < STACK_DEPTH) &&
(stackTraceEntry->trace.frameIds[count] != 0)) {
Thread* self;
void* fp;
int i;
-
+
if (objectPtr == NULL) {
return;
}
descriptor = dexProtoGetMethodDescriptor(&method->prototype, &cache);
hprofLookupStringId(descriptor);
dexStringCacheRelease(&cache);
-
+
const char* sourceFile = dvmGetMethodSourceFile(method);
if (sourceFile) {
hprofLookupStringId(sourceFile);
hprofLookupClassId(method->clazz);
}
}
-
+
return 0;
}
u4 hash = 0;
const char *cp = (char *) &stackFrameEntry->frame;
int i;
-
+
for (i = 0; i < (int) sizeof(StackFrame); i++) {
hash = 31 * hash + cp[i];
}
const char *sourceFile;
ClassObject *clazz;
int lineNum;
-
+
hprofStartNewRecord(ctx, HPROF_TAG_STACK_FRAME, HPROF_TIME);
-
+
stackFrameEntry = (const StackFrameEntry *) dvmHashIterData(&iter);
assert(stackFrameEntry != NULL);
-
+
method = stackFrameEntry->frame.method;
pc = stackFrameEntry->frame.pc;
sourceFile = dvmGetMethodSourceFile(method);
* ID: ID for this string
* [u1]*: UTF8 characters for string (NOT NULL terminated)
* (the record format encodes the length)
- *
+ *
* We use the address of the string data as its ID.
*/
err = hprofAddU4ToRecord(rec, (u4)str);
{
LineNumFromPcContext *pContext = (LineNumFromPcContext *)cnxt;
- // We know that this callback will be called in
+ // We know that this callback will be called in
// ascending address order, so keep going until we find
// a match or we've just gone past it.
method->prototype.protoIdx,
method->accessFlags,
lineNumForPcCb, NULL, &context);
-
+
return context.lineNum;
}
if (caller == NULL)
return NULL;
}
-
+
return SAVEAREA_FROM_FP(caller)->method->clazz;
}
netState->controlAddrLen =
sizeof(netState->controlAddr.controlAddrUn.sun_family) +
kJdwpControlNameLen;
-
- memcpy(netState->controlAddr.controlAddrUn.sun_path,
+
+ memcpy(netState->controlAddr.controlAddrUn.sun_path,
kJdwpControlName, kJdwpControlNameLen);
-
+
netState->wakeFds[0] = -1;
netState->wakeFds[1] = -1;
-
+
return netState;
}
JdwpNetState* netState;
LOGV("ADB transport startup\n");
-
+
state->netState = netState = adbStateAlloc();
if (netState == NULL)
return false;
msg.msg_flags = 0;
msg.msg_control = cm_un.buffer;
msg.msg_controllen = sizeof(cm_un.buffer);
-
+
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_len = msg.msg_controllen;
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
((int*)CMSG_DATA(cmsg))[0] = -1;
-
+
do {
ret = recvmsg(netState->controlSock, &msg, 0);
} while (ret < 0 && errno == EINTR);
int retryCount = 0;
/* first, ensure that we get a connection to the ADB daemon */
-
+
retry:
if (netState->shuttingDown)
return false;
shutdown(controlSock, SHUT_RDWR);
netState->controlSock = -1;
}
-
+
if (netState->wakeFds[1] >= 0) {
LOGV("+++ writing to wakePipe\n");
(void) write(netState->wakeFds[1], "", 1);
{
enum JdwpSuspendPolicy suspendPolicy;
ObjectId threadId = dvmDbgGetThreadSelfId();
-
+
if (suspend)
suspendPolicy = SP_ALL;
else
/*
* Are we talking to a debugger?
- */
+ */
bool dvmJdwpIsActive(JdwpState* state)
{
return dvmJdwpIsConnected(state);
bl dvmFindInterfaceMethodInCache @ r0<- call(class, ref, method, dex)
cmp r0, #0 @ failed?
beq common_exceptionThrown @ yes, handle exception
- b common_invokeMethod${routine} @ jump to common handler
+ b common_invokeMethod${routine} @ jump to common handler
arrayData >= curMethod->insns + dvmGetMethodInsnsSize(curMethod))
{
/* should have been caught in verifier */
- dvmThrowException("Ljava/lang/InternalError;",
+ dvmThrowException("Ljava/lang/InternalError;",
"bad fill array data");
GOTO_exceptionThrown();
}
bl dvmFindInterfaceMethodInCache @ r0<- call(class, ref, method, dex)
cmp r0, #0 @ failed?
beq common_exceptionThrown @ yes, handle exception
- b common_invokeMethodNoRange @ jump to common handler
+ b common_invokeMethodNoRange @ jump to common handler
/* ------------------------------ */
bl dvmFindInterfaceMethodInCache @ r0<- call(class, ref, method, dex)
cmp r0, #0 @ failed?
beq common_exceptionThrown @ yes, handle exception
- b common_invokeMethodRange @ jump to common handler
+ b common_invokeMethodRange @ jump to common handler
bl dvmFindInterfaceMethodInCache @ r0<- call(class, ref, method, dex)
cmp r0, #0 @ failed?
beq common_exceptionThrown @ yes, handle exception
- b common_invokeMethodNoRange @ jump to common handler
+ b common_invokeMethodNoRange @ jump to common handler
/* ------------------------------ */
bl dvmFindInterfaceMethodInCache @ r0<- call(class, ref, method, dex)
cmp r0, #0 @ failed?
beq common_exceptionThrown @ yes, handle exception
- b common_invokeMethodRange @ jump to common handler
+ b common_invokeMethodRange @ jump to common handler
bl dvmFindInterfaceMethodInCache @ r0<- call(class, ref, method, dex)
cmp r0, #0 @ failed?
beq common_exceptionThrown @ yes, handle exception
- b common_invokeMethodNoRange @ jump to common handler
+ b common_invokeMethodNoRange @ jump to common handler
/* ------------------------------ */
bl dvmFindInterfaceMethodInCache @ r0<- call(class, ref, method, dex)
cmp r0, #0 @ failed?
beq common_exceptionThrown @ yes, handle exception
- b common_invokeMethodRange @ jump to common handler
+ b common_invokeMethodRange @ jump to common handler
bl dvmFindInterfaceMethodInCache @ r0<- call(class, ref, method, dex)
cmp r0, #0 @ failed?
beq common_exceptionThrown @ yes, handle exception
- b common_invokeMethodNoRange @ jump to common handler
+ b common_invokeMethodNoRange @ jump to common handler
/* ------------------------------ */
bl dvmFindInterfaceMethodInCache @ r0<- call(class, ref, method, dex)
cmp r0, #0 @ failed?
beq common_exceptionThrown @ yes, handle exception
- b common_invokeMethodRange @ jump to common handler
+ b common_invokeMethodRange @ jump to common handler
bl dvmFindInterfaceMethodInCache @ r0<- call(class, ref, method, dex)
cmp r0, #0 @ failed?
beq common_exceptionThrown @ yes, handle exception
- b common_invokeMethodNoRange @ jump to common handler
+ b common_invokeMethodNoRange @ jump to common handler
/* ------------------------------ */
bl dvmFindInterfaceMethodInCache @ r0<- call(class, ref, method, dex)
cmp r0, #0 @ failed?
beq common_exceptionThrown @ yes, handle exception
- b common_invokeMethodRange @ jump to common handler
+ b common_invokeMethodRange @ jump to common handler
/*
* File: OP_THROW_VERIFICATION_ERROR.S
*
- * Code:
+ * Code:
*
* For: throw-verification-error
*
andb $0xf,%cl # ecx<- A
FETCH_INST_WORD(1)
ADVANCE_PC(1)
-
-
+
+
negl %eax
SET_VREG(%eax,%ecx)
GOTO_NEXT
andb $0xf,%cl # ecx<- A
FETCH_INST_WORD(1)
ADVANCE_PC(1)
-
-
+
+
notl %eax
SET_VREG(%eax,%ecx)
GOTO_NEXT
andb $0xf,%cl # ecx<- A
FETCH_INST_WORD(1)
ADVANCE_PC(1)
-
+
fstps (rFP,%ecx,4) # vA<- %st0
GOTO_NEXT
andb $0xf,%cl # ecx<- A
FETCH_INST_WORD(1)
ADVANCE_PC(1)
-
+
fstpl (rFP,%ecx,4) # vA<- %st0
GOTO_NEXT
andb $0xf,%cl # ecx<- A
FETCH_INST_WORD(1)
ADVANCE_PC(1)
-
+
fstps (rFP,%ecx,4) # vA<- %st0
GOTO_NEXT
andb $0xf,%cl # ecx<- A
FETCH_INST_WORD(1)
ADVANCE_PC(1)
-
+
fstpl (rFP,%ecx,4) # vA<- %st0
GOTO_NEXT
andb $0xf,%cl # ecx<- A
FETCH_INST_WORD(1)
ADVANCE_PC(1)
-
+
fstpl (rFP,%ecx,4) # vA<- %st0
GOTO_NEXT
andb $0xf,%cl # ecx<- A
FETCH_INST_WORD(1)
ADVANCE_PC(1)
-
+
fstps (rFP,%ecx,4) # vA<- %st0
GOTO_NEXT
andb $0xf,%cl # ecx<- A
FETCH_INST_WORD(1)
ADVANCE_PC(1)
-
-
+
+
movsbl %al,%eax
SET_VREG(%eax,%ecx)
GOTO_NEXT
andb $0xf,%cl # ecx<- A
FETCH_INST_WORD(1)
ADVANCE_PC(1)
-
-
+
+
movzwl %ax,%eax
SET_VREG(%eax,%ecx)
GOTO_NEXT
andb $0xf,%cl # ecx<- A
FETCH_INST_WORD(1)
ADVANCE_PC(1)
-
-
+
+
movswl %ax,%eax
SET_VREG(%eax,%ecx)
GOTO_NEXT
arrayData >= curMethod->insns + dvmGetMethodInsnsSize(curMethod))
{
/* should have been caught in verifier */
- dvmThrowException("Ljava/lang/InternalError;",
+ dvmThrowException("Ljava/lang/InternalError;",
"bad fill array data");
GOTO_exceptionThrown();
}
if (pCtrl->size == SS_MIN) {
doStop = true;
msg = "new instruction";
- } else if (!dvmAddressSetGet(pCtrl->pAddressSet,
+ } else if (!dvmAddressSetGet(pCtrl->pAddressSet,
pc - method->insns)) {
doStop = true;
msg = "new line";
arrayData >= curMethod->insns + dvmGetMethodInsnsSize(curMethod))
{
/* should have been caught in verifier */
- dvmThrowException("Ljava/lang/InternalError;",
+ dvmThrowException("Ljava/lang/InternalError;",
"bad fill array data");
GOTO_exceptionThrown();
}
arrayData >= curMethod->insns + dvmGetMethodInsnsSize(curMethod))
{
/* should have been caught in verifier */
- dvmThrowException("Ljava/lang/InternalError;",
+ dvmThrowException("Ljava/lang/InternalError;",
"bad fill array data");
GOTO_exceptionThrown();
}
if (pCtrl->size == SS_MIN) {
doStop = true;
msg = "new instruction";
- } else if (!dvmAddressSetGet(pCtrl->pAddressSet,
+ } else if (!dvmAddressSetGet(pCtrl->pAddressSet,
pc - method->insns)) {
doStop = true;
msg = "new line";
/*
* File: OP_THROW_VERIFICATION_ERROR.S
*
- * Code:
+ * Code:
*
* For: throw-verification-error
*
{ "Ldalvik/system/VMStack;", dvm_dalvik_system_VMStack, 0 },
{ "Lorg/apache/harmony/dalvik/ddmc/DdmServer;",
dvm_org_apache_harmony_dalvik_ddmc_DdmServer, 0 },
- { "Lorg/apache/harmony/dalvik/ddmc/DdmVmInternal;",
+ { "Lorg/apache/harmony/dalvik/ddmc/DdmVmInternal;",
dvm_org_apache_harmony_dalvik_ddmc_DdmVmInternal, 0 },
{ "Lorg/apache/harmony/dalvik/NativeTestTarget;",
dvm_org_apache_harmony_dalvik_NativeTestTarget, 0 },
* check the access flags at the time of the method call. This results in
* "native abstract" methods, which can't exist. If we see the "abstract"
* flag set, clear the "native" flag.
- *
+ *
* We also move the DECLARED_SYNCHRONIZED flag into the SYNCHRONIZED
* position, because the callers of this function are trying to convey
* the "traditional" meaning of the flags to their callers.
}
flags &= ~ACC_SYNCHRONIZED;
-
+
if ((flags & ACC_DECLARED_SYNCHRONIZED) != 0) {
flags |= ACC_SYNCHRONIZED;
}
-
+
return flags & JAVA_FLAGS_MASK;
}
* check the access flags at the time of the method call. This results in
* "native abstract" methods, which can't exist. If we see the "abstract"
* flag set, clear the "native" flag.
- *
+ *
* We also move the DECLARED_SYNCHRONIZED flag into the SYNCHRONIZED
* position, because the callers of this function are trying to convey
* the "traditional" meaning of the flags to their callers.
RETURN_VOID();
}
}
-
+
dvmMethodTraceStart(traceFileName != NULL ? traceFileName : "[DDMS]",
fd, bufferSize, flags, (traceFileName == NULL && fd == -1));
free(traceFileName);
#endif /* ifdef WCOREDUMP */
}
- /*
+ /*
* If the just-crashed process is the system_server, bring down zygote
* so that it is restarted by init and system server will be restarted
* from there.
*/
if (pid == gDvm.systemServerPid) {
LOG(LOG_INFO, ZYGOTE_LOG_TAG,
- "Exit zygote because system server (%d) has terminated\n",
+ "Exit zygote because system server (%d) has terminated\n",
(int) pid);
kill(getpid(), SIGKILL);
}
* This ends up being called repeatedly before each fork(), but there's
* no real harm in that.
*/
-static void setSignalHandler()
+static void setSignalHandler()
{
int err;
struct sigaction sa;
sa.sa_handler = sigchldHandler;
err = sigaction (SIGCHLD, &sa, NULL);
-
+
if (err < 0) {
LOGW("Error setting SIGCHLD handler errno: %d", errno);
}
sa.sa_handler = SIG_DFL;
err = sigaction (SIGCHLD, &sa, NULL);
-
+
if (err < 0) {
LOGW("Error unsetting SIGCHLD handler errno: %d", errno);
}
}
-/*
+/*
* Calls POSIX setgroups() using the int[] object as an argument.
* A NULL argument is tolerated.
*/
return -1;
}
}
-
+
return 0;
}
dvmAbort();
}
- setSignalHandler();
+ setSignalHandler();
dvmDumpLoaderStats("zygote");
pid = fork();
#endif
}
-/*
+/*
* Utility routine to fork zygote and specialize the child process.
*/
static pid_t forkAndSpecializeCommon(const u4* args)
dvmAbort();
}
- setSignalHandler();
+ setSignalHandler();
dvmDumpLoaderStats("zygote");
pid = fork();
/* configure additional debug options */
enableDebugFeatures(debugFlags);
- unsetSignalHandler();
+ unsetSignalHandler();
gDvm.zygote = false;
if (!dvmInitAfterZygote()) {
LOGE("error in post-zygote initialization\n");
return pid;
}
-/* native public static int forkAndSpecialize(int uid, int gid,
- * int[] gids, int debugFlags);
+/* native public static int forkAndSpecialize(int uid, int gid,
+ * int[] gids, int debugFlags);
*/
static void Dalvik_dalvik_system_Zygote_forkAndSpecialize(const u4* args,
JValue* pResult)
RETURN_INT(pid);
}
-/* native public static int forkSystemServer(int uid, int gid,
- * int[] gids, int debugFlags);
+/* native public static int forkSystemServer(int uid, int gid,
+ * int[] gids, int debugFlags);
*/
static void Dalvik_dalvik_system_Zygote_forkSystemServer(
const u4* args, JValue* pResult)
const DexFile* pDexFile = clazz->pDexFile;
const DexClassDef* pClassDef;
const DexClassId* pClassId;
-
+
pDexFile = clazz->pDexFile;
pClassDef = dvmDexFindClass(pDexFile, clazz->descriptor);
pClassId = dvmDexGetClassId(pDexFile, pClassDef->classIdx);
/*
* public String getInnerClassName()
*
- * Returns the simple name of a member class or local class, or null otherwise.
+ * Returns the simple name of a member class or local class, or null otherwise.
*/
static void Dalvik_java_lang_Class_getInnerClassName(const u4* args,
JValue* pResult)
ClassObject* clazz = (ClassObject*) args[0];
StringObject* nameObj;
int flags;
-
+
if (dvmGetInnerClass(clazz, &nameObj, &flags)) {
dvmReleaseTrackedAlloc((Object*) nameObj, NULL);
RETURN_PTR(nameObj);
else
result = THREAD_ZOMBIE; // assume it used to exist and is now gone
dvmUnlockThreadList();
-
+
RETURN_INT(result);
}
Object* thisPtr = (Object*) args[0];
int newPriority = args[1];
Thread* thread;
-
+
dvmLockThreadList(NULL);
thread = dvmGetThreadFromThreadObject(thisPtr);
if (thread != NULL)
// Note: android_atomic_cmpxchg() returns 0 on success, not failure.
int result = android_atomic_cmpxchg((int32_t) expectedValue,
(int32_t) newValue, address);
-
+
RETURN_BOOLEAN(result == 0);
}
*address = value;
RETURN_VOID();
}
-
+
/*
* public native int getInt(Object obj, long offset);
*/
* The dimension we're creating is in dimensions[0], so when we recurse
* we advance the pointer.
*/
-ArrayObject* dvmAllocMultiArray(ClassObject* arrayClass, int curDim,
+ArrayObject* dvmAllocMultiArray(ClassObject* arrayClass, int curDim,
const int* dimensions)
{
ArrayObject* newArray;
/*
* Find the class with the given descriptor. Load it if it hasn't already
* been.
- *
+ *
* "loader" is the initiating class loader.
*/
ClassObject* dvmFindClass(const char* descriptor, Object* loader);
const Method* method2)
{
return dexProtoCompare(&method1->prototype, &method2->prototype);
-}
+}
/*
* Compare the two method prototypes, considering only the parameters
const Method* method2)
{
return dexProtoCompareParameters(&method1->prototype, &method2->prototype);
-}
+}
/*
* Compare the two method names and prototypes, a la strcmp(). The
}
proto = &method->prototype;
-
+
if (strcmp(returnType, dexProtoGetReturnType(proto)) != 0) {
return 1;
}
* and also find a pointer to the return type.
*/
static inline size_t countArgsAndFindReturnType(const char* descriptor,
- const char** pReturnType)
+ const char** pReturnType)
{
size_t count = 0;
bool bogus = false;
assert(*descriptor == '(');
descriptor++;
-
+
while (!done) {
switch (*descriptor) {
case 'B': case 'C': case 'D': case 'F':
break;
}
case ')': {
- /*
+ /*
* Note: The loop will exit after incrementing descriptor
* one more time, so it then points at the return type.
*/
/* Skip the '('. */
descriptor++;
-
+
for (i = 0; i < argCount; i++) {
argTypes[i] = buffer;
*(buffer++) = c;
} while (c != ';');
}
-
+
*(buffer++) = '\0';
- }
+ }
}
/*
methods = clazz->directMethods;
methodCount = clazz->directMethodCount;
}
-
+
for (i = 0; i < methodCount; i++) {
Method* method = &methods[i];
if (compareMethodHelper(method, name, returnType, argCount,
*/
static Method* findMethodInListByProto(const ClassObject* clazz,
MethodType wantedType, bool isHier, const char* name, const DexProto* proto)
-{
+{
while (clazz != NULL) {
int i;
INLINE bool dvmIsAbstractClass(const ClassObject* clazz) {
return (clazz->accessFlags & ACC_ABSTRACT) != 0;
}
-INLINE bool dvmIsAnnotationClass(const ClassObject* clazz) {
- return (clazz->accessFlags & ACC_ANNOTATION) != 0;
+INLINE bool dvmIsAnnotationClass(const ClassObject* clazz) {
+ return (clazz->accessFlags & ACC_ANNOTATION) != 0;
}
INLINE bool dvmIsPrimitiveClass(const ClassObject* clazz) {
return clazz->primitiveType != PRIM_NOT;
*/
static u4 readUleb128(const u1** pBuf)
{
- u4 result = 0;
- int shift = 0;
+ u4 result = 0;
+ int shift = 0;
const u1* buf = *pBuf;
u1 val;
}
/*
- * Return an array of empty arrays of Annotation objects.
+ * Return an array of empty arrays of Annotation objects.
*
* Caller must call dvmReleaseTrackedAlloc().
*/
Thread* self = dvmThreadSelf();
ArrayObject* arr;
int i;
-
+
arr = dvmAllocArrayByClass(gDvm.classJavaLangAnnotationAnnotationArrayArray,
numElements, ALLOC_DEFAULT);
if (arr != NULL) {
/**
* Initializes an encoded array iterator.
- *
+ *
* @param iterator iterator to initialize
* @param encodedArray encoded array to iterate over
* @param clazz class to use when resolving strings and types
* cursor. This returns primitive values in their corresponding union
* slots, and returns everything else (including nulls) as object
* references in the "l" union slot.
- *
+ *
* The caller must call dvmReleaseTrackedAlloc() on any returned reference.
- *
+ *
* @param value pointer to store decoded value into
* @returns true if a value was decoded and the cursor advanced; false if
* the last value had already been decoded or if there was a problem decoding
ArrayObject* throws = NULL;
ClassObject* newClass = NULL;
int i;
-
+
nameStr = dvmCreateCstrFromString(str);
if (nameStr == NULL) {
dvmThrowException("Ljava/lang/IllegalArgumentException;",
meth->name = "<init>";
meth->prototype =
gDvm.methJavaLangReflectProxy_constructorPrototype->prototype;
- meth->shorty =
+ meth->shorty =
gDvm.methJavaLangReflectProxy_constructorPrototype->shorty;
// no pDexCode or pDexMethod
*/
int srcIndex = 0;
-
+
argCount = 0;
while (*desc != '\0') {
char descChar = *(desc++);
return false;
}
- gDvm.classJavaLangClassArray =
+ gDvm.classJavaLangClassArray =
dvmFindArrayClass("[Ljava/lang/Class;", NULL);
- gDvm.classJavaLangObjectArray =
+ gDvm.classJavaLangObjectArray =
dvmFindArrayClass("[Ljava/lang/Object;", NULL);
if (gDvm.classJavaLangClassArray == NULL ||
gDvm.classJavaLangObjectArray == NULL)
DataObject* dvmWrapPrimitive(JValue value, ClassObject* returnType)
{
static const char* boxTypes[] = { // order from enum PrimitiveType
- "Ljava/lang/Boolean;",
+ "Ljava/lang/Boolean;",
"Ljava/lang/Character;",
"Ljava/lang/Float;",
"Ljava/lang/Double;",
/**
* Initializes an encoded array iterator.
- *
+ *
* @param iterator iterator to initialize
* @param encodedArray encoded array to iterate over
* @param clazz class to use when resolving strings and types
* cursor. This returns primitive values in their corresponding union
* slots, and returns everything else (including nulls) as object
* references in the "l" union slot.
- *
+ *
* The caller must call dvmReleaseTrackedAlloc() on any returned reference.
- *
+ *
* @param value pointer to store decoded value into
* @returns true if a value was decoded and the cursor advanced; false if
* the last value had already been decoded or if there was a problem decoding
int* valuePtr = &value;
u8 start, end;
int i;
-
+
#ifdef TRIVIAL_COMPARE
/* init to arg value so compiler can't pre-determine result */
int j = repeatCount;