hotspot/src/share/vm/runtime/stubCodeGenerator.cpp
author phh
Wed, 28 Oct 2009 16:25:51 -0400
changeset 4434 4b41e5b42f81
parent 670 ddf3e9583f2f
child 5547 f4b087cbb361
permissions -rw-r--r--
6887571: Increase default heap config sizes Summary: Apply modification of existing server heap size ergo to all collectors except CMS. Reviewed-by: jmasa, ysr, xlu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
670
ddf3e9583f2f 6719955: Update copyright year
xdono
parents: 347
diff changeset
     2
 * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_stubCodeGenerator.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// Implementation of StubCodeDesc
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
StubCodeDesc* StubCodeDesc::_list = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
int           StubCodeDesc::_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
StubCodeDesc* StubCodeDesc::desc_for(address pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  StubCodeDesc* p = _list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  while (p != NULL && !p->contains(pc)) p = p->_next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  // p == NULL || p->contains(pc)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
StubCodeDesc* StubCodeDesc::desc_for_index(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  StubCodeDesc* p = _list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  while (p != NULL && p->index() != index) p = p->_next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
const char* StubCodeDesc::name_for(address pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  StubCodeDesc* p = desc_for(pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  return p == NULL ? NULL : p->name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
void StubCodeDesc::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  tty->print(group());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  tty->print("::");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  tty->print(name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  tty->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT "[ (%d bytes)", begin(), end(), size_in_bytes());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
// Implementation of StubCodeGenerator
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
StubCodeGenerator::StubCodeGenerator(CodeBuffer* code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  _masm = new MacroAssembler(code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  _first_stub = _last_stub = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
extern "C" {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  static int compare_cdesc(const void* void_a, const void* void_b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    int ai = (*((StubCodeDesc**) void_a))->index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    int bi = (*((StubCodeDesc**) void_b))->index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    return ai - bi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
StubCodeGenerator::~StubCodeGenerator() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  if (PrintStubCode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    CodeBuffer* cbuf = _masm->code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    CodeBlob*   blob = CodeCache::find_blob_unsafe(cbuf->insts()->start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    if (blob != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
      blob->set_comments(cbuf->comments());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    bool saw_first = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    StubCodeDesc* toprint[1000];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    int toprint_len = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    for (StubCodeDesc* cdesc = _last_stub; cdesc != NULL; cdesc = cdesc->_next) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      toprint[toprint_len++] = cdesc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      if (cdesc == _first_stub) { saw_first = true; break; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    assert(saw_first, "must get both first & last");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    // Print in reverse order:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    qsort(toprint, toprint_len, sizeof(toprint[0]), compare_cdesc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    for (int i = 0; i < toprint_len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
      StubCodeDesc* cdesc = toprint[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      cdesc->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
      Disassembler::decode(cdesc->begin(), cdesc->end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
void StubCodeGenerator::stub_prolog(StubCodeDesc* cdesc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  // default implementation - do nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
void StubCodeGenerator::stub_epilog(StubCodeDesc* cdesc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // default implementation - record the cdesc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  if (_first_stub == NULL)  _first_stub = cdesc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  _last_stub = cdesc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
// Implementation of CodeMark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
StubCodeMark::StubCodeMark(StubCodeGenerator* cgen, const char* group, const char* name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  _cgen  = cgen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  _cdesc = new StubCodeDesc(group, name, _cgen->assembler()->pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  _cgen->stub_prolog(_cdesc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // define the stub's beginning (= entry point) to be after the prolog:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  _cdesc->set_begin(_cgen->assembler()->pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
StubCodeMark::~StubCodeMark() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  _cgen->assembler()->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  _cdesc->set_end(_cgen->assembler()->pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  assert(StubCodeDesc::_list == _cdesc, "expected order on list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  _cgen->stub_epilog(_cdesc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  VTune::register_stub(_cdesc->name(), _cdesc->begin(), _cdesc->end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  Forte::register_stub(_cdesc->name(), _cdesc->begin(), _cdesc->end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  if (JvmtiExport::should_post_dynamic_code_generated()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    JvmtiExport::post_dynamic_code_generated(_cdesc->name(), _cdesc->begin(), _cdesc->end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
}