| buzbee | 7520ee7 | 2010-09-17 16:01:49 -0700 | [diff] [blame] | 1 | /* |
| 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 Bornstein | df4daaf | 2010-12-01 14:23:44 -0800 | [diff] [blame^] | 18 | #include "libdex/DexOpcodes.h" |
| buzbee | 7520ee7 | 2010-09-17 16:01:49 -0700 | [diff] [blame] | 19 | |
| 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 | */ |
| 78 | void dvmCompilerAssembleLIR(CompilationUnit *cUnit, JitTranslationInfo *info) |
| 79 | { |
| 80 | } |
| 81 | |
| 82 | /* |
| 83 | * Perform translation chain operation. |
| 84 | */ |
| 85 | void* 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. |
| 101 | * 3) Ask all other threads to stop before patching this chaining cell. |
| 102 | * This is required because another thread may have passed the class check |
| 103 | * but hasn't reached the chaining cell yet to follow the chain. If we |
| 104 | * patch the content before halting the other thread, there could be a |
| 105 | * small window for race conditions to happen that it may follow the new |
| 106 | * but wrong chain to invoke a different method. |
| 107 | */ |
| 108 | const Method *dvmJitToPatchPredictedChain(const Method *method, |
| 109 | InterpState *interpState, |
| 110 | PredictedChainingCell *cell, |
| 111 | const ClassObject *clazz) |
| 112 | { |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | /* |
| 117 | * Patch the inline cache content based on the content passed from the work |
| 118 | * order. |
| 119 | */ |
| 120 | void dvmCompilerPatchInlineCache(void) |
| 121 | { |
| 122 | } |
| 123 | |
| 124 | /* |
| 125 | * Unchain a trace given the starting address of the translation |
| 126 | * in the code cache. Refer to the diagram in dvmCompilerAssembleLIR. |
| 127 | * Returns the address following the last cell unchained. Note that |
| 128 | * the incoming codeAddr is a thumb code address, and therefore has |
| 129 | * the low bit set. |
| 130 | */ |
| 131 | u4* dvmJitUnchain(void* codeAddr) |
| 132 | { |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | /* Unchain all translation in the cache. */ |
| 137 | void dvmJitUnchainAll() |
| 138 | { |
| 139 | } |
| 140 | |
| 141 | /* Create a copy of the trace descriptor of an existing compilation */ |
| 142 | JitTraceDescription *dvmCopyTraceDescriptor(const u2 *pc, |
| 143 | const JitEntry *knownEntry) |
| 144 | { |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | /* Sort the trace profile counts and dump them */ |
| 149 | void dvmCompilerSortAndPrintTraceProfiles() |
| 150 | { |
| 151 | } |