blob: 3895d776604a9f7fda53a0bd8cc4b5f56831c69e [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/*
37 * FIXME - redo for x86
38 *
39 * Translation layout in the code cache. Note that the codeAddress pointer
40 * in JitTable will point directly to the code body (field codeAddress). The
41 * chain cell offset codeAddress - 2, and (if present) executionCount is at
42 * codeAddress - 6.
43 *
44 * +----------------------------+
45 * | Execution count | -> [Optional] 4 bytes
46 * +----------------------------+
47 * +--| Offset to chain cell counts| -> 2 bytes
48 * | +----------------------------+
49 * | | Code body | -> Start address for translation
50 * | | | variable in 2-byte chunks
51 * | . . (JitTable's codeAddress points here)
52 * | . .
53 * | | |
54 * | +----------------------------+
55 * | | Chaining Cells | -> 12/16 bytes each, must be 4 byte aligned
56 * | . .
57 * | . .
58 * | | |
59 * | +----------------------------+
60 * | | Gap for large switch stmt | -> # cases >= MAX_CHAINED_SWITCH_CASES
61 * | +----------------------------+
62 * +->| Chaining cell counts | -> 8 bytes, chain cell counts by type
63 * +----------------------------+
64 * | Trace description | -> variable sized
65 * . .
66 * | |
67 * +----------------------------+
68 * | Literal pool | -> 4-byte aligned, variable size
69 * . .
70 * . .
71 * | |
72 * +----------------------------+
73 *
74 * Go over each instruction in the list and calculate the offset from the top
75 * before sending them off to the assembler. If out-of-range branch distance is
76 * seen rearrange the instructions a bit to correct it.
77 */
78void dvmCompilerAssembleLIR(CompilationUnit *cUnit, JitTranslationInfo *info)
79{
80}
81
82/*
83 * Perform translation chain operation.
84 */
85void* dvmJitChain(void* tgtAddr, u4* branchAddr)
86{
87 return 0;
88}
89
90/*
91 * This method is called from the invoke templates for virtual and interface
92 * methods to speculatively setup a chain to the callee. The templates are
93 * written in assembly and have setup method, cell, and clazz at r0, r2, and
94 * r3 respectively, so there is a unused argument in the list. Upon return one
95 * of the following three results may happen:
96 * 1) Chain is not setup because the callee is native. Reset the rechain
97 * count to a big number so that it will take a long time before the next
98 * rechain attempt to happen.
99 * 2) Chain is not setup because the callee has not been created yet. Reset
100 * the rechain count to a small number and retry in the near future.
Ben Chengaf5aa1f2011-01-04 15:37:04 -0800101 * 3) Enqueue the new content for the chaining cell which will be appled in
102 * next safe point.
buzbee7520ee72010-09-17 16:01:49 -0700103 */
104const Method *dvmJitToPatchPredictedChain(const Method *method,
105 InterpState *interpState,
106 PredictedChainingCell *cell,
107 const ClassObject *clazz)
108{
109 return 0;
110}
111
112/*
113 * Patch the inline cache content based on the content passed from the work
114 * order.
115 */
116void dvmCompilerPatchInlineCache(void)
117{
118}
119
120/*
121 * Unchain a trace given the starting address of the translation
122 * in the code cache. Refer to the diagram in dvmCompilerAssembleLIR.
123 * Returns the address following the last cell unchained. Note that
124 * the incoming codeAddr is a thumb code address, and therefore has
125 * the low bit set.
126 */
127u4* dvmJitUnchain(void* codeAddr)
128{
129 return 0;
130}
131
132/* Unchain all translation in the cache. */
133void dvmJitUnchainAll()
134{
135}
136
137/* Create a copy of the trace descriptor of an existing compilation */
138JitTraceDescription *dvmCopyTraceDescriptor(const u2 *pc,
139 const JitEntry *knownEntry)
140{
141 return 0;
142}
143
144/* Sort the trace profile counts and dump them */
145void dvmCompilerSortAndPrintTraceProfiles()
146{
147}