ArchVariant.cpp revision a8b91c52fd8a90b784835dfe1f8898035266c4dd
1/*
2 * Copyright (C) 2009 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
17extern "C" void dvmCompilerTemplateStart(void);
18
19/*
20 * This file is included by Codegen-mips.c, and implements architecture
21 * variant-specific code.
22 */
23
24/*
25 * Determine the initial instruction set to be used for this trace.
26 * Later components may decide to change this.
27 */
28JitInstructionSetType dvmCompilerInstructionSet(void)
29{
30    return DALVIK_JIT_MIPS;
31}
32
33/* First, declare dvmCompiler_TEMPLATE_XXX for each template */
34#define JIT_TEMPLATE(X) extern "C" void dvmCompiler_TEMPLATE_##X();
35#include "../../../template/mips/TemplateOpList.h"
36#undef JIT_TEMPLATE
37
38/* Architecture-specific initializations and checks go here */
39bool dvmCompilerArchVariantInit(void)
40{
41    int i = 0;
42
43    /*
44     * Then, populate the templateEntryOffsets array with the offsets from the
45     * the dvmCompilerTemplateStart symbol for each template.
46     */
47#define JIT_TEMPLATE(X) templateEntryOffsets[i++] = \
48    (intptr_t) dvmCompiler_TEMPLATE_##X - (intptr_t) dvmCompilerTemplateStart;
49#include "../../../template/mips/TemplateOpList.h"
50#undef JIT_TEMPLATE
51
52    /* Target-specific configuration */
53    gDvmJit.jitTableSize = 1 << 9; // 512
54    gDvmJit.jitTableMask = gDvmJit.jitTableSize - 1;
55    gDvmJit.threshold = 200;
56    gDvmJit.codeCacheSize = 512*1024;
57
58#if defined(WITH_SELF_VERIFICATION)
59    /* Force into blocking mode */
60    gDvmJit.blockingMode = true;
61    gDvm.nativeDebuggerActive = true;
62#endif
63
64    /* Codegen-specific assumptions */
65    assert(OFFSETOF_MEMBER(ClassObject, vtable) < 128 &&
66           (OFFSETOF_MEMBER(ClassObject, vtable) & 0x3) == 0);
67    assert(OFFSETOF_MEMBER(ArrayObject, length) < 128 &&
68           (OFFSETOF_MEMBER(ArrayObject, length) & 0x3) == 0);
69    assert(OFFSETOF_MEMBER(ArrayObject, contents) < 256);
70
71    /* Up to 5 args are pushed on top of FP - sizeofStackSaveArea */
72    assert(sizeof(StackSaveArea) < 236);
73
74    /*
75     * EA is calculated by doing "Rn + imm5 << 2", make sure that the last
76     * offset from the struct is less than 128.
77     */
78    assert((offsetof(Thread, jitToInterpEntries) +
79            sizeof(struct JitToInterpEntries)) < 128);
80
81    /* FIXME - comment out the following to enable method-based JIT */
82    gDvmJit.disableOpt |= (1 << kMethodJit);
83
84    // Make sure all threads have current values
85    dvmJitUpdateThreadStateAll();
86
87    return true;
88}
89
90int dvmCompilerTargetOptHint(int key)
91{
92    int res;
93    switch (key) {
94        case kMaxHoistDistance:
95            res = 2;
96            break;
97        default:
98            LOGE("Unknown target optimization hint key: %d",key);
99            res = 0;
100    }
101    return res;
102}
103
104void dvmCompilerGenMemBarrier(CompilationUnit *cUnit, int barrierKind)
105{
106    __asm__ __volatile__ ("" : : : "memory");
107}
108