1 /*
2  * Copyright (c) 2017, 2019, 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 #ifndef SHARE_JVMCI_JVMCI_HPP
25 #define SHARE_JVMCI_JVMCI_HPP
26 
27 #include "compiler/compilerDefinitions.hpp"
28 #include "utilities/exceptions.hpp"
29 
30 class BoolObjectClosure;
31 class constantPoolHandle;
32 class JavaThread;
33 class JVMCIEnv;
34 class JVMCIRuntime;
35 class Metadata;
36 class MetadataHandleBlock;
37 class OopClosure;
38 class OopStorage;
39 
40 struct _jmetadata;
41 typedef struct _jmetadata *jmetadata;
42 
43 class JVMCI : public AllStatic {
44   friend class JVMCIRuntime;
45   friend class JVMCIEnv;
46 
47  private:
48   // Handles to Metadata objects.
49   static MetadataHandleBlock* _metadata_handles;
50 
51   // Access to the HotSpotJVMCIRuntime used by the CompileBroker.
52   static JVMCIRuntime* _compiler_runtime;
53 
54   // Access to the HotSpotJVMCIRuntime used by Java code running on the
55   // HotSpot heap. It will be the same as _compiler_runtime if
56   // UseJVMCINativeLibrary is false
57   static JVMCIRuntime* _java_runtime;
58 
59  public:
60   enum CodeInstallResult {
61      ok,
62      dependencies_failed,
63      cache_full,
64      code_too_large
65   };
66 
67   static void do_unloading(bool unloading_occurred);
68 
69   static void metadata_do(void f(Metadata*));
70 
71   static void shutdown();
72 
73   static bool shutdown_called();
74 
75   static bool is_compiler_initialized();
76 
77   /**
78    * Determines if the VM is sufficiently booted to initialize JVMCI.
79    */
80   static bool can_initialize_JVMCI();
81 
82   static void initialize_globals();
83 
84   static void initialize_compiler(TRAPS);
85 
86   static jobject make_global(const Handle& obj);
87   static void destroy_global(jobject handle);
88   static bool is_global_handle(jobject handle);
89 
90   static jmetadata allocate_handle(const methodHandle& handle);
91   static jmetadata allocate_handle(const constantPoolHandle& handle);
92 
93   static void release_handle(jmetadata handle);
94 
compiler_runtime()95   static JVMCIRuntime* compiler_runtime() { return _compiler_runtime; }
java_runtime()96   static JVMCIRuntime* java_runtime()     { return _java_runtime; }
97 };
98 
99 #endif // SHARE_JVMCI_JVMCI_HPP
100