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" 18 #include "libdex/DexOpcodes.h" 19 20 #include "../../CompilerInternals.h" 21 #include "X86LIR.h" 22 #include "Codegen.h" 23 #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 /* 36 * 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 * | +----------------------------+ 52 * | | Chaining Cells | -> 16 bytes each, 8 byte aligned 53 * | . . 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 66 * . . Note: for x86 literals will 67 * . . generally appear inline. 68 * | | 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 */ 75 void dvmCompilerAssembleLIR(CompilationUnit *cUnit, JitTranslationInfo *info) 76 { 77 } 78 79 /* 80 * Perform translation chain operation. 81 */ 82 void* 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) Enqueue the new content for the chaining cell which will be appled in 99 * next safe point. 100 */ 101 const Method *dvmJitToPatchPredictedChain(const Method *method, 102 Thread *self, 103 PredictedChainingCell *cell, 104 const ClassObject *clazz) 105 { 106 return 0; 107 } 108 109 /* 110 * Patch the inline cache content based on the content passed from the work 111 * order. 112 */ 113 void dvmCompilerPatchInlineCache(void) 114 { 115 } 116 117 /* 118 * Unchain a trace given the starting address of the translation 119 * in the code cache. Refer to the diagram in dvmCompilerAssembleLIR. 120 * Returns the address following the last cell unchained. Note that 121 * the incoming codeAddr is a thumb code address, and therefore has 122 * the low bit set. 123 */ 124 u4* dvmJitUnchain(void* codeAddr) 125 { 126 return 0; 127 } 128 129 /* Unchain all translation in the cache. */ 130 void dvmJitUnchainAll() 131 { 132 } 133 134 /* Create a copy of the trace descriptor of an existing compilation */ 135 JitTraceDescription *dvmCopyTraceDescriptor(const u2 *pc, 136 const JitEntry *knownEntry) 137 { 138 return 0; 139 } 140 141 /* Sort the trace profile counts and dump them */ 142 void dvmCompilerSortAndPrintTraceProfiles() 143 { 144 } 145 146 void dvmJitScanAllClassPointers(void (*callback)(void *)) 147 { 148 } 149