1 /*
2 * Copyright (C) 2008 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 /*
18 * Mterp entry point and support functions.
19 */
20 #include "mterp/Mterp.h"
21
22 #include <stddef.h>
23
24
25 /*
26 * Verify some constants used by the mterp interpreter.
27 */
dvmCheckAsmConstants(void)28 bool dvmCheckAsmConstants(void)
29 {
30 bool failed = false;
31
32 #ifndef DVM_NO_ASM_INTERP
33
34 extern char dvmAsmInstructionStart[];
35 extern char dvmAsmInstructionEnd[];
36
37 #define ASM_DEF_VERIFY
38 #include "mterp/common/asm-constants.h"
39
40 if (failed) {
41 LOGE("Please correct the values in mterp/common/asm-constants.h\n");
42 dvmAbort();
43 }
44
45 /*
46 * If an instruction overflows the 64-byte handler size limit, it will
47 * push everything up and alter the total size. Check it here.
48 */
49 const int width = 64;
50 int interpSize = dvmAsmInstructionEnd - dvmAsmInstructionStart;
51 if (interpSize != 0 && interpSize != 256*width) {
52 LOGE("ERROR: unexpected asm interp size %d\n", interpSize);
53 LOGE("(did an instruction handler exceed %d bytes?)\n", width);
54 dvmAbort();
55 }
56
57 #endif // ndef DVM_NO_ASM_INTERP
58
59 return !failed;
60 }
61
62
63 /*
64 * "Standard" mterp entry point. This sets up a "glue" structure and then
65 * calls into the assembly interpreter implementation.
66 *
67 * (There is presently no "debug" entry point.)
68 */
dvmMterpStd(Thread * self,InterpState * glue)69 bool dvmMterpStd(Thread* self, InterpState* glue)
70 {
71 int changeInterp;
72
73 /* configure mterp items */
74 glue->self = self;
75 glue->methodClassDex = glue->method->clazz->pDvmDex;
76
77 glue->interpStackEnd = self->interpStackEnd;
78 glue->pSelfSuspendCount = &self->suspendCount;
79 glue->cardTable = gDvm.biasedCardTableBase;
80 #if defined(WITH_JIT)
81 glue->pJitProfTable = gDvmJit.pProfTable;
82 glue->ppJitProfTable = &gDvmJit.pProfTable;
83 glue->jitThreshold = gDvmJit.threshold;
84 #endif
85 if (gDvm.jdwpConfigured) {
86 glue->pDebuggerActive = &gDvm.debuggerActive;
87 } else {
88 glue->pDebuggerActive = NULL;
89 }
90 glue->pActiveProfilers = &gDvm.activeProfilers;
91
92 IF_LOGVV() {
93 char* desc = dexProtoCopyMethodDescriptor(&glue->method->prototype);
94 LOGVV("mterp threadid=%d entry %d: %s.%s %s\n",
95 dvmThreadSelf()->threadId,
96 glue->entryPoint,
97 glue->method->clazz->descriptor,
98 glue->method->name,
99 desc);
100 free(desc);
101 }
102 //LOGI("glue is %p, pc=%p, fp=%p\n", glue, glue->pc, glue->fp);
103 //LOGI("first instruction is 0x%04x\n", glue->pc[0]);
104
105 changeInterp = dvmMterpStdRun(glue);
106
107 #if defined(WITH_JIT)
108 if (glue->jitState != kJitSingleStep) {
109 glue->self->inJitCodeCache = NULL;
110 }
111 #endif
112
113 if (!changeInterp) {
114 /* this is a "normal" exit; we're not coming back */
115 #ifdef LOG_INSTR
116 LOGD("|-- Leaving interpreter loop");
117 #endif
118 return false;
119 } else {
120 /* we're "standard", so switch to "debug" */
121 LOGVV(" mterp returned, changeInterp=%d\n", changeInterp);
122 glue->nextMode = INTERP_DBG;
123 return true;
124 }
125 }
126