1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "opto/compile.hpp"
  27 #include "opto/node.hpp"
  28 #include "opto/safepointTable.hpp"
  29 #include "runtime/sharedRuntime.hpp"
  30 
  31 Label &ThreadLocalSafepointTable::add_safepoint(InternalAddress safepoint_addr, bool is_return) {
  32   ThreadLocalSafepointEntry *entry = new (Compile::current()->comp_arena()) ThreadLocalSafepointEntry(safepoint_addr, is_return);
  33   int index = _safepoints.append(entry);
  34   return _safepoints.at(index)->_stub_label;
  35 }
  36 
  37 int ThreadLocalSafepointTable::stub_size() {
  38   return _safepoints.length() * 14 * 2;
  39 }
  40 
  41 #define __ _masm.
  42 void ThreadLocalSafepointTable::emit(CodeBuffer& cbuf, bool has_wide_vectors) {
  43   //cb->insts()->freeze();
  44 
  45   MacroAssembler _masm(&cbuf);
  46 
  47   for (int i = _safepoints.length() - 1; i >= 0; i--) {
  48     ThreadLocalSafepointEntry &entry = *_safepoints.at(i);
  49 
  50     __ bind(entry._stub_label);
  51     __ push(rax);
  52     __ lea(rax, entry._safepoint_addr);
  53     __ movptr(Address(r15_thread, JavaThread::saved_exception_pc_offset()), rax);
  54     __ pop(rax);
  55 
  56     address stub;
  57 
  58     if (entry._is_return) {
  59       assert(SharedRuntime::polling_page_return_handler_blob() != NULL,
  60              "polling page return stub not created yet");
  61       stub = SharedRuntime::polling_page_return_handler_blob()->entry_point();
  62     } else if (has_wide_vectors) {
  63       assert(SharedRuntime::polling_page_vectors_safepoint_handler_blob() != NULL,
  64              "polling page safepoint stub not created yet");
  65       stub = SharedRuntime::polling_page_vectors_safepoint_handler_blob()->entry_point();
  66     } else {
  67       assert(SharedRuntime::polling_page_safepoint_handler_blob() != NULL,
  68              "polling page safepoint stub not created yet");
  69       stub = SharedRuntime::polling_page_safepoint_handler_blob()->entry_point();
  70     }
  71 
  72     RuntimeAddress callback_addr(stub);
  73 
  74     __ jump(callback_addr);
  75   }
  76 
  77 }
  78 #undef __