blob: fcc497419596898767dccd5ec40c6d6e76954a2e [file] [log] [blame]
buzbee7520ee72010-09-17 16:01:49 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "Dalvik.h"
18#include "libdex/OpCode.h"
19#include "libdex/OpCodeNames.h"
20
21#include "../../CompilerInternals.h"
22#include "X86LIR.h"
23#include "Codegen.h"
24#include <unistd.h> /* for cacheflush */
25#include <sys/mman.h> /* for protection change */
26
27#define MAX_ASSEMBLER_RETRIES 10
28
29
30/* Track the number of times that the code cache is patched */
31#if defined(WITH_JIT_TUNING)
32#define UPDATE_CODE_CACHE_PATCHES() (gDvmJit.codeCachePatches++)
33#else
34#define UPDATE_CODE_CACHE_PATCHES()
35#endif
36
37/*
38 * FIXME - redo for x86
39 *
40 * Translation layout in the code cache. Note that the codeAddress pointer
41 * in JitTable will point directly to the code body (field codeAddress). The
42 * chain cell offset codeAddress - 2, and (if present) executionCount is at
43 * codeAddress - 6.
44 *
45 * +----------------------------+
46 * | Execution count | -> [Optional] 4 bytes
47 * +----------------------------+
48 * +--| Offset to chain cell counts| -> 2 bytes
49 * | +----------------------------+
50 * | | Code body | -> Start address for translation
51 * | | | variable in 2-byte chunks
52 * | . . (JitTable's codeAddress points here)
53 * | . .
54 * | | |
55 * | +----------------------------+
56 * | | Chaining Cells | -> 12/16 bytes each, must be 4 byte aligned
57 * | . .
58 * | . .
59 * | | |
60 * | +----------------------------+
61 * | | Gap for large switch stmt | -> # cases >= MAX_CHAINED_SWITCH_CASES
62 * | +----------------------------+
63 * +->| Chaining cell counts | -> 8 bytes, chain cell counts by type
64 * +----------------------------+
65 * | Trace description | -> variable sized
66 * . .
67 * | |
68 * +----------------------------+
69 * | Literal pool | -> 4-byte aligned, variable size
70 * . .
71 * . .
72 * | |
73 * +----------------------------+
74 *
75 * Go over each instruction in the list and calculate the offset from the top
76 * before sending them off to the assembler. If out-of-range branch distance is
77 * seen rearrange the instructions a bit to correct it.
78 */
79void dvmCompilerAssembleLIR(CompilationUnit *cUnit, JitTranslationInfo *info)
80{
81}
82
83/*
84 * Perform translation chain operation.
85 */
86void* dvmJitChain(void* tgtAddr, u4* branchAddr)
87{
88 return 0;
89}
90
91/*
92 * This method is called from the invoke templates for virtual and interface
93 * methods to speculatively setup a chain to the callee. The templates are
94 * written in assembly and have setup method, cell, and clazz at r0, r2, and
95 * r3 respectively, so there is a unused argument in the list. Upon return one
96 * of the following three results may happen:
97 * 1) Chain is not setup because the callee is native. Reset the rechain
98 * count to a big number so that it will take a long time before the next
99 * rechain attempt to happen.
100 * 2) Chain is not setup because the callee has not been created yet. Reset
101 * the rechain count to a small number and retry in the near future.
102 * 3) Ask all other threads to stop before patching this chaining cell.
103 * This is required because another thread may have passed the class check
104 * but hasn't reached the chaining cell yet to follow the chain. If we
105 * patch the content before halting the other thread, there could be a
106 * small window for race conditions to happen that it may follow the new
107 * but wrong chain to invoke a different method.
108 */
109const Method *dvmJitToPatchPredictedChain(const Method *method,
110 InterpState *interpState,
111 PredictedChainingCell *cell,
112 const ClassObject *clazz)
113{
114 return 0;
115}
116
117/*
118 * Patch the inline cache content based on the content passed from the work
119 * order.
120 */
121void dvmCompilerPatchInlineCache(void)
122{
123}
124
125/*
126 * Unchain a trace given the starting address of the translation
127 * in the code cache. Refer to the diagram in dvmCompilerAssembleLIR.
128 * Returns the address following the last cell unchained. Note that
129 * the incoming codeAddr is a thumb code address, and therefore has
130 * the low bit set.
131 */
132u4* dvmJitUnchain(void* codeAddr)
133{
134 return 0;
135}
136
137/* Unchain all translation in the cache. */
138void dvmJitUnchainAll()
139{
140}
141
142/* Create a copy of the trace descriptor of an existing compilation */
143JitTraceDescription *dvmCopyTraceDescriptor(const u2 *pc,
144 const JitEntry *knownEntry)
145{
146 return 0;
147}
148
149/* Sort the trace profile counts and dump them */
150void dvmCompilerSortAndPrintTraceProfiles()
151{
152}