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