annotate src/share/vm/runtime/stubCodeGenerator.cpp @ 1091:6aa7255741f3

6906727: UseCompressedOops: some card-marking fixes related to object arrays Summary: Introduced a new write_ref_array(HeapWords* start, size_t count) method that does the requisite MemRegion range calculation so (some of the) clients of the erstwhile write_ref_array(MemRegion mr) do not need to worry. This removed all external uses of array_size(), which was also simplified and made private. Asserts were added to catch other possible issues. Further, less essential, fixes stemming from this investigation are deferred to CR 6904516 (to follow shortly in hs17). Reviewed-by: kvn, coleenp, jmasa
author ysr
date Thu, 03 Dec 2009 15:01:57 -0800
parents d1605aabd0a1
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
196
d1605aabd0a1 6719955: Update copyright year
xdono
parents: 100
diff changeset
2 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_stubCodeGenerator.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // Implementation of StubCodeDesc
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 StubCodeDesc* StubCodeDesc::_list = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 int StubCodeDesc::_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 StubCodeDesc* StubCodeDesc::desc_for(address pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 StubCodeDesc* p = _list;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 while (p != NULL && !p->contains(pc)) p = p->_next;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // p == NULL || p->contains(pc)
a61af66fc99e Initial load
duke
parents:
diff changeset
39 return p;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 }
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 StubCodeDesc* StubCodeDesc::desc_for_index(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 StubCodeDesc* p = _list;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 while (p != NULL && p->index() != index) p = p->_next;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 return p;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 }
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 const char* StubCodeDesc::name_for(address pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 StubCodeDesc* p = desc_for(pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
52 return p == NULL ? NULL : p->name();
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 void StubCodeDesc::print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 tty->print(group());
a61af66fc99e Initial load
duke
parents:
diff changeset
58 tty->print("::");
a61af66fc99e Initial load
duke
parents:
diff changeset
59 tty->print(name());
a61af66fc99e Initial load
duke
parents:
diff changeset
60 tty->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT "[ (%d bytes)", begin(), end(), size_in_bytes());
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // Implementation of StubCodeGenerator
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 StubCodeGenerator::StubCodeGenerator(CodeBuffer* code) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 _masm = new MacroAssembler(code);
a61af66fc99e Initial load
duke
parents:
diff changeset
69 _first_stub = _last_stub = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 extern "C" {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 static int compare_cdesc(const void* void_a, const void* void_b) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 int ai = (*((StubCodeDesc**) void_a))->index();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 int bi = (*((StubCodeDesc**) void_b))->index();
a61af66fc99e Initial load
duke
parents:
diff changeset
76 return ai - bi;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 StubCodeGenerator::~StubCodeGenerator() {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 if (PrintStubCode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 CodeBuffer* cbuf = _masm->code();
a61af66fc99e Initial load
duke
parents:
diff changeset
83 CodeBlob* blob = CodeCache::find_blob_unsafe(cbuf->insts()->start());
a61af66fc99e Initial load
duke
parents:
diff changeset
84 if (blob != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 blob->set_comments(cbuf->comments());
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87 bool saw_first = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 StubCodeDesc* toprint[1000];
a61af66fc99e Initial load
duke
parents:
diff changeset
89 int toprint_len = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 for (StubCodeDesc* cdesc = _last_stub; cdesc != NULL; cdesc = cdesc->_next) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 toprint[toprint_len++] = cdesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 if (cdesc == _first_stub) { saw_first = true; break; }
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94 assert(saw_first, "must get both first & last");
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // Print in reverse order:
a61af66fc99e Initial load
duke
parents:
diff changeset
96 qsort(toprint, toprint_len, sizeof(toprint[0]), compare_cdesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
97 for (int i = 0; i < toprint_len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 StubCodeDesc* cdesc = toprint[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
99 cdesc->print();
a61af66fc99e Initial load
duke
parents:
diff changeset
100 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
101 Disassembler::decode(cdesc->begin(), cdesc->end());
a61af66fc99e Initial load
duke
parents:
diff changeset
102 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 void StubCodeGenerator::stub_prolog(StubCodeDesc* cdesc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // default implementation - do nothing
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 void StubCodeGenerator::stub_epilog(StubCodeDesc* cdesc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 // default implementation - record the cdesc
a61af66fc99e Initial load
duke
parents:
diff changeset
115 if (_first_stub == NULL) _first_stub = cdesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 _last_stub = cdesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // Implementation of CodeMark
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 StubCodeMark::StubCodeMark(StubCodeGenerator* cgen, const char* group, const char* name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 _cgen = cgen;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 _cdesc = new StubCodeDesc(group, name, _cgen->assembler()->pc());
a61af66fc99e Initial load
duke
parents:
diff changeset
125 _cgen->stub_prolog(_cdesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // define the stub's beginning (= entry point) to be after the prolog:
a61af66fc99e Initial load
duke
parents:
diff changeset
127 _cdesc->set_begin(_cgen->assembler()->pc());
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 StubCodeMark::~StubCodeMark() {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 _cgen->assembler()->flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
132 _cdesc->set_end(_cgen->assembler()->pc());
a61af66fc99e Initial load
duke
parents:
diff changeset
133 assert(StubCodeDesc::_list == _cdesc, "expected order on list");
a61af66fc99e Initial load
duke
parents:
diff changeset
134 _cgen->stub_epilog(_cdesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
135 VTune::register_stub(_cdesc->name(), _cdesc->begin(), _cdesc->end());
a61af66fc99e Initial load
duke
parents:
diff changeset
136 Forte::register_stub(_cdesc->name(), _cdesc->begin(), _cdesc->end());
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 if (JvmtiExport::should_post_dynamic_code_generated()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 JvmtiExport::post_dynamic_code_generated(_cdesc->name(), _cdesc->begin(), _cdesc->end());
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }