runtime.hpp revision 6760:22b98ab2a69f
1/*
2 * Copyright (c) 1998, 2014, 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#ifndef SHARE_VM_OPTO_RUNTIME_HPP
26#define SHARE_VM_OPTO_RUNTIME_HPP
27
28#include "code/codeBlob.hpp"
29#include "opto/machnode.hpp"
30#include "opto/optoreg.hpp"
31#include "opto/type.hpp"
32#include "runtime/biasedLocking.hpp"
33#include "runtime/rtmLocking.hpp"
34#include "runtime/deoptimization.hpp"
35#include "runtime/vframe.hpp"
36
37//------------------------------OptoRuntime------------------------------------
38// Opto compiler runtime routines
39//
40// These are all generated from Ideal graphs.  They are called with the
41// Java calling convention.  Internally they call C++.  They are made once at
42// startup time and Opto compiles calls to them later.
43// Things are broken up into quads: the signature they will be called with,
44// the address of the generated code, the corresponding C++ code and an
45// nmethod.
46
47// The signature (returned by "xxx_Type()") is used at startup time by the
48// Generator to make the generated code "xxx_Java".  Opto compiles calls
49// to the generated code "xxx_Java".  When the compiled code gets executed,
50// it calls the C++ code "xxx_C".  The generated nmethod is saved in the
51// CodeCache.  Exception handlers use the nmethod to get the callee-save
52// register OopMaps.
53class CallInfo;
54
55//
56// NamedCounters are tagged counters which can be used for profiling
57// code in various ways.  Currently they are used by the lock coarsening code
58//
59
60class NamedCounter : public CHeapObj<mtCompiler> {
61public:
62    enum CounterTag {
63    NoTag,
64    LockCounter,
65    EliminatedLockCounter,
66    BiasedLockingCounter,
67    RTMLockingCounter
68  };
69
70private:
71  const char *  _name;
72  int           _count;
73  CounterTag    _tag;
74  NamedCounter* _next;
75
76 public:
77  NamedCounter(const char *n, CounterTag tag = NoTag):
78    _name(n),
79    _count(0),
80    _next(NULL),
81    _tag(tag) {}
82
83  const char * name() const     { return _name; }
84  int count() const             { return _count; }
85  address addr()                { return (address)&_count; }
86  CounterTag tag() const        { return _tag; }
87  void set_tag(CounterTag tag)  { _tag = tag; }
88
89  NamedCounter* next() const    { return _next; }
90  void set_next(NamedCounter* next) {
91    assert(_next == NULL || next == NULL, "already set");
92    _next = next;
93  }
94
95};
96
97class BiasedLockingNamedCounter : public NamedCounter {
98 private:
99  BiasedLockingCounters _counters;
100
101 public:
102  BiasedLockingNamedCounter(const char *n) :
103    NamedCounter(n, BiasedLockingCounter), _counters() {}
104
105  BiasedLockingCounters* counters() { return &_counters; }
106};
107
108
109class RTMLockingNamedCounter : public NamedCounter {
110 private:
111 RTMLockingCounters _counters;
112
113 public:
114  RTMLockingNamedCounter(const char *n) :
115    NamedCounter(n, RTMLockingCounter), _counters() {}
116
117  RTMLockingCounters* counters() { return &_counters; }
118};
119
120typedef const TypeFunc*(*TypeFunc_generator)();
121
122class OptoRuntime : public AllStatic {
123  friend class Matcher;  // allow access to stub names
124
125 private:
126  // define stubs
127  static address generate_stub(ciEnv* ci_env, TypeFunc_generator gen, address C_function, const char *name, int is_fancy_jump, bool pass_tls, bool save_arguments, bool return_pc);
128
129  // References to generated stubs
130  static address _new_instance_Java;
131  static address _new_array_Java;
132  static address _new_array_nozero_Java;
133  static address _multianewarray2_Java;
134  static address _multianewarray3_Java;
135  static address _multianewarray4_Java;
136  static address _multianewarray5_Java;
137  static address _multianewarrayN_Java;
138  static address _g1_wb_pre_Java;
139  static address _g1_wb_post_Java;
140  static address _vtable_must_compile_Java;
141  static address _complete_monitor_locking_Java;
142  static address _rethrow_Java;
143
144  static address _slow_arraycopy_Java;
145  static address _register_finalizer_Java;
146
147# ifdef ENABLE_ZAP_DEAD_LOCALS
148  static address _zap_dead_Java_locals_Java;
149  static address _zap_dead_native_locals_Java;
150# endif
151
152
153  //
154  // Implementation of runtime methods
155  // =================================
156
157  // Allocate storage for a Java instance.
158  static void new_instance_C(Klass* instance_klass, JavaThread *thread);
159
160  // Allocate storage for a objArray or typeArray
161  static void new_array_C(Klass* array_klass, int len, JavaThread *thread);
162  static void new_array_nozero_C(Klass* array_klass, int len, JavaThread *thread);
163
164  // Post-slow-path-allocation, pre-initializing-stores step for
165  // implementing ReduceInitialCardMarks
166  static void new_store_pre_barrier(JavaThread* thread);
167
168  // Allocate storage for a multi-dimensional arrays
169  // Note: needs to be fixed for arbitrary number of dimensions
170  static void multianewarray2_C(Klass* klass, int len1, int len2, JavaThread *thread);
171  static void multianewarray3_C(Klass* klass, int len1, int len2, int len3, JavaThread *thread);
172  static void multianewarray4_C(Klass* klass, int len1, int len2, int len3, int len4, JavaThread *thread);
173  static void multianewarray5_C(Klass* klass, int len1, int len2, int len3, int len4, int len5, JavaThread *thread);
174  static void multianewarrayN_C(Klass* klass, arrayOopDesc* dims, JavaThread *thread);
175  static void g1_wb_pre_C(oopDesc* orig, JavaThread* thread);
176  static void g1_wb_post_C(void* card_addr, JavaThread* thread);
177
178public:
179  // Slow-path Locking and Unlocking
180  static void complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* thread);
181  static void complete_monitor_unlocking_C(oopDesc* obj, BasicLock* lock);
182
183private:
184
185  // Implicit exception support
186  static void throw_null_exception_C(JavaThread* thread);
187
188  // Exception handling
189  static address handle_exception_C       (JavaThread* thread);
190  static address handle_exception_C_helper(JavaThread* thread, nmethod*& nm);
191  static address rethrow_C                (oopDesc* exception, JavaThread *thread, address return_pc );
192  static void deoptimize_caller_frame     (JavaThread *thread);
193  static void deoptimize_caller_frame     (JavaThread *thread, bool doit);
194  static bool is_deoptimized_caller_frame (JavaThread *thread);
195
196  // CodeBlob support
197  // ===================================================================
198
199  static ExceptionBlob*       _exception_blob;
200  static void generate_exception_blob();
201
202  static void register_finalizer(oopDesc* obj, JavaThread* thread);
203
204  // zaping dead locals, either from Java frames or from native frames
205# ifdef ENABLE_ZAP_DEAD_LOCALS
206  static void zap_dead_Java_locals_C(   JavaThread* thread);
207  static void zap_dead_native_locals_C( JavaThread* thread);
208
209  static void zap_dead_java_or_native_locals( JavaThread*, bool (*)(frame*));
210
211 public:
212   static int ZapDeadCompiledLocals_count;
213
214# endif
215
216
217 public:
218
219  static bool is_callee_saved_register(MachRegisterNumbers reg);
220
221  // One time only generate runtime code stubs. Returns true
222  // when runtime stubs have been generated successfully and
223  // false otherwise.
224  static bool generate(ciEnv* env);
225
226  // Returns the name of a stub
227  static const char* stub_name(address entry);
228
229  // access to runtime stubs entry points for java code
230  static address new_instance_Java()                     { return _new_instance_Java; }
231  static address new_array_Java()                        { return _new_array_Java; }
232  static address new_array_nozero_Java()                 { return _new_array_nozero_Java; }
233  static address multianewarray2_Java()                  { return _multianewarray2_Java; }
234  static address multianewarray3_Java()                  { return _multianewarray3_Java; }
235  static address multianewarray4_Java()                  { return _multianewarray4_Java; }
236  static address multianewarray5_Java()                  { return _multianewarray5_Java; }
237  static address multianewarrayN_Java()                  { return _multianewarrayN_Java; }
238  static address g1_wb_pre_Java()                        { return _g1_wb_pre_Java; }
239  static address g1_wb_post_Java()                       { return _g1_wb_post_Java; }
240  static address vtable_must_compile_stub()              { return _vtable_must_compile_Java; }
241  static address complete_monitor_locking_Java()         { return _complete_monitor_locking_Java;   }
242
243  static address slow_arraycopy_Java()                   { return _slow_arraycopy_Java; }
244  static address register_finalizer_Java()               { return _register_finalizer_Java; }
245
246
247# ifdef ENABLE_ZAP_DEAD_LOCALS
248  static address zap_dead_locals_stub(bool is_native)    { return is_native
249                                                                  ? _zap_dead_native_locals_Java
250                                                                  : _zap_dead_Java_locals_Java; }
251  static MachNode* node_to_call_zap_dead_locals(Node* n, int block_num, bool is_native);
252# endif
253
254  static ExceptionBlob*    exception_blob()                      { return _exception_blob; }
255
256  // Leaf routines helping with method data update
257  static void profile_receiver_type_C(DataLayout* data, oopDesc* receiver);
258
259  // Implicit exception support
260  static void throw_div0_exception_C      (JavaThread* thread);
261  static void throw_stack_overflow_error_C(JavaThread* thread);
262
263  // Exception handling
264  static address rethrow_stub()             { return _rethrow_Java; }
265
266
267  // Type functions
268  // ======================================================
269
270  static const TypeFunc* new_instance_Type(); // object allocation (slow case)
271  static const TypeFunc* new_array_Type ();   // [a]newarray (slow case)
272  static const TypeFunc* multianewarray_Type(int ndim); // multianewarray
273  static const TypeFunc* multianewarray2_Type(); // multianewarray
274  static const TypeFunc* multianewarray3_Type(); // multianewarray
275  static const TypeFunc* multianewarray4_Type(); // multianewarray
276  static const TypeFunc* multianewarray5_Type(); // multianewarray
277  static const TypeFunc* multianewarrayN_Type(); // multianewarray
278  static const TypeFunc* g1_wb_pre_Type();
279  static const TypeFunc* g1_wb_post_Type();
280  static const TypeFunc* complete_monitor_enter_Type();
281  static const TypeFunc* complete_monitor_exit_Type();
282  static const TypeFunc* uncommon_trap_Type();
283  static const TypeFunc* athrow_Type();
284  static const TypeFunc* rethrow_Type();
285  static const TypeFunc* Math_D_D_Type();  // sin,cos & friends
286  static const TypeFunc* Math_DD_D_Type(); // mod,pow & friends
287  static const TypeFunc* modf_Type();
288  static const TypeFunc* l2f_Type();
289  static const TypeFunc* void_long_Type();
290
291  static const TypeFunc* flush_windows_Type();
292
293  // arraycopy routine types
294  static const TypeFunc* fast_arraycopy_Type(); // bit-blasters
295  static const TypeFunc* checkcast_arraycopy_Type();
296  static const TypeFunc* generic_arraycopy_Type();
297  static const TypeFunc* slow_arraycopy_Type();   // the full routine
298
299  static const TypeFunc* array_fill_Type();
300
301  static const TypeFunc* aescrypt_block_Type();
302  static const TypeFunc* cipherBlockChaining_aescrypt_Type();
303
304  static const TypeFunc* sha_implCompress_Type();
305  static const TypeFunc* digestBase_implCompressMB_Type();
306
307  static const TypeFunc* updateBytesCRC32_Type();
308
309  // leaf on stack replacement interpreter accessor types
310  static const TypeFunc* osr_end_Type();
311
312  // leaf methodData routine types
313  static const TypeFunc* profile_receiver_type_Type();
314
315  // leaf on stack replacement interpreter accessor types
316  static const TypeFunc* fetch_int_Type();
317  static const TypeFunc* fetch_long_Type();
318  static const TypeFunc* fetch_float_Type();
319  static const TypeFunc* fetch_double_Type();
320  static const TypeFunc* fetch_oop_Type();
321  static const TypeFunc* fetch_monitor_Type();
322
323  static const TypeFunc* register_finalizer_Type();
324
325  // Dtrace support
326  static const TypeFunc* dtrace_method_entry_exit_Type();
327  static const TypeFunc* dtrace_object_alloc_Type();
328
329# ifdef ENABLE_ZAP_DEAD_LOCALS
330  static const TypeFunc* zap_dead_locals_Type();
331# endif
332
333 private:
334 static NamedCounter * volatile _named_counters;
335
336 public:
337 // helper function which creates a named counter labeled with the
338 // if they are available
339 static NamedCounter* new_named_counter(JVMState* jvms, NamedCounter::CounterTag tag);
340
341 // dumps all the named counters
342 static void          print_named_counters();
343
344};
345
346#endif // SHARE_VM_OPTO_RUNTIME_HPP
347