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