src/share/vm/shark/sharkFunction.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial