src/share/vm/runtime/stubCodeGenerator.cpp

Wed, 01 Dec 2010 15:04:06 +0100

author
stefank
date
Wed, 01 Dec 2010 15:04:06 +0100
changeset 2325
c760f78e0a53
parent 2314
f95d63e2154a
child 2508
b92c45f2bc75
permissions
-rw-r--r--

7003125: precompiled.hpp is included when precompiled headers are not used
Summary: Added an ifndef DONT_USE_PRECOMPILED_HEADER to precompiled.hpp. Set up DONT_USE_PRECOMPILED_HEADER when compiling with Sun Studio or when the user specifies USE_PRECOMPILED_HEADER=0. Fixed broken include dependencies.
Reviewed-by: coleenp, kvn

     1 /*
     2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #include "precompiled.hpp"
    26 #include "compiler/disassembler.hpp"
    27 #include "oops/oop.inline.hpp"
    28 #include "prims/forte.hpp"
    29 #include "runtime/stubCodeGenerator.hpp"
    30 #ifdef TARGET_ARCH_x86
    31 # include "assembler_x86.inline.hpp"
    32 #endif
    33 #ifdef TARGET_ARCH_sparc
    34 # include "assembler_sparc.inline.hpp"
    35 #endif
    36 #ifdef TARGET_ARCH_zero
    37 # include "assembler_zero.inline.hpp"
    38 #endif
    41 // Implementation of StubCodeDesc
    43 StubCodeDesc* StubCodeDesc::_list = NULL;
    44 int           StubCodeDesc::_count = 0;
    47 StubCodeDesc* StubCodeDesc::desc_for(address pc) {
    48   StubCodeDesc* p = _list;
    49   while (p != NULL && !p->contains(pc)) p = p->_next;
    50   // p == NULL || p->contains(pc)
    51   return p;
    52 }
    55 StubCodeDesc* StubCodeDesc::desc_for_index(int index) {
    56   StubCodeDesc* p = _list;
    57   while (p != NULL && p->index() != index) p = p->_next;
    58   return p;
    59 }
    62 const char* StubCodeDesc::name_for(address pc) {
    63   StubCodeDesc* p = desc_for(pc);
    64   return p == NULL ? NULL : p->name();
    65 }
    68 void StubCodeDesc::print_on(outputStream* st) const {
    69   st->print(group());
    70   st->print("::");
    71   st->print(name());
    72   st->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT "[ (%d bytes)", begin(), end(), size_in_bytes());
    73 }
    75 // Implementation of StubCodeGenerator
    77 StubCodeGenerator::StubCodeGenerator(CodeBuffer* code) {
    78   _masm = new MacroAssembler(code);
    79   _first_stub = _last_stub = NULL;
    80 }
    82 extern "C" {
    83   static int compare_cdesc(const void* void_a, const void* void_b) {
    84     int ai = (*((StubCodeDesc**) void_a))->index();
    85     int bi = (*((StubCodeDesc**) void_b))->index();
    86     return ai - bi;
    87   }
    88 }
    90 StubCodeGenerator::~StubCodeGenerator() {
    91   if (PrintStubCode) {
    92     CodeBuffer* cbuf = _masm->code();
    93     CodeBlob*   blob = CodeCache::find_blob_unsafe(cbuf->insts()->start());
    94     if (blob != NULL) {
    95       blob->set_comments(cbuf->comments());
    96     }
    97     bool saw_first = false;
    98     StubCodeDesc* toprint[1000];
    99     int toprint_len = 0;
   100     for (StubCodeDesc* cdesc = _last_stub; cdesc != NULL; cdesc = cdesc->_next) {
   101       toprint[toprint_len++] = cdesc;
   102       if (cdesc == _first_stub) { saw_first = true; break; }
   103     }
   104     assert(saw_first, "must get both first & last");
   105     // Print in reverse order:
   106     qsort(toprint, toprint_len, sizeof(toprint[0]), compare_cdesc);
   107     for (int i = 0; i < toprint_len; i++) {
   108       StubCodeDesc* cdesc = toprint[i];
   109       cdesc->print();
   110       tty->cr();
   111       Disassembler::decode(cdesc->begin(), cdesc->end());
   112       tty->cr();
   113     }
   114   }
   115 }
   118 void StubCodeGenerator::stub_prolog(StubCodeDesc* cdesc) {
   119   // default implementation - do nothing
   120 }
   123 void StubCodeGenerator::stub_epilog(StubCodeDesc* cdesc) {
   124   // default implementation - record the cdesc
   125   if (_first_stub == NULL)  _first_stub = cdesc;
   126   _last_stub = cdesc;
   127 }
   130 // Implementation of CodeMark
   132 StubCodeMark::StubCodeMark(StubCodeGenerator* cgen, const char* group, const char* name) {
   133   _cgen  = cgen;
   134   _cdesc = new StubCodeDesc(group, name, _cgen->assembler()->pc());
   135   _cgen->stub_prolog(_cdesc);
   136   // define the stub's beginning (= entry point) to be after the prolog:
   137   _cdesc->set_begin(_cgen->assembler()->pc());
   138 }
   140 StubCodeMark::~StubCodeMark() {
   141   _cgen->assembler()->flush();
   142   _cdesc->set_end(_cgen->assembler()->pc());
   143   assert(StubCodeDesc::_list == _cdesc, "expected order on list");
   144   _cgen->stub_epilog(_cdesc);
   145   Forte::register_stub(_cdesc->name(), _cdesc->begin(), _cdesc->end());
   147   if (JvmtiExport::should_post_dynamic_code_generated()) {
   148     JvmtiExport::post_dynamic_code_generated(_cdesc->name(), _cdesc->begin(), _cdesc->end());
   149   }
   150 }

mercurial