src/share/vm/shark/sharkFunction.cpp

Wed, 11 Aug 2010 05:51:21 -0700

author
twisti
date
Wed, 11 Aug 2010 05:51:21 -0700
changeset 2047
d2ede61b7a12
child 2314
f95d63e2154a
permissions
-rw-r--r--

6976186: integrate Shark HotSpot changes
Summary: Shark is a JIT compiler for Zero that uses the LLVM compiler infrastructure.
Reviewed-by: kvn, twisti
Contributed-by: Gary Benson <gbenson@redhat.com>

twisti@2047 1 /*
twisti@2047 2 * Copyright (c) 1999, 2007, 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
twisti@2047 26 #include "incls/_precompiled.incl"
twisti@2047 27 #include "incls/_sharkFunction.cpp.incl"
twisti@2047 28
twisti@2047 29 using namespace llvm;
twisti@2047 30
twisti@2047 31 void SharkFunction::initialize(const char *name) {
twisti@2047 32 // Create the function
twisti@2047 33 _function = Function::Create(
twisti@2047 34 entry_point_type(),
twisti@2047 35 GlobalVariable::InternalLinkage,
twisti@2047 36 name);
twisti@2047 37
twisti@2047 38 // Get our arguments
twisti@2047 39 Function::arg_iterator ai = function()->arg_begin();
twisti@2047 40 Argument *method = ai++;
twisti@2047 41 method->setName("method");
twisti@2047 42 Argument *osr_buf = NULL;
twisti@2047 43 if (is_osr()) {
twisti@2047 44 osr_buf = ai++;
twisti@2047 45 osr_buf->setName("osr_buf");
twisti@2047 46 }
twisti@2047 47 Argument *base_pc = ai++;
twisti@2047 48 base_pc->setName("base_pc");
twisti@2047 49 code_buffer()->set_base_pc(base_pc);
twisti@2047 50 Argument *thread = ai++;
twisti@2047 51 thread->setName("thread");
twisti@2047 52 set_thread(thread);
twisti@2047 53
twisti@2047 54 // Create the list of blocks
twisti@2047 55 set_block_insertion_point(NULL);
twisti@2047 56 _blocks = NEW_RESOURCE_ARRAY(SharkTopLevelBlock*, block_count());
twisti@2047 57 for (int i = 0; i < block_count(); i++) {
twisti@2047 58 ciTypeFlow::Block *b = flow()->pre_order_at(i);
twisti@2047 59
twisti@2047 60 // Work around a bug in pre_order_at() that does not return
twisti@2047 61 // the correct pre-ordering. If pre_order_at() were correct
twisti@2047 62 // this line could simply be:
twisti@2047 63 // _blocks[i] = new SharkTopLevelBlock(this, b);
twisti@2047 64 _blocks[b->pre_order()] = new SharkTopLevelBlock(this, b);
twisti@2047 65 }
twisti@2047 66
twisti@2047 67 // Walk the tree from the start block to determine which
twisti@2047 68 // blocks are entered and which blocks require phis
twisti@2047 69 SharkTopLevelBlock *start_block = block(flow()->start_block_num());
twisti@2047 70 assert(start_block->start() == flow()->start_bci(), "blocks out of order");
twisti@2047 71 start_block->enter();
twisti@2047 72
twisti@2047 73 // Initialize all entered blocks
twisti@2047 74 for (int i = 0; i < block_count(); i++) {
twisti@2047 75 if (block(i)->entered())
twisti@2047 76 block(i)->initialize();
twisti@2047 77 }
twisti@2047 78
twisti@2047 79 // Create and push our stack frame
twisti@2047 80 set_block_insertion_point(&function()->front());
twisti@2047 81 builder()->SetInsertPoint(CreateBlock());
twisti@2047 82 _stack = SharkStack::CreateBuildAndPushFrame(this, method);
twisti@2047 83
twisti@2047 84 // Create the entry state
twisti@2047 85 SharkState *entry_state;
twisti@2047 86 if (is_osr()) {
twisti@2047 87 entry_state = new SharkOSREntryState(start_block, method, osr_buf);
twisti@2047 88
twisti@2047 89 // Free the OSR buffer
twisti@2047 90 builder()->CreateCall(builder()->osr_migration_end(), osr_buf);
twisti@2047 91 }
twisti@2047 92 else {
twisti@2047 93 entry_state = new SharkNormalEntryState(start_block, method);
twisti@2047 94
twisti@2047 95 // Lock if necessary
twisti@2047 96 if (is_synchronized()) {
twisti@2047 97 SharkTopLevelBlock *locker =
twisti@2047 98 new SharkTopLevelBlock(this, start_block->ciblock());
twisti@2047 99 locker->add_incoming(entry_state);
twisti@2047 100
twisti@2047 101 set_block_insertion_point(start_block->entry_block());
twisti@2047 102 locker->acquire_method_lock();
twisti@2047 103
twisti@2047 104 entry_state = locker->current_state();
twisti@2047 105 }
twisti@2047 106 }
twisti@2047 107
twisti@2047 108 // Transition into the method proper
twisti@2047 109 start_block->add_incoming(entry_state);
twisti@2047 110 builder()->CreateBr(start_block->entry_block());
twisti@2047 111
twisti@2047 112 // Parse the blocks
twisti@2047 113 for (int i = 0; i < block_count(); i++) {
twisti@2047 114 if (!block(i)->entered())
twisti@2047 115 continue;
twisti@2047 116
twisti@2047 117 if (i + 1 < block_count())
twisti@2047 118 set_block_insertion_point(block(i + 1)->entry_block());
twisti@2047 119 else
twisti@2047 120 set_block_insertion_point(NULL);
twisti@2047 121
twisti@2047 122 block(i)->emit_IR();
twisti@2047 123 }
twisti@2047 124 do_deferred_zero_checks();
twisti@2047 125 }
twisti@2047 126
twisti@2047 127 class DeferredZeroCheck : public SharkTargetInvariants {
twisti@2047 128 public:
twisti@2047 129 DeferredZeroCheck(SharkTopLevelBlock* block, SharkValue* value)
twisti@2047 130 : SharkTargetInvariants(block),
twisti@2047 131 _block(block),
twisti@2047 132 _value(value),
twisti@2047 133 _bci(block->bci()),
twisti@2047 134 _state(block->current_state()->copy()),
twisti@2047 135 _check_block(builder()->GetInsertBlock()),
twisti@2047 136 _continue_block(function()->CreateBlock("not_zero")) {
twisti@2047 137 builder()->SetInsertPoint(continue_block());
twisti@2047 138 }
twisti@2047 139
twisti@2047 140 private:
twisti@2047 141 SharkTopLevelBlock* _block;
twisti@2047 142 SharkValue* _value;
twisti@2047 143 int _bci;
twisti@2047 144 SharkState* _state;
twisti@2047 145 BasicBlock* _check_block;
twisti@2047 146 BasicBlock* _continue_block;
twisti@2047 147
twisti@2047 148 public:
twisti@2047 149 SharkTopLevelBlock* block() const {
twisti@2047 150 return _block;
twisti@2047 151 }
twisti@2047 152 SharkValue* value() const {
twisti@2047 153 return _value;
twisti@2047 154 }
twisti@2047 155 int bci() const {
twisti@2047 156 return _bci;
twisti@2047 157 }
twisti@2047 158 SharkState* state() const {
twisti@2047 159 return _state;
twisti@2047 160 }
twisti@2047 161 BasicBlock* check_block() const {
twisti@2047 162 return _check_block;
twisti@2047 163 }
twisti@2047 164 BasicBlock* continue_block() const {
twisti@2047 165 return _continue_block;
twisti@2047 166 }
twisti@2047 167
twisti@2047 168 public:
twisti@2047 169 SharkFunction* function() const {
twisti@2047 170 return block()->function();
twisti@2047 171 }
twisti@2047 172
twisti@2047 173 public:
twisti@2047 174 void process() const {
twisti@2047 175 builder()->SetInsertPoint(check_block());
twisti@2047 176 block()->do_deferred_zero_check(value(), bci(), state(), continue_block());
twisti@2047 177 }
twisti@2047 178 };
twisti@2047 179
twisti@2047 180 void SharkFunction::add_deferred_zero_check(SharkTopLevelBlock* block,
twisti@2047 181 SharkValue* value) {
twisti@2047 182 deferred_zero_checks()->append(new DeferredZeroCheck(block, value));
twisti@2047 183 }
twisti@2047 184
twisti@2047 185 void SharkFunction::do_deferred_zero_checks() {
twisti@2047 186 for (int i = 0; i < deferred_zero_checks()->length(); i++)
twisti@2047 187 deferred_zero_checks()->at(i)->process();
twisti@2047 188 }

mercurial