src/share/vm/shark/sharkFunction.cpp

Mon, 04 Apr 2011 03:02:00 -0700

author
twisti
date
Mon, 04 Apr 2011 03:02:00 -0700
changeset 2729
e863062e521d
parent 2314
f95d63e2154a
child 4443
c095a7f289aa
permissions
-rw-r--r--

7032458: Zero and Shark fixes
Reviewed-by: twisti
Contributed-by: Gary Benson <gbenson@redhat.com>

twisti@2047 1 /*
stefank@2314 2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
twisti@2047 3 * Copyright 2008, 2009 Red Hat, Inc.
twisti@2047 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
twisti@2047 5 *
twisti@2047 6 * This code is free software; you can redistribute it and/or modify it
twisti@2047 7 * under the terms of the GNU General Public License version 2 only, as
twisti@2047 8 * published by the Free Software Foundation.
twisti@2047 9 *
twisti@2047 10 * This code is distributed in the hope that it will be useful, but WITHOUT
twisti@2047 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
twisti@2047 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
twisti@2047 13 * version 2 for more details (a copy is included in the LICENSE file that
twisti@2047 14 * accompanied this code).
twisti@2047 15 *
twisti@2047 16 * You should have received a copy of the GNU General Public License version
twisti@2047 17 * 2 along with this work; if not, write to the Free Software Foundation,
twisti@2047 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
twisti@2047 19 *
twisti@2047 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
twisti@2047 21 * or visit www.oracle.com if you need additional information or have any
twisti@2047 22 * questions.
twisti@2047 23 *
twisti@2047 24 */
twisti@2047 25
stefank@2314 26 #include "precompiled.hpp"
stefank@2314 27 #include "ci/ciTypeFlow.hpp"
stefank@2314 28 #include "memory/allocation.hpp"
stefank@2314 29 #include "shark/llvmHeaders.hpp"
stefank@2314 30 #include "shark/llvmValue.hpp"
stefank@2314 31 #include "shark/sharkBuilder.hpp"
stefank@2314 32 #include "shark/sharkEntry.hpp"
stefank@2314 33 #include "shark/sharkFunction.hpp"
stefank@2314 34 #include "shark/sharkState.hpp"
stefank@2314 35 #include "shark/sharkTopLevelBlock.hpp"
stefank@2314 36 #include "shark/shark_globals.hpp"
stefank@2314 37 #include "utilities/debug.hpp"
twisti@2047 38
twisti@2047 39 using namespace llvm;
twisti@2047 40
twisti@2047 41 void SharkFunction::initialize(const char *name) {
twisti@2047 42 // Create the function
twisti@2047 43 _function = Function::Create(
twisti@2047 44 entry_point_type(),
twisti@2047 45 GlobalVariable::InternalLinkage,
twisti@2047 46 name);
twisti@2047 47
twisti@2047 48 // Get our arguments
twisti@2047 49 Function::arg_iterator ai = function()->arg_begin();
twisti@2047 50 Argument *method = ai++;
twisti@2047 51 method->setName("method");
twisti@2047 52 Argument *osr_buf = NULL;
twisti@2047 53 if (is_osr()) {
twisti@2047 54 osr_buf = ai++;
twisti@2047 55 osr_buf->setName("osr_buf");
twisti@2047 56 }
twisti@2047 57 Argument *base_pc = ai++;
twisti@2047 58 base_pc->setName("base_pc");
twisti@2047 59 code_buffer()->set_base_pc(base_pc);
twisti@2047 60 Argument *thread = ai++;
twisti@2047 61 thread->setName("thread");
twisti@2047 62 set_thread(thread);
twisti@2047 63
twisti@2047 64 // Create the list of blocks
twisti@2047 65 set_block_insertion_point(NULL);
twisti@2047 66 _blocks = NEW_RESOURCE_ARRAY(SharkTopLevelBlock*, block_count());
twisti@2047 67 for (int i = 0; i < block_count(); i++) {
twisti@2047 68 ciTypeFlow::Block *b = flow()->pre_order_at(i);
twisti@2047 69
twisti@2047 70 // Work around a bug in pre_order_at() that does not return
twisti@2047 71 // the correct pre-ordering. If pre_order_at() were correct
twisti@2047 72 // this line could simply be:
twisti@2047 73 // _blocks[i] = new SharkTopLevelBlock(this, b);
twisti@2047 74 _blocks[b->pre_order()] = new SharkTopLevelBlock(this, b);
twisti@2047 75 }
twisti@2047 76
twisti@2047 77 // Walk the tree from the start block to determine which
twisti@2047 78 // blocks are entered and which blocks require phis
twisti@2047 79 SharkTopLevelBlock *start_block = block(flow()->start_block_num());
twisti@2047 80 assert(start_block->start() == flow()->start_bci(), "blocks out of order");
twisti@2047 81 start_block->enter();
twisti@2047 82
twisti@2047 83 // Initialize all entered blocks
twisti@2047 84 for (int i = 0; i < block_count(); i++) {
twisti@2047 85 if (block(i)->entered())
twisti@2047 86 block(i)->initialize();
twisti@2047 87 }
twisti@2047 88
twisti@2047 89 // Create and push our stack frame
twisti@2047 90 set_block_insertion_point(&function()->front());
twisti@2047 91 builder()->SetInsertPoint(CreateBlock());
twisti@2047 92 _stack = SharkStack::CreateBuildAndPushFrame(this, method);
twisti@2047 93
twisti@2047 94 // Create the entry state
twisti@2047 95 SharkState *entry_state;
twisti@2047 96 if (is_osr()) {
twisti@2047 97 entry_state = new SharkOSREntryState(start_block, method, osr_buf);
twisti@2047 98
twisti@2047 99 // Free the OSR buffer
twisti@2047 100 builder()->CreateCall(builder()->osr_migration_end(), osr_buf);
twisti@2047 101 }
twisti@2047 102 else {
twisti@2047 103 entry_state = new SharkNormalEntryState(start_block, method);
twisti@2047 104
twisti@2047 105 // Lock if necessary
twisti@2047 106 if (is_synchronized()) {
twisti@2047 107 SharkTopLevelBlock *locker =
twisti@2047 108 new SharkTopLevelBlock(this, start_block->ciblock());
twisti@2047 109 locker->add_incoming(entry_state);
twisti@2047 110
twisti@2047 111 set_block_insertion_point(start_block->entry_block());
twisti@2047 112 locker->acquire_method_lock();
twisti@2047 113
twisti@2047 114 entry_state = locker->current_state();
twisti@2047 115 }
twisti@2047 116 }
twisti@2047 117
twisti@2047 118 // Transition into the method proper
twisti@2047 119 start_block->add_incoming(entry_state);
twisti@2047 120 builder()->CreateBr(start_block->entry_block());
twisti@2047 121
twisti@2047 122 // Parse the blocks
twisti@2047 123 for (int i = 0; i < block_count(); i++) {
twisti@2047 124 if (!block(i)->entered())
twisti@2047 125 continue;
twisti@2047 126
twisti@2047 127 if (i + 1 < block_count())
twisti@2047 128 set_block_insertion_point(block(i + 1)->entry_block());
twisti@2047 129 else
twisti@2047 130 set_block_insertion_point(NULL);
twisti@2047 131
twisti@2047 132 block(i)->emit_IR();
twisti@2047 133 }
twisti@2047 134 do_deferred_zero_checks();
twisti@2047 135 }
twisti@2047 136
twisti@2047 137 class DeferredZeroCheck : public SharkTargetInvariants {
twisti@2047 138 public:
twisti@2047 139 DeferredZeroCheck(SharkTopLevelBlock* block, SharkValue* value)
twisti@2047 140 : SharkTargetInvariants(block),
twisti@2047 141 _block(block),
twisti@2047 142 _value(value),
twisti@2047 143 _bci(block->bci()),
twisti@2047 144 _state(block->current_state()->copy()),
twisti@2047 145 _check_block(builder()->GetInsertBlock()),
twisti@2047 146 _continue_block(function()->CreateBlock("not_zero")) {
twisti@2047 147 builder()->SetInsertPoint(continue_block());
twisti@2047 148 }
twisti@2047 149
twisti@2047 150 private:
twisti@2047 151 SharkTopLevelBlock* _block;
twisti@2047 152 SharkValue* _value;
twisti@2047 153 int _bci;
twisti@2047 154 SharkState* _state;
twisti@2047 155 BasicBlock* _check_block;
twisti@2047 156 BasicBlock* _continue_block;
twisti@2047 157
twisti@2047 158 public:
twisti@2047 159 SharkTopLevelBlock* block() const {
twisti@2047 160 return _block;
twisti@2047 161 }
twisti@2047 162 SharkValue* value() const {
twisti@2047 163 return _value;
twisti@2047 164 }
twisti@2047 165 int bci() const {
twisti@2047 166 return _bci;
twisti@2047 167 }
twisti@2047 168 SharkState* state() const {
twisti@2047 169 return _state;
twisti@2047 170 }
twisti@2047 171 BasicBlock* check_block() const {
twisti@2047 172 return _check_block;
twisti@2047 173 }
twisti@2047 174 BasicBlock* continue_block() const {
twisti@2047 175 return _continue_block;
twisti@2047 176 }
twisti@2047 177
twisti@2047 178 public:
twisti@2047 179 SharkFunction* function() const {
twisti@2047 180 return block()->function();
twisti@2047 181 }
twisti@2047 182
twisti@2047 183 public:
twisti@2047 184 void process() const {
twisti@2047 185 builder()->SetInsertPoint(check_block());
twisti@2047 186 block()->do_deferred_zero_check(value(), bci(), state(), continue_block());
twisti@2047 187 }
twisti@2047 188 };
twisti@2047 189
twisti@2047 190 void SharkFunction::add_deferred_zero_check(SharkTopLevelBlock* block,
twisti@2047 191 SharkValue* value) {
twisti@2047 192 deferred_zero_checks()->append(new DeferredZeroCheck(block, value));
twisti@2047 193 }
twisti@2047 194
twisti@2047 195 void SharkFunction::do_deferred_zero_checks() {
twisti@2047 196 for (int i = 0; i < deferred_zero_checks()->length(); i++)
twisti@2047 197 deferred_zero_checks()->at(i)->process();
twisti@2047 198 }

mercurial