codeBuffer.cpp

Go to the documentation of this file.
00001 /* Copyright 1994 - 1996, LongView Technologies L.L.C. $Revision: 1.3 $ */
00002 /* Copyright (c) 2006, Sun Microsystems, Inc.
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 
00006 following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 
00010           disclaimer in the documentation and/or other materials provided with the distribution.
00011     * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 
00012           from this software without specific prior written permission.
00013 
00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 
00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
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     // no space for relocation information provided => code cannot be relocated
00067     // make sure that relocate is only called with rtypes that can be ignored for
00068     // this kind of code.
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;                        // align code
00097   while (reloc_size() % oopSize != 0) *locsEnd++  = relocInfo(false, 0);        // align relocation info
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   // Fix the pc relative information after the move
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

Generated on Mon Oct 9 13:37:05 2006 for Strongtalk VM by  doxygen 1.4.7