1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/shark/sharkFunction.cpp Wed Aug 11 05:51:21 2010 -0700 1.3 @@ -0,0 +1,188 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright 2008, 2009 Red Hat, Inc. 1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 + * 1.9 + * This code is free software; you can redistribute it and/or modify it 1.10 + * under the terms of the GNU General Public License version 2 only, as 1.11 + * published by the Free Software Foundation. 1.12 + * 1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.16 + * version 2 for more details (a copy is included in the LICENSE file that 1.17 + * accompanied this code). 1.18 + * 1.19 + * You should have received a copy of the GNU General Public License version 1.20 + * 2 along with this work; if not, write to the Free Software Foundation, 1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.22 + * 1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.24 + * or visit www.oracle.com if you need additional information or have any 1.25 + * questions. 1.26 + * 1.27 + */ 1.28 + 1.29 +#include "incls/_precompiled.incl" 1.30 +#include "incls/_sharkFunction.cpp.incl" 1.31 + 1.32 +using namespace llvm; 1.33 + 1.34 +void SharkFunction::initialize(const char *name) { 1.35 + // Create the function 1.36 + _function = Function::Create( 1.37 + entry_point_type(), 1.38 + GlobalVariable::InternalLinkage, 1.39 + name); 1.40 + 1.41 + // Get our arguments 1.42 + Function::arg_iterator ai = function()->arg_begin(); 1.43 + Argument *method = ai++; 1.44 + method->setName("method"); 1.45 + Argument *osr_buf = NULL; 1.46 + if (is_osr()) { 1.47 + osr_buf = ai++; 1.48 + osr_buf->setName("osr_buf"); 1.49 + } 1.50 + Argument *base_pc = ai++; 1.51 + base_pc->setName("base_pc"); 1.52 + code_buffer()->set_base_pc(base_pc); 1.53 + Argument *thread = ai++; 1.54 + thread->setName("thread"); 1.55 + set_thread(thread); 1.56 + 1.57 + // Create the list of blocks 1.58 + set_block_insertion_point(NULL); 1.59 + _blocks = NEW_RESOURCE_ARRAY(SharkTopLevelBlock*, block_count()); 1.60 + for (int i = 0; i < block_count(); i++) { 1.61 + ciTypeFlow::Block *b = flow()->pre_order_at(i); 1.62 + 1.63 + // Work around a bug in pre_order_at() that does not return 1.64 + // the correct pre-ordering. If pre_order_at() were correct 1.65 + // this line could simply be: 1.66 + // _blocks[i] = new SharkTopLevelBlock(this, b); 1.67 + _blocks[b->pre_order()] = new SharkTopLevelBlock(this, b); 1.68 + } 1.69 + 1.70 + // Walk the tree from the start block to determine which 1.71 + // blocks are entered and which blocks require phis 1.72 + SharkTopLevelBlock *start_block = block(flow()->start_block_num()); 1.73 + assert(start_block->start() == flow()->start_bci(), "blocks out of order"); 1.74 + start_block->enter(); 1.75 + 1.76 + // Initialize all entered blocks 1.77 + for (int i = 0; i < block_count(); i++) { 1.78 + if (block(i)->entered()) 1.79 + block(i)->initialize(); 1.80 + } 1.81 + 1.82 + // Create and push our stack frame 1.83 + set_block_insertion_point(&function()->front()); 1.84 + builder()->SetInsertPoint(CreateBlock()); 1.85 + _stack = SharkStack::CreateBuildAndPushFrame(this, method); 1.86 + 1.87 + // Create the entry state 1.88 + SharkState *entry_state; 1.89 + if (is_osr()) { 1.90 + entry_state = new SharkOSREntryState(start_block, method, osr_buf); 1.91 + 1.92 + // Free the OSR buffer 1.93 + builder()->CreateCall(builder()->osr_migration_end(), osr_buf); 1.94 + } 1.95 + else { 1.96 + entry_state = new SharkNormalEntryState(start_block, method); 1.97 + 1.98 + // Lock if necessary 1.99 + if (is_synchronized()) { 1.100 + SharkTopLevelBlock *locker = 1.101 + new SharkTopLevelBlock(this, start_block->ciblock()); 1.102 + locker->add_incoming(entry_state); 1.103 + 1.104 + set_block_insertion_point(start_block->entry_block()); 1.105 + locker->acquire_method_lock(); 1.106 + 1.107 + entry_state = locker->current_state(); 1.108 + } 1.109 + } 1.110 + 1.111 + // Transition into the method proper 1.112 + start_block->add_incoming(entry_state); 1.113 + builder()->CreateBr(start_block->entry_block()); 1.114 + 1.115 + // Parse the blocks 1.116 + for (int i = 0; i < block_count(); i++) { 1.117 + if (!block(i)->entered()) 1.118 + continue; 1.119 + 1.120 + if (i + 1 < block_count()) 1.121 + set_block_insertion_point(block(i + 1)->entry_block()); 1.122 + else 1.123 + set_block_insertion_point(NULL); 1.124 + 1.125 + block(i)->emit_IR(); 1.126 + } 1.127 + do_deferred_zero_checks(); 1.128 +} 1.129 + 1.130 +class DeferredZeroCheck : public SharkTargetInvariants { 1.131 + public: 1.132 + DeferredZeroCheck(SharkTopLevelBlock* block, SharkValue* value) 1.133 + : SharkTargetInvariants(block), 1.134 + _block(block), 1.135 + _value(value), 1.136 + _bci(block->bci()), 1.137 + _state(block->current_state()->copy()), 1.138 + _check_block(builder()->GetInsertBlock()), 1.139 + _continue_block(function()->CreateBlock("not_zero")) { 1.140 + builder()->SetInsertPoint(continue_block()); 1.141 + } 1.142 + 1.143 + private: 1.144 + SharkTopLevelBlock* _block; 1.145 + SharkValue* _value; 1.146 + int _bci; 1.147 + SharkState* _state; 1.148 + BasicBlock* _check_block; 1.149 + BasicBlock* _continue_block; 1.150 + 1.151 + public: 1.152 + SharkTopLevelBlock* block() const { 1.153 + return _block; 1.154 + } 1.155 + SharkValue* value() const { 1.156 + return _value; 1.157 + } 1.158 + int bci() const { 1.159 + return _bci; 1.160 + } 1.161 + SharkState* state() const { 1.162 + return _state; 1.163 + } 1.164 + BasicBlock* check_block() const { 1.165 + return _check_block; 1.166 + } 1.167 + BasicBlock* continue_block() const { 1.168 + return _continue_block; 1.169 + } 1.170 + 1.171 + public: 1.172 + SharkFunction* function() const { 1.173 + return block()->function(); 1.174 + } 1.175 + 1.176 + public: 1.177 + void process() const { 1.178 + builder()->SetInsertPoint(check_block()); 1.179 + block()->do_deferred_zero_check(value(), bci(), state(), continue_block()); 1.180 + } 1.181 +}; 1.182 + 1.183 +void SharkFunction::add_deferred_zero_check(SharkTopLevelBlock* block, 1.184 + SharkValue* value) { 1.185 + deferred_zero_checks()->append(new DeferredZeroCheck(block, value)); 1.186 +} 1.187 + 1.188 +void SharkFunction::do_deferred_zero_checks() { 1.189 + for (int i = 0; i < deferred_zero_checks()->length(); i++) 1.190 + deferred_zero_checks()->at(i)->process(); 1.191 +}