00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 # include "incls/_precompiled.incl"
00025 # include "incls/_codeBuffer.cpp.incl"
00026 # ifdef DELTA_COMPILER
00027
00028
00029 MacroAssembler* theMacroAssm = NULL;
00030
00031
00032 CodeBuffer::CodeBuffer(int instsSize, int locsSize) {
00033 instsStart = instsEnd = NEW_RESOURCE_ARRAY(char, instsSize);
00034 instsOverflow = instsStart + instsSize;
00035 locsStart = locsEnd = (relocInfo*) NEW_RESOURCE_ARRAY(char, locsSize);
00036 locsOverflow = (relocInfo*) ((char*) locsStart + locsSize);
00037 last_reloc_offset = code_size();
00038 _decode_begin = NULL;
00039 }
00040
00041
00042 CodeBuffer::CodeBuffer(char* code_start, int code_size) {
00043 instsStart = instsEnd = (char*)code_start;
00044 instsOverflow = instsStart + code_size;
00045 locsStart = locsEnd = NULL;
00046 locsOverflow = NULL;
00047 last_reloc_offset = CodeBuffer::code_size();
00048 _decode_begin = NULL;
00049 }
00050
00051
00052 char* CodeBuffer::decode_begin() {
00053 return _decode_begin == NULL ? (char*)instsStart : _decode_begin;
00054 }
00055
00056
00057 void CodeBuffer::set_code_end(char* end) {
00058 if ((char*)end < instsStart || instsOverflow < (char*)end) fatal("code end out of bounds");
00059 instsEnd = (char*)end;
00060 }
00061
00062
00063 void CodeBuffer::relocate(char* at, relocInfo::relocType rtype) {
00064 assert(code_begin() <= at && at <= code_end(), "cannot relocate data outside code boundaries");
00065 if (locsEnd == NULL) {
00066
00067
00068
00069 assert(rtype == relocInfo::none ||
00070 rtype == relocInfo::runtime_call_type ||
00071 rtype == relocInfo::external_word_type, "code needs relocation information");
00072 } else {
00073 assert(sizeof(relocInfo) == sizeof(short), "change this code");
00074 int len = at - instsStart;
00075 int offset = len - last_reloc_offset;
00076 last_reloc_offset = len;
00077 *locsEnd++ = relocInfo(rtype, offset);
00078 if (locsEnd >= locsOverflow) fatal("routine is too long to compile");
00079 }
00080 }
00081
00082
00083 void CodeBuffer::decode() {
00084 Disassembler::decode((char*)decode_begin(), (char*)code_end());
00085 _decode_begin = code_end();
00086 }
00087
00088
00089 void CodeBuffer::decode_all() {
00090 Disassembler::decode((char*)code_begin(), (char*)code_end());
00091 }
00092
00093
00094 void CodeBuffer::copyTo(nmethod* nm) {
00095 const char hlt = '\xF4';
00096 while (code_size() % oopSize != 0) *instsEnd++ = hlt;
00097 while (reloc_size() % oopSize != 0) *locsEnd++ = relocInfo(false, 0);
00098
00099 copy_oops((oop*)instsStart, (oop*)nm->insts(), code_size() /oopSize);
00100 copy_oops((oop*)locsStart, (oop*)nm->locs(), reloc_size()/oopSize);
00101
00102
00103 int delta = (char*)instsStart - (char*)nm->insts();
00104 nm->fix_relocation_at_move(delta);
00105 }
00106
00107
00108 void CodeBuffer::print() {
00109 std->print("CodeBuffer:\n");
00110 std->print("Code [0x%x <- used -> 0x%x[ <- free -> 0x%x[\n", instsStart, instsEnd, instsOverflow);
00111 std->print("Reloc [0x%x <- used -> 0x%x[ <- free -> 0x%x[\n", locsStart, locsEnd, locsOverflow );
00112 }
00113
00114
00115 # endif