1 | /* |
2 | * Copyright (c) 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_JVMCIOBJECT_HPP |
25 | #define SHARE_JVMCI_JVMCIOBJECT_HPP |
26 | |
27 | #include "jni.h" |
28 | #include "utilities/debug.hpp" |
29 | |
30 | class JVMCIArray; |
31 | class JVMCIPrimitiveArray; |
32 | class JVMCIObjectArray; |
33 | |
34 | class JVMCIObject { |
35 | |
36 | private: |
37 | jobject _object; |
38 | bool _is_hotspot; |
39 | |
40 | public: |
41 | JVMCIObject(): _object(NULL), _is_hotspot(false) {} |
42 | JVMCIObject(jobject o, bool is_hotspot): _object(o), _is_hotspot(is_hotspot) { } |
43 | |
44 | static JVMCIObject create(jobject o, bool is_hotspot) { JVMCIObject r(o, is_hotspot); return r; } |
45 | jobject as_jobject() { return _object; } |
46 | jobject as_jweak() { return (jweak) _object; } |
47 | jstring as_jstring() { return (jstring) _object; } |
48 | bool is_hotspot() { return _is_hotspot; } |
49 | |
50 | bool is_null() const { return _object == NULL; } |
51 | bool is_non_null() const { return _object != NULL; } |
52 | |
53 | operator JVMCIArray(); |
54 | operator JVMCIPrimitiveArray(); |
55 | operator JVMCIObjectArray(); |
56 | }; |
57 | |
58 | class JVMCIArray : public JVMCIObject { |
59 | public: |
60 | JVMCIArray() {} |
61 | JVMCIArray(jobject o, bool is_hotspot): JVMCIObject(o, is_hotspot) {} |
62 | jarray as_jobject() { return (jarray) JVMCIObject::as_jobject(); } |
63 | }; |
64 | |
65 | class JVMCIObjectArray : public JVMCIArray { |
66 | public: |
67 | JVMCIObjectArray() {} |
68 | JVMCIObjectArray(void* v): JVMCIArray() { assert(v == NULL, "must be NULL" ); } |
69 | JVMCIObjectArray(jobject o, bool is_hotspot): JVMCIArray(o, is_hotspot) {} |
70 | |
71 | jobjectArray as_jobject() { return (jobjectArray) JVMCIArray::as_jobject(); } |
72 | }; |
73 | |
74 | class JVMCIPrimitiveArray : public JVMCIArray { |
75 | public: |
76 | JVMCIPrimitiveArray() {} |
77 | JVMCIPrimitiveArray(void* v): JVMCIArray() { assert(v == NULL, "must be NULL" ); } |
78 | JVMCIPrimitiveArray(jobject o, bool is_hotspot): JVMCIArray(o, is_hotspot) {} |
79 | |
80 | jbooleanArray as_jbooleanArray() { return (jbooleanArray) as_jobject(); } |
81 | jbyteArray as_jbyteArray() { return (jbyteArray) as_jobject(); } |
82 | jcharArray as_jcharArray() { return (jcharArray) as_jobject(); } |
83 | jshortArray as_jshortArray() { return (jshortArray) as_jobject(); } |
84 | jintArray as_jintArray() { return (jintArray) as_jobject(); } |
85 | jfloatArray as_jfloatArray() { return (jfloatArray) as_jobject(); } |
86 | jlongArray as_jlongArray() { return (jlongArray) as_jobject(); } |
87 | jdoubleArray as_jdoubleArray() { return (jdoubleArray) as_jobject(); } |
88 | }; |
89 | |
90 | inline JVMCIObject::operator JVMCIArray() { return JVMCIArray(_object, _is_hotspot); } |
91 | inline JVMCIObject::operator JVMCIPrimitiveArray() { return JVMCIPrimitiveArray(_object, _is_hotspot); } |
92 | inline JVMCIObject::operator JVMCIObjectArray() { return JVMCIObjectArray(_object, _is_hotspot); } |
93 | |
94 | #endif // SHARE_JVMCI_JVMCIOBJECT_HPP |
95 | |