Coverage Report

Created: 2026-08-16 20:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/util/jni-util.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include <butil/macros.h>
21
#include <jni.h>
22
#include <limits.h>
23
#include <stddef.h>
24
#include <stdint.h>
25
26
#include <string>
27
28
#include "common/status.h"
29
#include "jni_md.h"
30
#include "util/defer_op.h"
31
#include "util/thrift_util.h"
32
33
#ifdef USE_HADOOP_HDFS
34
// defined in hadoop/hadoop-hdfs-project/hadoop-hdfs/src/main/native/libhdfs/jni_helper.c
35
extern "C" JNIEnv* getJNIEnv(void);
36
#endif
37
38
namespace doris {
39
40
#define RETURN_ERROR_IF_EXC(env)                      \
41
302k
    do {                                              \
42
302k
        if (env->ExceptionCheck()) [[unlikely]]       \
43
4
            return Jni::Env::GetJniExceptionMsg(env); \
44
302k
    } while (false)
45
46
//In order to reduce the potential risks caused by not handling exceptions,
47
// you need to refer to  https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html
48
// to confirm whether the jni method will throw an exception.
49
50
namespace Jni {
51
class Env {
52
public:
53
244k
    static Status Get(JNIEnv** env) {
54
244k
        if (tls_env_) {
55
244k
            *env = tls_env_;
56
244k
        } else {
57
212
            Status status = GetJNIEnvSlowPath(env);
58
212
            if (!status.ok()) {
59
0
                return status;
60
0
            }
61
212
        }
62
244k
        if (*env == nullptr) [[unlikely]] {
63
0
            return Status::JniError("Failed to get JNIEnv: it is nullptr.");
64
0
        }
65
244k
        return Status::OK();
66
244k
    }
67
68
7
    static Status Init() { return init_throw_exception(); }
69
70
    static Status GetJniExceptionMsg(JNIEnv* env, bool log_stack = true,
71
                                     const std::string& prefix = "") WARN_UNUSED_RESULT;
72
73
private:
74
    static Status GetJNIEnvSlowPath(JNIEnv** env);
75
7
    static Status init_throw_exception() {
76
7
        JNIEnv* env = nullptr;
77
7
        RETURN_IF_ERROR(Jni::Env::Get(&env));
78
79
        // Find JniUtil class and create a global ref.
80
7
        jclass local_jni_util_cl = env->FindClass("org/apache/doris/common/jni/utils/JniUtil");
81
7
        if (local_jni_util_cl == nullptr) {
82
0
            if (env->ExceptionOccurred()) {
83
0
                env->ExceptionDescribe();
84
0
            }
85
0
            return Status::JniError("Failed to find JniUtil class.");
86
0
        }
87
7
        jni_util_cl_ = reinterpret_cast<jclass>(env->NewGlobalRef(local_jni_util_cl));
88
7
        env->DeleteLocalRef(local_jni_util_cl);
89
7
        if (jni_util_cl_ == nullptr) {
90
0
            if (env->ExceptionOccurred()) {
91
0
                env->ExceptionDescribe();
92
0
            }
93
0
            return Status::JniError("Failed to create global reference to JniUtil class.");
94
0
        }
95
7
        if (env->ExceptionOccurred()) {
96
0
            return Status::JniError("Failed to delete local reference to JniUtil class.");
97
0
        }
98
99
        // Throwable toString()
100
7
        throwable_to_string_id_ = env->GetStaticMethodID(
101
7
                jni_util_cl_, "throwableToString", "(Ljava/lang/Throwable;)Ljava/lang/String;");
102
7
        if (throwable_to_string_id_ == nullptr) {
103
0
            if (env->ExceptionOccurred()) {
104
0
                env->ExceptionDescribe();
105
0
            }
106
0
            return Status::JniError("Failed to find JniUtil.throwableToString method.");
107
0
        }
108
109
        // throwableToStackTrace()
110
7
        throwable_to_stack_trace_id_ = env->GetStaticMethodID(
111
7
                jni_util_cl_, "throwableToStackTrace", "(Ljava/lang/Throwable;)Ljava/lang/String;");
112
7
        if (throwable_to_stack_trace_id_ == nullptr) {
113
0
            if (env->ExceptionOccurred()) {
114
0
                env->ExceptionDescribe();
115
0
            }
116
0
            return Status::JniError("Failed to find JniUtil.throwableToFullStackTrace method.");
117
0
        }
118
7
        return Status::OK();
119
7
    }
120
121
private:
122
    // Thread-local cache of the JNIEnv for this thread.
123
    static __thread JNIEnv* tls_env_;
124
125
    //for exception
126
    static jclass jni_util_cl_;
127
    static jmethodID throwable_to_string_id_;
128
    static jmethodID throwable_to_stack_trace_id_;
129
};
130
131
enum RefType { Local, Global };
132
133
enum BufferType { Chars, ByteArray };
134
135
template <RefType Ref>
136
struct RefHelper {};
137
138
template <>
139
struct RefHelper<Local> {
140
6.83k
    static jobject create(JNIEnv* env, jobject obj) { return env->NewLocalRef(obj); }
141
142
212k
    static void destroy(JNIEnv* env, jobject obj) { env->DeleteLocalRef(obj); }
143
144
219k
    static Status get_env(JNIEnv** env) {
145
        // Get the JNIEnv* corresponding to current thread.
146
219k
        return Jni::Env::Get(env);
147
219k
    }
148
};
149
150
template <>
151
struct RefHelper<Global> {
152
10.4k
    static jobject create(JNIEnv* env, jobject obj) { return env->NewGlobalRef(obj); }
153
154
10.3k
    static void destroy(JNIEnv* env, jobject obj) { env->DeleteGlobalRef(obj); }
155
156
10.3k
    static Status get_env(JNIEnv** env) { return Jni::Env::Get(env); }
157
};
158
159
template <RefType Ref>
160
class Object;
161
162
template <RefType Ref>
163
class Class;
164
165
class MethodId {
166
public:
167
17.7k
    MethodId() = default;
168
168k
    bool uninitialized() const { return _id == nullptr; }
169
170
    template <RefType U>
171
    friend class Object;
172
173
    template <RefType U>
174
    friend class Class;
175
176
private:
177
    jmethodID _id = nullptr;
178
};
179
180
class FieldId {
181
public:
182
42
    FieldId() = default;
183
84
    bool uninitialized() const { return _id == nullptr; }
184
185
    template <RefType U>
186
    friend class Object;
187
188
    template <RefType U>
189
    friend class Class;
190
191
private:
192
    jfieldID _id = nullptr;
193
};
194
195
enum CallTag {
196
    ObjectMethod,
197
    IntMethod,
198
    LongMethod,
199
    VoidMethod,
200
    BooleanMethod,
201
202
    StaticObjectMethod,
203
    StaticIntMethod,
204
    StaticLongMethod,
205
    StaticVoidMethod,
206
207
    NewObject,
208
209
    NonvirtualVoidMethod,
210
    NonvirtualObjectMethod,
211
    NonvirtualIntMethod,
212
    NonvirtualBooleanMethod,
213
};
214
215
template <CallTag Tag>
216
struct CallHelper {};
217
218
template <>
219
struct CallHelper<ObjectMethod> {
220
104k
    static jobject call_impl(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) {
221
104k
        return env->CallObjectMethodA(obj, methodID, args);
222
104k
    }
223
    using BASE_TYPE = jobject;
224
    using RETURN_TYPE = jobject;
225
};
226
227
template <>
228
struct CallHelper<IntMethod> {
229
2.04k
    static jint call_impl(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) {
230
2.04k
        return env->CallIntMethodA(obj, methodID, args);
231
2.04k
    }
232
    using BASE_TYPE = jobject;
233
    using RETURN_TYPE = jint;
234
};
235
236
template <>
237
struct CallHelper<LongMethod> {
238
25.2k
    static jlong call_impl(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) {
239
25.2k
        return env->CallLongMethodA(obj, methodID, args);
240
25.2k
    }
241
    using BASE_TYPE = jobject;
242
    using RETURN_TYPE = jlong;
243
};
244
245
template <>
246
struct CallHelper<VoidMethod> {
247
237
    static void call_impl(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) {
248
237
        env->CallVoidMethodA(obj, methodID, args);
249
237
    }
250
    using BASE_TYPE = jobject;
251
    using RETURN_TYPE = void;
252
};
253
254
template <>
255
struct CallHelper<BooleanMethod> {
256
6
    static jboolean call_impl(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) {
257
6
        return env->CallBooleanMethodA(obj, methodID, args);
258
6
    }
259
    using BASE_TYPE = jobject;
260
    using RETURN_TYPE = jboolean;
261
};
262
263
template <>
264
struct CallHelper<StaticObjectMethod> {
265
2.73k
    static jobject call_impl(JNIEnv* env, jclass cls, jmethodID methodID, const jvalue* args) {
266
2.73k
        return env->CallStaticObjectMethodA(cls, methodID, args);
267
2.73k
    }
268
    using BASE_TYPE = jclass;
269
    using RETURN_TYPE = jobject;
270
};
271
272
template <>
273
struct CallHelper<StaticIntMethod> {
274
0
    static jint call_impl(JNIEnv* env, jclass cls, jmethodID methodID, const jvalue* args) {
275
0
        return env->CallStaticIntMethodA(cls, methodID, args);
276
0
    }
277
    using BASE_TYPE = jclass;
278
    using RETURN_TYPE = jint;
279
};
280
281
template <>
282
struct CallHelper<StaticLongMethod> {
283
0
    static jlong call_impl(JNIEnv* env, jclass cls, jmethodID methodID, const jvalue* args) {
284
0
        return env->CallStaticLongMethodA(cls, methodID, args);
285
0
    }
286
    using BASE_TYPE = jclass;
287
    using RETURN_TYPE = jlong;
288
};
289
290
template <>
291
struct CallHelper<StaticVoidMethod> {
292
0
    static void call_impl(JNIEnv* env, jclass cls, jmethodID methodID, const jvalue* args) {
293
0
        return env->CallStaticVoidMethodA(cls, methodID, args);
294
0
    }
295
296
    using BASE_TYPE = jclass;
297
    using RETURN_TYPE = void;
298
};
299
300
template <>
301
struct CallHelper<NewObject> {
302
10.5k
    static jobject call_impl(JNIEnv* env, jclass cls, jmethodID methodID, const jvalue* args) {
303
10.5k
        return env->NewObjectA(cls, methodID, args);
304
10.5k
    }
305
306
    using BASE_TYPE = jclass;
307
    using RETURN_TYPE = jobject;
308
};
309
310
template <>
311
struct CallHelper<NonvirtualVoidMethod> {
312
    static void call_impl(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID,
313
5.97k
                          const jvalue* args) {
314
5.97k
        return env->CallNonvirtualVoidMethodA(obj, clazz, methodID, args);
315
5.97k
    }
316
317
    using BASE_TYPE = jobject;
318
    using RETURN_TYPE = void;
319
};
320
321
template <>
322
struct CallHelper<NonvirtualObjectMethod> {
323
    static jobject call_impl(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID,
324
38
                             const jvalue* args) {
325
38
        return env->CallNonvirtualObjectMethodA(obj, clazz, methodID, args);
326
38
    }
327
328
    using BASE_TYPE = jobject;
329
    using RETURN_TYPE = jobject;
330
};
331
332
template <>
333
struct CallHelper<NonvirtualIntMethod> {
334
    static jint call_impl(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID,
335
0
                          const jvalue* args) {
336
0
        return env->CallNonvirtualIntMethodA(obj, clazz, methodID, args);
337
0
    }
338
339
    using BASE_TYPE = jobject;
340
    using RETURN_TYPE = jint;
341
};
342
343
template <>
344
struct CallHelper<NonvirtualBooleanMethod> {
345
    static jboolean call_impl(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID,
346
0
                              const jvalue* args) {
347
0
        return env->CallNonvirtualBooleanMethodA(obj, clazz, methodID, args);
348
0
    }
349
350
    using BASE_TYPE = jobject;
351
    using RETURN_TYPE = jboolean;
352
};
353
354
template <CallTag tag>
355
class FunctionCall {
356
public:
357
    FunctionCall(FunctionCall&& other) noexcept = default;
358
359
    static FunctionCall instance(JNIEnv* env, typename CallHelper<tag>::BASE_TYPE base,
360
145k
                                 jmethodID method_id) {
361
145k
        return FunctionCall(env, base, method_id);
362
145k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE5EE8instanceEP7JNIEnv_P7_jclassP10_jmethodID
Line
Count
Source
360
2.73k
                                 jmethodID method_id) {
361
2.73k
        return FunctionCall(env, base, method_id);
362
2.73k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE0EE8instanceEP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
360
104k
                                 jmethodID method_id) {
361
104k
        return FunctionCall(env, base, method_id);
362
104k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE2EE8instanceEP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
360
25.2k
                                 jmethodID method_id) {
361
25.2k
        return FunctionCall(env, base, method_id);
362
25.2k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE1EE8instanceEP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
360
2.04k
                                 jmethodID method_id) {
361
2.04k
        return FunctionCall(env, base, method_id);
362
2.04k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE9EE8instanceEP7JNIEnv_P7_jclassP10_jmethodID
Line
Count
Source
360
10.5k
                                 jmethodID method_id) {
361
10.5k
        return FunctionCall(env, base, method_id);
362
10.5k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE3EE8instanceEP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
360
239
                                 jmethodID method_id) {
361
239
        return FunctionCall(env, base, method_id);
362
239
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE4EE8instanceEP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
360
6
                                 jmethodID method_id) {
361
6
        return FunctionCall(env, base, method_id);
362
6
    }
Unexecuted instantiation: _ZN5doris3Jni12FunctionCallILNS0_7CallTagE8EE8instanceEP7JNIEnv_P7_jclassP10_jmethodID
363
364
    /// Pass a primitive arg (eg an integer).
365
    /// Multiple arguments may be passed by repeated calls.
366
    template <class T>
367
        requires std::disjunction_v<std::is_same<T, jboolean>, std::is_same<T, jbyte>,
368
                                    std::is_same<T, jchar>, std::is_same<T, jshort>,
369
                                    std::is_same<T, jint>, std::is_same<T, jlong>,
370
                                    std::is_same<T, jfloat>, std::is_same<T, jdouble>>
371
14.2k
    FunctionCall& with_arg(T arg) {
372
14.2k
        jvalue v;
373
14.2k
        std::memset(&v, 0, sizeof(v));
374
14.2k
        if constexpr (std::is_same_v<T, jboolean>) {
375
208
            v.z = arg;
376
        } else if constexpr (std::is_same_v<T, jbyte>) {
377
            v.b = arg;
378
        } else if constexpr (std::is_same_v<T, jchar>) {
379
            v.c = arg;
380
        } else if constexpr (std::is_same_v<T, jshort>) {
381
            v.s = arg;
382
13.6k
        } else if constexpr (std::is_same_v<T, jint>) {
383
13.6k
            v.i = arg;
384
13.6k
        } else if constexpr (std::is_same_v<T, jlong>) {
385
402
            v.j = arg;
386
        } else if constexpr (std::is_same_v<T, jfloat>) {
387
            v.f = arg;
388
        } else if constexpr (std::is_same_v<T, jdouble>) {
389
            v.d = arg;
390
        } else {
391
            static_assert(false);
392
        }
393
14.2k
        _args.push_back(v);
394
14.2k
        return *this;
395
14.2k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE0EE8with_argIiQsr3stdE13disjunction_vISt7is_sameITL0__hES5_IS6_aES5_IS6_tES5_IS6_sES5_IS6_iES5_IS6_lES5_IS6_fES5_IS6_dEEEERS3_T_
Line
Count
Source
371
7.51k
    FunctionCall& with_arg(T arg) {
372
7.51k
        jvalue v;
373
7.51k
        std::memset(&v, 0, sizeof(v));
374
        if constexpr (std::is_same_v<T, jboolean>) {
375
            v.z = arg;
376
        } else if constexpr (std::is_same_v<T, jbyte>) {
377
            v.b = arg;
378
        } else if constexpr (std::is_same_v<T, jchar>) {
379
            v.c = arg;
380
        } else if constexpr (std::is_same_v<T, jshort>) {
381
            v.s = arg;
382
7.51k
        } else if constexpr (std::is_same_v<T, jint>) {
383
7.51k
            v.i = arg;
384
        } else if constexpr (std::is_same_v<T, jlong>) {
385
            v.j = arg;
386
        } else if constexpr (std::is_same_v<T, jfloat>) {
387
            v.f = arg;
388
        } else if constexpr (std::is_same_v<T, jdouble>) {
389
            v.d = arg;
390
        } else {
391
            static_assert(false);
392
        }
393
7.51k
        _args.push_back(v);
394
7.51k
        return *this;
395
7.51k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE9EE8with_argIiQsr3stdE13disjunction_vISt7is_sameITL0__hES5_IS6_aES5_IS6_tES5_IS6_sES5_IS6_iES5_IS6_lES5_IS6_fES5_IS6_dEEEERS3_T_
Line
Count
Source
371
5.49k
    FunctionCall& with_arg(T arg) {
372
5.49k
        jvalue v;
373
5.49k
        std::memset(&v, 0, sizeof(v));
374
        if constexpr (std::is_same_v<T, jboolean>) {
375
            v.z = arg;
376
        } else if constexpr (std::is_same_v<T, jbyte>) {
377
            v.b = arg;
378
        } else if constexpr (std::is_same_v<T, jchar>) {
379
            v.c = arg;
380
        } else if constexpr (std::is_same_v<T, jshort>) {
381
            v.s = arg;
382
5.49k
        } else if constexpr (std::is_same_v<T, jint>) {
383
5.49k
            v.i = arg;
384
        } else if constexpr (std::is_same_v<T, jlong>) {
385
            v.j = arg;
386
        } else if constexpr (std::is_same_v<T, jfloat>) {
387
            v.f = arg;
388
        } else if constexpr (std::is_same_v<T, jdouble>) {
389
            v.d = arg;
390
        } else {
391
            static_assert(false);
392
        }
393
5.49k
        _args.push_back(v);
394
5.49k
        return *this;
395
5.49k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE3EE8with_argIhQsr3stdE13disjunction_vISt7is_sameITL0__hES5_IS6_aES5_IS6_tES5_IS6_sES5_IS6_iES5_IS6_lES5_IS6_fES5_IS6_dEEEERS3_T_
Line
Count
Source
371
208
    FunctionCall& with_arg(T arg) {
372
208
        jvalue v;
373
208
        std::memset(&v, 0, sizeof(v));
374
208
        if constexpr (std::is_same_v<T, jboolean>) {
375
208
            v.z = arg;
376
        } else if constexpr (std::is_same_v<T, jbyte>) {
377
            v.b = arg;
378
        } else if constexpr (std::is_same_v<T, jchar>) {
379
            v.c = arg;
380
        } else if constexpr (std::is_same_v<T, jshort>) {
381
            v.s = arg;
382
        } else if constexpr (std::is_same_v<T, jint>) {
383
            v.i = arg;
384
        } else if constexpr (std::is_same_v<T, jlong>) {
385
            v.j = arg;
386
        } else if constexpr (std::is_same_v<T, jfloat>) {
387
            v.f = arg;
388
        } else if constexpr (std::is_same_v<T, jdouble>) {
389
            v.d = arg;
390
        } else {
391
            static_assert(false);
392
        }
393
208
        _args.push_back(v);
394
208
        return *this;
395
208
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE3EE8with_argIiQsr3stdE13disjunction_vISt7is_sameITL0__hES5_IS6_aES5_IS6_tES5_IS6_sES5_IS6_iES5_IS6_lES5_IS6_fES5_IS6_dEEEERS3_T_
Line
Count
Source
371
637
    FunctionCall& with_arg(T arg) {
372
637
        jvalue v;
373
637
        std::memset(&v, 0, sizeof(v));
374
        if constexpr (std::is_same_v<T, jboolean>) {
375
            v.z = arg;
376
        } else if constexpr (std::is_same_v<T, jbyte>) {
377
            v.b = arg;
378
        } else if constexpr (std::is_same_v<T, jchar>) {
379
            v.c = arg;
380
        } else if constexpr (std::is_same_v<T, jshort>) {
381
            v.s = arg;
382
637
        } else if constexpr (std::is_same_v<T, jint>) {
383
637
            v.i = arg;
384
        } else if constexpr (std::is_same_v<T, jlong>) {
385
            v.j = arg;
386
        } else if constexpr (std::is_same_v<T, jfloat>) {
387
            v.f = arg;
388
        } else if constexpr (std::is_same_v<T, jdouble>) {
389
            v.d = arg;
390
        } else {
391
            static_assert(false);
392
        }
393
637
        _args.push_back(v);
394
637
        return *this;
395
637
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE3EE8with_argIlQsr3stdE13disjunction_vISt7is_sameITL0__hES5_IS6_aES5_IS6_tES5_IS6_sES5_IS6_iES5_IS6_lES5_IS6_fES5_IS6_dEEEERS3_T_
Line
Count
Source
371
210
    FunctionCall& with_arg(T arg) {
372
210
        jvalue v;
373
210
        std::memset(&v, 0, sizeof(v));
374
        if constexpr (std::is_same_v<T, jboolean>) {
375
            v.z = arg;
376
        } else if constexpr (std::is_same_v<T, jbyte>) {
377
            v.b = arg;
378
        } else if constexpr (std::is_same_v<T, jchar>) {
379
            v.c = arg;
380
        } else if constexpr (std::is_same_v<T, jshort>) {
381
            v.s = arg;
382
        } else if constexpr (std::is_same_v<T, jint>) {
383
            v.i = arg;
384
210
        } else if constexpr (std::is_same_v<T, jlong>) {
385
210
            v.j = arg;
386
        } else if constexpr (std::is_same_v<T, jfloat>) {
387
            v.f = arg;
388
        } else if constexpr (std::is_same_v<T, jdouble>) {
389
            v.d = arg;
390
        } else {
391
            static_assert(false);
392
        }
393
210
        _args.push_back(v);
394
210
        return *this;
395
210
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE2EE8with_argIlQsr3stdE13disjunction_vISt7is_sameITL0__hES5_IS6_aES5_IS6_tES5_IS6_sES5_IS6_iES5_IS6_lES5_IS6_fES5_IS6_dEEEERS3_T_
Line
Count
Source
371
192
    FunctionCall& with_arg(T arg) {
372
192
        jvalue v;
373
192
        std::memset(&v, 0, sizeof(v));
374
        if constexpr (std::is_same_v<T, jboolean>) {
375
            v.z = arg;
376
        } else if constexpr (std::is_same_v<T, jbyte>) {
377
            v.b = arg;
378
        } else if constexpr (std::is_same_v<T, jchar>) {
379
            v.c = arg;
380
        } else if constexpr (std::is_same_v<T, jshort>) {
381
            v.s = arg;
382
        } else if constexpr (std::is_same_v<T, jint>) {
383
            v.i = arg;
384
192
        } else if constexpr (std::is_same_v<T, jlong>) {
385
192
            v.j = arg;
386
        } else if constexpr (std::is_same_v<T, jfloat>) {
387
            v.f = arg;
388
        } else if constexpr (std::is_same_v<T, jdouble>) {
389
            v.d = arg;
390
        } else {
391
            static_assert(false);
392
        }
393
192
        _args.push_back(v);
394
192
        return *this;
395
192
    }
396
397
    template <RefType Ref>
398
    FunctionCall& with_arg(const Object<Ref>& obj) WARN_UNUSED_RESULT;
399
400
    template <typename ReturnType>
401
        requires(std::is_same_v<typename CallHelper<tag>::RETURN_TYPE, ReturnType>)
402
27.3k
    Status call(ReturnType* result) {
403
27.3k
        *result = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
404
27.3k
        RETURN_ERROR_IF_EXC(_env);
405
27.3k
        return Status::OK();
406
27.3k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE2EE4callIlQsr3stdE9is_same_vINS0_10CallHelperIXT_EE11RETURN_TYPEETL0__EEENS_6StatusEPT_
Line
Count
Source
402
25.2k
    Status call(ReturnType* result) {
403
25.2k
        *result = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
404
25.2k
        RETURN_ERROR_IF_EXC(_env);
405
25.2k
        return Status::OK();
406
25.2k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE1EE4callIiQsr3stdE9is_same_vINS0_10CallHelperIXT_EE11RETURN_TYPEETL0__EEENS_6StatusEPT_
Line
Count
Source
402
2.04k
    Status call(ReturnType* result) {
403
2.04k
        *result = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
404
2.04k
        RETURN_ERROR_IF_EXC(_env);
405
2.04k
        return Status::OK();
406
2.04k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE4EE4callIhQsr3stdE9is_same_vINS0_10CallHelperIXT_EE11RETURN_TYPEETL0__EEENS_6StatusEPT_
Line
Count
Source
402
6
    Status call(ReturnType* result) {
403
6
        *result = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
404
6
        RETURN_ERROR_IF_EXC(_env);
405
6
        return Status::OK();
406
6
    }
407
408
    Status call(Object<Local>* result);
409
410
    Status call(Object<Global>* result);
411
412
16.7k
    Status call() {
413
16.7k
        using return_type = typename CallHelper<tag>::RETURN_TYPE;
414
        if constexpr (std::disjunction_v<
415
                              std::is_same<return_type, jboolean>, std::is_same<return_type, jbyte>,
416
                              std::is_same<return_type, jchar>, std::is_same<return_type, jshort>,
417
                              std::is_same<return_type, jint>, std::is_same<return_type, jlong>,
418
                              std::is_same<return_type, jfloat>, std::is_same<return_type, jdouble>,
419
237
                              std::is_same<return_type, void>>) {
420
237
            CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
421
237
            RETURN_ERROR_IF_EXC(_env);
422
16.5k
        } else if constexpr (std::is_same_v<return_type, jobject>) {
423
16.5k
            jobject tmp = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
424
16.5k
            _env->DeleteLocalRef(tmp);
425
16.5k
            RETURN_ERROR_IF_EXC(_env);
426
        } else {
427
            static_assert(false);
428
        }
429
16.7k
        return Status::OK();
430
16.7k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE0EE4callEv
Line
Count
Source
412
16.5k
    Status call() {
413
16.5k
        using return_type = typename CallHelper<tag>::RETURN_TYPE;
414
        if constexpr (std::disjunction_v<
415
                              std::is_same<return_type, jboolean>, std::is_same<return_type, jbyte>,
416
                              std::is_same<return_type, jchar>, std::is_same<return_type, jshort>,
417
                              std::is_same<return_type, jint>, std::is_same<return_type, jlong>,
418
                              std::is_same<return_type, jfloat>, std::is_same<return_type, jdouble>,
419
                              std::is_same<return_type, void>>) {
420
            CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
421
            RETURN_ERROR_IF_EXC(_env);
422
16.5k
        } else if constexpr (std::is_same_v<return_type, jobject>) {
423
16.5k
            jobject tmp = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
424
16.5k
            _env->DeleteLocalRef(tmp);
425
16.5k
            RETURN_ERROR_IF_EXC(_env);
426
        } else {
427
            static_assert(false);
428
        }
429
16.5k
        return Status::OK();
430
16.5k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE3EE4callEv
Line
Count
Source
412
237
    Status call() {
413
237
        using return_type = typename CallHelper<tag>::RETURN_TYPE;
414
        if constexpr (std::disjunction_v<
415
                              std::is_same<return_type, jboolean>, std::is_same<return_type, jbyte>,
416
                              std::is_same<return_type, jchar>, std::is_same<return_type, jshort>,
417
                              std::is_same<return_type, jint>, std::is_same<return_type, jlong>,
418
                              std::is_same<return_type, jfloat>, std::is_same<return_type, jdouble>,
419
237
                              std::is_same<return_type, void>>) {
420
237
            CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
421
237
            RETURN_ERROR_IF_EXC(_env);
422
        } else if constexpr (std::is_same_v<return_type, jobject>) {
423
            jobject tmp = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
424
            _env->DeleteLocalRef(tmp);
425
            RETURN_ERROR_IF_EXC(_env);
426
        } else {
427
            static_assert(false);
428
        }
429
237
        return Status::OK();
430
237
    }
Unexecuted instantiation: _ZN5doris3Jni12FunctionCallILNS0_7CallTagE8EE4callEv
431
432
protected:
433
    explicit FunctionCall(JNIEnv* env, typename CallHelper<tag>::BASE_TYPE base,
434
                          jmethodID method_id)
435
151k
            : _env(env), _base(base), _method(method_id) {}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE5EEC2EP7JNIEnv_P7_jclassP10_jmethodID
Line
Count
Source
435
2.73k
            : _env(env), _base(base), _method(method_id) {}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE0EEC2EP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
435
104k
            : _env(env), _base(base), _method(method_id) {}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE2EEC2EP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
435
25.2k
            : _env(env), _base(base), _method(method_id) {}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE1EEC2EP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
435
2.04k
            : _env(env), _base(base), _method(method_id) {}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE9EEC2EP7JNIEnv_P7_jclassP10_jmethodID
Line
Count
Source
435
10.5k
            : _env(env), _base(base), _method(method_id) {}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE10EEC2EP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
435
5.97k
            : _env(env), _base(base), _method(method_id) {}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE3EEC2EP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
435
239
            : _env(env), _base(base), _method(method_id) {}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE11EEC2EP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
435
40
            : _env(env), _base(base), _method(method_id) {}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE4EEC2EP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
435
6
            : _env(env), _base(base), _method(method_id) {}
Unexecuted instantiation: _ZN5doris3Jni12FunctionCallILNS0_7CallTagE8EEC2EP7JNIEnv_P7_jclassP10_jmethodID
436
437
    JNIEnv* _env = nullptr;
438
    CallHelper<tag>::BASE_TYPE _base; // is jobject/jclass  not need new/delete local/global ref.
439
    const jmethodID _method = nullptr;
440
    std::vector<jvalue> _args;
441
    Status _st = Status::OK();
442
    DISALLOW_COPY_AND_ASSIGN(FunctionCall);
443
};
444
445
template <CallTag tag>
446
class NonvirtualFunctionCall : public FunctionCall<tag> {
447
public:
448
    NonvirtualFunctionCall(NonvirtualFunctionCall&& other) noexcept = default;
449
450
    static NonvirtualFunctionCall instance(JNIEnv* env, typename CallHelper<tag>::BASE_TYPE base,
451
6.01k
                                           jclass cls, jmethodID method_id) {
452
6.01k
        return NonvirtualFunctionCall(env, base, cls, method_id);
453
6.01k
    }
_ZN5doris3Jni22NonvirtualFunctionCallILNS0_7CallTagE10EE8instanceEP7JNIEnv_P8_jobjectP7_jclassP10_jmethodID
Line
Count
Source
451
5.97k
                                           jclass cls, jmethodID method_id) {
452
5.97k
        return NonvirtualFunctionCall(env, base, cls, method_id);
453
5.97k
    }
_ZN5doris3Jni22NonvirtualFunctionCallILNS0_7CallTagE11EE8instanceEP7JNIEnv_P8_jobjectP7_jclassP10_jmethodID
Line
Count
Source
451
40
                                           jclass cls, jmethodID method_id) {
452
40
        return NonvirtualFunctionCall(env, base, cls, method_id);
453
40
    }
454
455
    // no override
456
    template <class T>
457
        requires std::disjunction_v<std::is_same<T, jboolean>, std::is_same<T, jbyte>,
458
                                    std::is_same<T, jchar>, std::is_same<T, jshort>,
459
                                    std::is_same<T, jint>, std::is_same<T, jlong>,
460
                                    std::is_same<T, jfloat>, std::is_same<T, jdouble>>
461
117
    NonvirtualFunctionCall& with_arg(T arg) {
462
117
        jvalue v;
463
117
        std::memset(&v, 0, sizeof(v));
464
        if constexpr (std::is_same_v<T, jboolean>) {
465
            v.z = arg;
466
        } else if constexpr (std::is_same_v<T, jbyte>) {
467
            v.b = arg;
468
        } else if constexpr (std::is_same_v<T, jchar>) {
469
            v.c = arg;
470
        } else if constexpr (std::is_same_v<T, jshort>) {
471
            v.s = arg;
472
        } else if constexpr (std::is_same_v<T, jint>) {
473
            v.i = arg;
474
117
        } else if constexpr (std::is_same_v<T, jlong>) {
475
117
            v.j = arg;
476
        } else if constexpr (std::is_same_v<T, jfloat>) {
477
            v.f = arg;
478
        } else if constexpr (std::is_same_v<T, jdouble>) {
479
            v.d = arg;
480
        } else {
481
            static_assert(false);
482
        }
483
117
        this->_args.push_back(v);
484
117
        return *this;
485
117
    }
_ZN5doris3Jni22NonvirtualFunctionCallILNS0_7CallTagE10EE8with_argIlQsr3stdE13disjunction_vISt7is_sameITL0__hES5_IS6_aES5_IS6_tES5_IS6_sES5_IS6_iES5_IS6_lES5_IS6_fES5_IS6_dEEEERS3_T_
Line
Count
Source
461
77
    NonvirtualFunctionCall& with_arg(T arg) {
462
77
        jvalue v;
463
77
        std::memset(&v, 0, sizeof(v));
464
        if constexpr (std::is_same_v<T, jboolean>) {
465
            v.z = arg;
466
        } else if constexpr (std::is_same_v<T, jbyte>) {
467
            v.b = arg;
468
        } else if constexpr (std::is_same_v<T, jchar>) {
469
            v.c = arg;
470
        } else if constexpr (std::is_same_v<T, jshort>) {
471
            v.s = arg;
472
        } else if constexpr (std::is_same_v<T, jint>) {
473
            v.i = arg;
474
77
        } else if constexpr (std::is_same_v<T, jlong>) {
475
77
            v.j = arg;
476
        } else if constexpr (std::is_same_v<T, jfloat>) {
477
            v.f = arg;
478
        } else if constexpr (std::is_same_v<T, jdouble>) {
479
            v.d = arg;
480
        } else {
481
            static_assert(false);
482
        }
483
77
        this->_args.push_back(v);
484
77
        return *this;
485
77
    }
_ZN5doris3Jni22NonvirtualFunctionCallILNS0_7CallTagE11EE8with_argIlQsr3stdE13disjunction_vISt7is_sameITL0__hES5_IS6_aES5_IS6_tES5_IS6_sES5_IS6_iES5_IS6_lES5_IS6_fES5_IS6_dEEEERS3_T_
Line
Count
Source
461
40
    NonvirtualFunctionCall& with_arg(T arg) {
462
40
        jvalue v;
463
40
        std::memset(&v, 0, sizeof(v));
464
        if constexpr (std::is_same_v<T, jboolean>) {
465
            v.z = arg;
466
        } else if constexpr (std::is_same_v<T, jbyte>) {
467
            v.b = arg;
468
        } else if constexpr (std::is_same_v<T, jchar>) {
469
            v.c = arg;
470
        } else if constexpr (std::is_same_v<T, jshort>) {
471
            v.s = arg;
472
        } else if constexpr (std::is_same_v<T, jint>) {
473
            v.i = arg;
474
40
        } else if constexpr (std::is_same_v<T, jlong>) {
475
40
            v.j = arg;
476
        } else if constexpr (std::is_same_v<T, jfloat>) {
477
            v.f = arg;
478
        } else if constexpr (std::is_same_v<T, jdouble>) {
479
            v.d = arg;
480
        } else {
481
            static_assert(false);
482
        }
483
40
        this->_args.push_back(v);
484
40
        return *this;
485
40
    }
486
487
    template <RefType Ref>
488
    NonvirtualFunctionCall& with_arg(const Object<Ref>& obj) WARN_UNUSED_RESULT;
489
490
    // no override
491
5.97k
    Status call() {
492
5.97k
        using return_type = typename CallHelper<tag>::RETURN_TYPE;
493
        if constexpr (std::disjunction_v<
494
                              std::is_same<return_type, jboolean>, std::is_same<return_type, jbyte>,
495
                              std::is_same<return_type, jchar>, std::is_same<return_type, jshort>,
496
                              std::is_same<return_type, jint>, std::is_same<return_type, jlong>,
497
                              std::is_same<return_type, jfloat>, std::is_same<return_type, jdouble>,
498
5.97k
                              std::is_same<return_type, void>>) {
499
5.97k
            CallHelper<tag>::call_impl(this->_env, this->_base, _cls, this->_method,
500
5.97k
                                       this->_args.data());
501
5.97k
            RETURN_ERROR_IF_EXC(this->_env);
502
        } else if constexpr (std::is_same_v<return_type, jobject>) {
503
            jobject tmp = CallHelper<tag>::call_impl(this->_env, this->_base, _cls, this->_method,
504
                                                     this->_args.data());
505
            RETURN_ERROR_IF_EXC(this->_env);
506
            this->_env->DeleteLocalRef(tmp);
507
        } else {
508
            static_assert(false);
509
        }
510
5.97k
        return Status::OK();
511
5.97k
    }
512
513
    Status call(Object<Local>* result);
514
515
    template <typename ReturnType>
516
        requires(std::is_same_v<typename CallHelper<tag>::RETURN_TYPE, ReturnType>)
517
    Status call(ReturnType* result) {
518
        *result = CallHelper<tag>::call_impl(this->_env, this->_base, _cls, this->_method,
519
                                             this->_args.data());
520
        RETURN_ERROR_IF_EXC(this->_env);
521
        return Status::OK();
522
    }
523
524
private:
525
    explicit NonvirtualFunctionCall(JNIEnv* env, typename CallHelper<tag>::BASE_TYPE base,
526
                                    jclass cls, jmethodID method_id)
527
6.01k
            : FunctionCall<tag>(env, base, method_id), _cls(cls) {}
_ZN5doris3Jni22NonvirtualFunctionCallILNS0_7CallTagE10EEC2EP7JNIEnv_P8_jobjectP7_jclassP10_jmethodID
Line
Count
Source
527
5.97k
            : FunctionCall<tag>(env, base, method_id), _cls(cls) {}
_ZN5doris3Jni22NonvirtualFunctionCallILNS0_7CallTagE11EEC2EP7JNIEnv_P8_jobjectP7_jclassP10_jmethodID
Line
Count
Source
527
40
            : FunctionCall<tag>(env, base, method_id), _cls(cls) {}
528
    jclass _cls;
529
    DISALLOW_COPY_AND_ASSIGN(NonvirtualFunctionCall);
530
};
531
532
/**
533
 * When writing JNI code, developers usually need to pay extra attention to several error-prone aspects, including:
534
 * 1. The reference type of jobject (local vs. global)
535
 * 2. The lifetime and scope of JNI references
536
 * 3. Proper release of references after use
537
 * 4. Explicit exception checking after JNI calls
538
 * Because these concerns are verbose and easy to overlook, they often lead to bugs or inconsistent code. To simplify this, 
539
 * we provide a wrapper framework around raw JNI APIs. The following describes how to use it (assuming the user already 
540
 * understands the basic JNI programming model).
541
 *
542
 * 0. Get JNIEnv* env: `Status st = Jni::Env::Get(&env)`
543
 * 1. Choose the reference type
544
 *   First, determine whether the JNI object should be a local or global reference. Based on this, create the corresponding C++ wrapper object:
545
 *   LocalObject / GlobalObject. If the exact JNI type is known, use specialized wrappers such as <Local/Global><Array/String/Class>. 
546
 * 2. Initialize the object
547
 *   For `jclass`, typically use: `Status st = Jni::Util::find_class(xxx);`
548
 *   For other object types, they are usually initialized via: `Status st = clazz.new_object(xxx).with_arg(xxx).call(&object) or by calling methods on existing objects.
549
 * 3. Call methods and retrieve results
550
 *   To invoke a method and obtain a return value, use: `Status st = object.call_<return_type>_method(xxx).call(&result);` 
551
 * 
552
 * Notes
553
 * 1. All JNI references are automatically released in the wrapper’s destructor, ensuring safe and deterministic cleanup.
554
 * 2. All framework method invocations return a Status.
555
 * The actual JNI return value is written to the address passed to call().
556
 * 
557
 * Example: be/test/util/jni_util_test.cpp
558
*/
559
template <RefType Ref>
560
class Object {
561
    // env->GetObjectRefType
562
public:
563
239k
    Object() = default;
_ZN5doris3Jni6ObjectILNS0_7RefTypeE1EEC2Ev
Line
Count
Source
563
10.5k
    Object() = default;
_ZN5doris3Jni6ObjectILNS0_7RefTypeE0EEC2Ev
Line
Count
Source
563
228k
    Object() = default;
564
565
    template <RefType U>
566
    friend class Object;
567
568
    template <RefType U>
569
    friend class Class;
570
571
    template <RefType U>
572
    friend class String;
573
574
    template <RefType U>
575
    friend class Array;
576
577
    template <BufferType bufferfType, RefType U>
578
    friend class BufferGuard;
579
580
    template <CallTag tag>
581
    friend class FunctionCall;
582
583
    template <CallTag tag>
584
    friend class NonvirtualFunctionCall;
585
586
239k
    virtual ~Object() {
587
239k
        if (_obj != nullptr) [[likely]] {
588
222k
            JNIEnv* env = nullptr;
589
222k
            if (Status st = RefHelper<Ref>::get_env(&env); !st.ok()) [[unlikely]] {
590
0
                LOG(WARNING) << "Can't destroy Jni Ref : " << st.msg();
591
0
                return;
592
0
            }
593
222k
            RefHelper<Ref>::destroy(env, _obj);
594
222k
        }
595
239k
    }
_ZN5doris3Jni6ObjectILNS0_7RefTypeE0EED2Ev
Line
Count
Source
586
228k
    virtual ~Object() {
587
228k
        if (_obj != nullptr) [[likely]] {
588
212k
            JNIEnv* env = nullptr;
589
212k
            if (Status st = RefHelper<Ref>::get_env(&env); !st.ok()) [[unlikely]] {
590
0
                LOG(WARNING) << "Can't destroy Jni Ref : " << st.msg();
591
0
                return;
592
0
            }
593
212k
            RefHelper<Ref>::destroy(env, _obj);
594
212k
        }
595
228k
    }
_ZN5doris3Jni6ObjectILNS0_7RefTypeE1EED2Ev
Line
Count
Source
586
10.5k
    virtual ~Object() {
587
10.5k
        if (_obj != nullptr) [[likely]] {
588
10.3k
            JNIEnv* env = nullptr;
589
10.3k
            if (Status st = RefHelper<Ref>::get_env(&env); !st.ok()) [[unlikely]] {
590
0
                LOG(WARNING) << "Can't destroy Jni Ref : " << st.msg();
591
0
                return;
592
0
            }
593
10.3k
            RefHelper<Ref>::destroy(env, _obj);
594
10.3k
        }
595
10.5k
    }
596
597
    template <RefType R>
598
17.2k
    static Status create(JNIEnv* env, const Object<R>& other, Object<Ref>* result) {
599
17.2k
        DCHECK(!other.uninitialized());
600
17.2k
        DCHECK(result->uninitialized());
601
602
17.2k
        result->_obj = RefHelper<Ref>::create(env, other._obj);
603
17.2k
        RETURN_ERROR_IF_EXC(env);
604
17.2k
        return Status::OK();
605
17.2k
    }
_ZN5doris3Jni6ObjectILNS0_7RefTypeE1EE6createILS2_0EEENS_6StatusEP7JNIEnv_RKNS1_IXT_EEEPS3_
Line
Count
Source
598
10.3k
    static Status create(JNIEnv* env, const Object<R>& other, Object<Ref>* result) {
599
10.3k
        DCHECK(!other.uninitialized());
600
10.3k
        DCHECK(result->uninitialized());
601
602
10.3k
        result->_obj = RefHelper<Ref>::create(env, other._obj);
603
10.3k
        RETURN_ERROR_IF_EXC(env);
604
10.3k
        return Status::OK();
605
10.3k
    }
_ZN5doris3Jni6ObjectILNS0_7RefTypeE0EE6createILS2_0EEENS_6StatusEP7JNIEnv_RKNS1_IXT_EEEPS3_
Line
Count
Source
598
6.83k
    static Status create(JNIEnv* env, const Object<R>& other, Object<Ref>* result) {
599
6.83k
        DCHECK(!other.uninitialized());
600
6.83k
        DCHECK(result->uninitialized());
601
602
6.83k
        result->_obj = RefHelper<Ref>::create(env, other._obj);
603
6.83k
        RETURN_ERROR_IF_EXC(env);
604
6.83k
        return Status::OK();
605
6.83k
    }
606
607
798k
    bool uninitialized() const { return _obj == nullptr; }
_ZNK5doris3Jni6ObjectILNS0_7RefTypeE0EE13uninitializedEv
Line
Count
Source
607
610k
    bool uninitialized() const { return _obj == nullptr; }
_ZNK5doris3Jni6ObjectILNS0_7RefTypeE1EE13uninitializedEv
Line
Count
Source
607
187k
    bool uninitialized() const { return _obj == nullptr; }
608
609
2
    void reset(JNIEnv* env) {
610
2
        if (_obj == nullptr) {
611
0
            return;
612
0
        }
613
2
        RefHelper<Ref>::destroy(env, _obj);
614
2
        _obj = nullptr;
615
2
    }
616
617
    template <RefType T>
618
127k
    bool equal(JNIEnv* env, const Object<T>& other) {
619
127k
        DCHECK(!uninitialized());
620
127k
        DCHECK(!other.uninitialized());
621
127k
        return env->IsSameObject(this->_obj, other._obj); //assume not throw exception.
622
127k
    }
623
624
104k
    FunctionCall<ObjectMethod> call_object_method(JNIEnv* env, MethodId method_id) const {
625
104k
        DCHECK(!this->uninitialized());
626
104k
        DCHECK(!method_id.uninitialized());
627
104k
        return FunctionCall<ObjectMethod>::instance(env, _obj, method_id._id);
628
104k
    }
_ZNK5doris3Jni6ObjectILNS0_7RefTypeE0EE18call_object_methodEP7JNIEnv_NS0_8MethodIdE
Line
Count
Source
624
104k
    FunctionCall<ObjectMethod> call_object_method(JNIEnv* env, MethodId method_id) const {
625
104k
        DCHECK(!this->uninitialized());
626
        DCHECK(!method_id.uninitialized());
627
104k
        return FunctionCall<ObjectMethod>::instance(env, _obj, method_id._id);
628
104k
    }
_ZNK5doris3Jni6ObjectILNS0_7RefTypeE1EE18call_object_methodEP7JNIEnv_NS0_8MethodIdE
Line
Count
Source
624
7
    FunctionCall<ObjectMethod> call_object_method(JNIEnv* env, MethodId method_id) const {
625
7
        DCHECK(!this->uninitialized());
626
        DCHECK(!method_id.uninitialized());
627
7
        return FunctionCall<ObjectMethod>::instance(env, _obj, method_id._id);
628
7
    }
629
630
2.04k
    FunctionCall<IntMethod> call_int_method(JNIEnv* env, MethodId method_id) const {
631
2.04k
        DCHECK(!this->uninitialized());
632
2.04k
        DCHECK(!method_id.uninitialized());
633
2.04k
        return FunctionCall<IntMethod>::instance(env, _obj, method_id._id);
634
2.04k
    }
635
636
25.2k
    FunctionCall<LongMethod> call_long_method(JNIEnv* env, MethodId method_id) const {
637
25.2k
        DCHECK(!this->uninitialized());
638
25.2k
        DCHECK(!method_id.uninitialized());
639
25.2k
        return FunctionCall<LongMethod>::instance(env, _obj, method_id._id);
640
25.2k
    }
_ZNK5doris3Jni6ObjectILNS0_7RefTypeE0EE16call_long_methodEP7JNIEnv_NS0_8MethodIdE
Line
Count
Source
636
22.5k
    FunctionCall<LongMethod> call_long_method(JNIEnv* env, MethodId method_id) const {
637
22.5k
        DCHECK(!this->uninitialized());
638
        DCHECK(!method_id.uninitialized());
639
22.5k
        return FunctionCall<LongMethod>::instance(env, _obj, method_id._id);
640
22.5k
    }
_ZNK5doris3Jni6ObjectILNS0_7RefTypeE1EE16call_long_methodEP7JNIEnv_NS0_8MethodIdE
Line
Count
Source
636
2.74k
    FunctionCall<LongMethod> call_long_method(JNIEnv* env, MethodId method_id) const {
637
2.74k
        DCHECK(!this->uninitialized());
638
        DCHECK(!method_id.uninitialized());
639
2.74k
        return FunctionCall<LongMethod>::instance(env, _obj, method_id._id);
640
2.74k
    }
641
642
239
    FunctionCall<VoidMethod> call_void_method(JNIEnv* env, MethodId method_id) const {
643
239
        DCHECK(!this->uninitialized());
644
239
        DCHECK(!method_id.uninitialized());
645
239
        return FunctionCall<VoidMethod>::instance(env, _obj, method_id._id);
646
239
    }
647
648
6
    FunctionCall<BooleanMethod> call_boolean_method(JNIEnv* env, MethodId method_id) const {
649
6
        DCHECK(!this->uninitialized());
650
6
        DCHECK(!method_id.uninitialized());
651
6
        return FunctionCall<BooleanMethod>::instance(env, _obj, method_id._id);
652
6
    }
653
654
    template <RefType R>
655
    NonvirtualFunctionCall<NonvirtualVoidMethod> call_nonvirtual_void_method(
656
            JNIEnv* env, const Class<R>& clazz, MethodId method_id) const;
657
658
    template <RefType R>
659
    NonvirtualFunctionCall<NonvirtualObjectMethod> call_nonvirtual_object_method(
660
            JNIEnv* env, const Class<R>& clazz, MethodId method_id) const;
661
662
    template <RefType R>
663
    NonvirtualFunctionCall<NonvirtualIntMethod> call_nonvirtual_int_method(
664
            JNIEnv* env, const Class<R>& clazz, MethodId method_id) const;
665
666
    template <RefType R>
667
    NonvirtualFunctionCall<NonvirtualBooleanMethod> call_nonvirtual_boolean_method(
668
            JNIEnv* env, const Class<R>& clazz, MethodId method_id) const;
669
670
protected:
671
    jobject _obj = nullptr;
672
    DISALLOW_COPY_AND_ASSIGN(Object);
673
};
674
675
using LocalObject = Object<Local>;
676
using GlobalObject = Object<Global>;
677
678
static inline Status local_to_global_ref(JNIEnv* env, const LocalObject& local_ref,
679
10.4k
                                         GlobalObject* global_ref) {
680
10.4k
    return Object<Global>::create(env, local_ref, global_ref);
681
10.4k
}
Unexecuted instantiation: doris_main.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_0_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: config.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: doris_metrics.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
jvm_metrics.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Line
Count
Source
679
5.29k
                                         GlobalObject* global_ref) {
680
5.29k
    return Object<Global>::create(env, local_ref, global_ref);
681
5.29k
}
Unexecuted instantiation: unity_2_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: field.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_3_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
unity_1_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Line
Count
Source
679
5
                                         GlobalObject* global_ref) {
680
5
    return Object<Global>::create(env, local_ref, global_ref);
681
5
}
Unexecuted instantiation: unity_5_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_6_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: vdatetime_value.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: data_type_serde.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: data_type_number_serde.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_4_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: column_variant.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: convert_field_to_type.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_13_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_7_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_12_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_11_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_10_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_9_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_8_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: hashjoin_build_sink.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: join_build_sink_operator.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: operator.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: partitioned_aggregation_sink_operator.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: scan_operator.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: vfile_result_writer.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_30_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
unity_29_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Line
Count
Source
679
5.15k
                                         GlobalObject* global_ref) {
680
5.15k
    return Object<Global>::create(env, local_ref, global_ref);
681
5.15k
}
Unexecuted instantiation: unity_28_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_27_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_26_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_25_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_24_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_23_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_22_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_21_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_20_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_19_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_18_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_17_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_16_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_15_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_14_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: ai_functions.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: function_array_aggregation.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: function_cast_decimal.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: function_bitmap_variadic.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: function_date_or_datetime_computation.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: function_datetime_floor_ceil.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: function_jsonb_transform.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: function_string_misc.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: function_variant_element.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: in.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: minus.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: multiply.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: plus.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: round.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: uuid.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: arrow_row_batch.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: arrow_stream_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: csv_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: jni_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: new_json_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: native_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: vorc_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: column_type_convert.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: vparquet_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: schema_desc.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: vparquet_group_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: vparquet_column_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: vparquet_column_chunk_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: vparquet_page_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: parquet_column_convert.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: vparquet_page_index.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: parquet_block_split_bloom_filter.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: deletion_vector_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: es_http_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: es_scroll_parser.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: hive_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: hive_orc_nested_column_utils.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: hudi_jni_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: hudi_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: iceberg_delete_file_reader_helper.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: iceberg_position_delete_sys_table_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: iceberg_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: iceberg_orc_nested_column_utils.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: equality_delete.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: iceberg_sys_table_jni_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: jdbc_jni_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: max_compute_jni_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: paimon_cpp_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: paimon_jni_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: paimon_predicate_converter.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: paimon_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: parquet_metadata_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: parquet_utils.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: remote_doris_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: table_format_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: table_schema_change_helper.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: transactional_hive_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: trino_connector_jni_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: text_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: merge_partitioner.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: iceberg_partition_function.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: vcsv_transformer.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: vfile_format_transformer_factory.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: vjni_format_transformer.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: vnative_transformer.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: vorc_transformer.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: vparquet_transformer.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: adbc_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: hdfs_file_system.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: collection_statistics.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: inverted_index_compound_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: inverted_index_fs_directory.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: zone_map_index.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: vcollect_iterator.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: predicate_creator_comparison.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: predicate_creator_in_list_in.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: predicate_creator_in_list_not_in.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: tablet.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: engine_clone_task.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: descriptors.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: backend_service.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: internal_service.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: point_query_executor.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: be_server_starter_factory.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: http_service.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: arrow_flight_batch_reader.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: thrift_util.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: load_stream.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: routine_load_task_executor.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: cloud_compaction_action.cpp:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
682
683
// auto ReleaseStringUTFChars ReleaseByteArrayElements ...
684
template <BufferType bufferfType, RefType Ref>
685
class BufferGuard {
686
public:
687
6.83k
    BufferGuard() = default;
688
689
    template <RefType R>
690
    static Status create(JNIEnv* env, const Object<R>& object,
691
6.83k
                         BufferGuard<bufferfType, Ref>* result, jboolean* isCopy) {
692
6.83k
        DCHECK(result->_buffer == nullptr && result->_object.uninitialized());
693
694
6.83k
        RETURN_IF_ERROR(Object<Ref>::create(env, object, &result->_object));
695
696
6.83k
        if constexpr (bufferfType == BufferType::Chars) {
697
6.83k
            result->_buffer = env->GetStringUTFChars((jstring)result->_object._obj, isCopy);
698
        } else if constexpr (bufferfType == BufferType::ByteArray) {
699
            result->_buffer =
700
                    (char*)env->GetByteArrayElements((jbyteArray)result->_object._obj, isCopy);
701
        } else {
702
            static_assert(false);
703
        }
704
705
6.83k
        RETURN_ERROR_IF_EXC(env);
706
6.83k
        if (result->_buffer == nullptr) [[unlikely]] {
707
0
            return Status::JniError("GetStringUTFChars/GetByteArrayElements fail.");
708
0
        }
709
710
6.83k
        return Status::OK();
711
6.83k
    }
712
713
6.83k
    ~BufferGuard() {
714
6.83k
        if (_object.uninitialized() || _buffer == nullptr) [[unlikely]] {
715
0
            return;
716
0
        }
717
6.83k
        JNIEnv* env = nullptr;
718
719
6.83k
        if (auto st = RefHelper<Ref>::get_env(&env); !st.ok()) [[unlikely]] {
720
0
            LOG(WARNING) << "BufferGuard release fail: " << st;
721
0
            return;
722
0
        }
723
724
6.83k
        if constexpr (bufferfType == BufferType::Chars) {
725
6.83k
            env->ReleaseStringUTFChars((jstring)_object._obj, _buffer);
726
        } else if constexpr (bufferfType == BufferType::ByteArray) {
727
            env->ReleaseByteArrayElements((jbyteArray)_object._obj, (jbyte*)_buffer, JNI_ABORT);
728
        }
729
6.83k
    }
730
731
13.6k
    const char* get() const { return _buffer; }
732
733
private:
734
    Object<Ref> _object;
735
    const char* _buffer = nullptr;
736
737
    DISALLOW_COPY_AND_ASSIGN(BufferGuard);
738
};
739
740
template <RefType Ref>
741
using StringBufferGuard = BufferGuard<Chars, Ref>;
742
using LocalStringBufferGuard = BufferGuard<Chars, Local>;
743
using GlobalStringBufferGuard = BufferGuard<Chars, Global>;
744
745
template <RefType Ref>
746
using ByteArrayBufferGuard = BufferGuard<ByteArray, Ref>;
747
using LocalByteArrayBufferGuard = BufferGuard<ByteArray, Local>;
748
using GlobalByteArrayBufferGuard = BufferGuard<ByteArray, Global>;
749
750
template <RefType Ref>
751
class String : public Object<Ref> {
752
public:
753
39.9k
    String() = default;
754
755
33.0k
    static Status new_string(JNIEnv* env, const char* utf_chars, String<Ref>* result) {
756
33.0k
        DCHECK(result->uninitialized());
757
758
33.0k
        if constexpr (Ref == Local) {
759
33.0k
            result->_obj = env->NewStringUTF(utf_chars);
760
33.0k
            RETURN_ERROR_IF_EXC(env);
761
        } else if constexpr (Ref == Global) {
762
            String local_result;
763
            local_result->_obj = env->NewStringUTF(utf_chars);
764
            RETURN_ERROR_IF_EXC(env);
765
            RETURN_IF_ERROR(local_to_global_ref(env, local_result, result));
766
        } else {
767
            static_assert(false);
768
        }
769
33.0k
        return Status::OK();
770
33.0k
    }
771
772
6.83k
    Status get_string_chars(JNIEnv* env, StringBufferGuard<Ref>* jni_chars) const {
773
6.83k
        return StringBufferGuard<Ref>::create(env, *this, jni_chars, nullptr);
774
6.83k
    }
775
776
private:
777
    DISALLOW_COPY_AND_ASSIGN(String);
778
};
779
780
template <RefType Ref>
781
class Array : public Object<Ref> {
782
public:
783
6.55k
    Array() = default;
784
785
722
    Status get_length(JNIEnv* env, jsize* result) const {
786
722
        DCHECK(!this->uninitialized());
787
788
722
        *result = env->GetArrayLength((jarray)this->_obj);
789
722
        RETURN_ERROR_IF_EXC(env);
790
722
        return Status::OK();
791
722
    }
792
793
60.5k
    Status get_object_array_element(JNIEnv* env, jsize index, Jni::LocalObject* result) {
794
60.5k
        DCHECK(!this->uninitialized());
795
60.5k
        DCHECK(result->uninitialized());
796
60.5k
        result->_obj = env->GetObjectArrayElement((jobjectArray)this->_obj, index);
797
60.5k
        RETURN_ERROR_IF_EXC(env);
798
60.5k
        return Status::OK();
799
60.5k
    }
800
801
    Status get_byte_elements(JNIEnv* env, ByteArrayBufferGuard<Ref>* jni_bytes) const {
802
        DCHECK(!this->uninitialized());
803
        return ByteArrayBufferGuard<Ref>::create(env, *this, jni_bytes, nullptr);
804
    }
805
806
39
    Status get_byte_elements(JNIEnv* env, jsize start, jsize len, jbyte* buffer) {
807
39
        DCHECK(!this->uninitialized());
808
39
        env->GetByteArrayRegion((jbyteArray)this->_obj, start, len, buffer);
809
39
        RETURN_ERROR_IF_EXC(env);
810
39
        return Status::OK();
811
39
    }
812
813
    static Status WriteBufferToByteArray(JNIEnv* env, const jbyte* buffer, jint size,
814
5.11k
                                         Array<Local>* serialized_msg) {
815
5.11k
        DCHECK(serialized_msg->uninitialized());
816
        /// create jbyteArray given buffer
817
5.11k
        serialized_msg->_obj = env->NewByteArray(size);
818
5.11k
        RETURN_ERROR_IF_EXC(env);
819
5.11k
        if (serialized_msg->_obj == nullptr) [[unlikely]] {
820
0
            return Status::JniError("couldn't construct jbyteArray");
821
0
        }
822
5.11k
        env->SetByteArrayRegion((jbyteArray)serialized_msg->_obj, 0, size, buffer);
823
5.11k
        RETURN_ERROR_IF_EXC(env);
824
5.11k
        return Status::OK();
825
5.11k
    }
826
827
    template <class T>
828
5.04k
    static Status SerializeThriftMsg(JNIEnv* env, T* msg, Array<Local>* serialized_msg) {
829
5.04k
        int buffer_size = 100 * 1024; // start out with 100KB
830
5.04k
        ThriftSerializer serializer(false, buffer_size);
831
832
5.04k
        uint8_t* buffer = nullptr;
833
5.04k
        uint32_t size = 0;
834
5.04k
        RETURN_IF_ERROR(serializer.serialize(msg, &size, &buffer));
835
836
        // Make sure that 'size' is within the limit of INT_MAX as the use of
837
        // 'size' below takes int.
838
5.04k
        if (size > INT_MAX) [[unlikely]] {
839
0
            return Status::JniError(
840
0
                    "The length of the serialization buffer ({} bytes) exceeds the limit of {} "
841
0
                    "bytes",
842
0
                    size, INT_MAX);
843
0
        }
844
5.04k
        RETURN_IF_ERROR(WriteBufferToByteArray(env, (jbyte*)buffer, size, serialized_msg));
845
5.04k
        return Status::OK();
846
5.04k
    }
847
848
private:
849
    DISALLOW_COPY_AND_ASSIGN(Array);
850
};
851
852
template <RefType Ref>
853
class Class : public Object<Ref> {
854
public:
855
10.5k
    Class() = default;
_ZN5doris3Jni5ClassILNS0_7RefTypeE1EEC2Ev
Line
Count
Source
855
5.28k
    Class() = default;
_ZN5doris3Jni5ClassILNS0_7RefTypeE0EEC2Ev
Line
Count
Source
855
5.26k
    Class() = default;
856
857
5.25k
    static Status find_class(JNIEnv* env, const char* class_str, Class<Ref>* result) {
858
5.25k
        DCHECK(result->uninitialized());
859
5.25k
        if constexpr (Ref == Local) {
860
7
            result->_obj = env->FindClass(class_str);
861
7
            RETURN_ERROR_IF_EXC(env);
862
7
            return Status::OK();
863
5.24k
        } else if constexpr (Ref == Global) {
864
5.24k
            Class<Local> local_class;
865
5.24k
            local_class._obj = env->FindClass(class_str);
866
5.24k
            RETURN_ERROR_IF_EXC(env);
867
5.24k
            return local_to_global_ref(env, local_class, result);
868
        } else {
869
            static_assert(false);
870
        }
871
5.25k
    }
_ZN5doris3Jni5ClassILNS0_7RefTypeE1EE10find_classEP7JNIEnv_PKcPS3_
Line
Count
Source
857
5.24k
    static Status find_class(JNIEnv* env, const char* class_str, Class<Ref>* result) {
858
5.24k
        DCHECK(result->uninitialized());
859
        if constexpr (Ref == Local) {
860
            result->_obj = env->FindClass(class_str);
861
            RETURN_ERROR_IF_EXC(env);
862
            return Status::OK();
863
5.24k
        } else if constexpr (Ref == Global) {
864
5.24k
            Class<Local> local_class;
865
5.24k
            local_class._obj = env->FindClass(class_str);
866
5.24k
            RETURN_ERROR_IF_EXC(env);
867
5.24k
            return local_to_global_ref(env, local_class, result);
868
        } else {
869
            static_assert(false);
870
        }
871
5.24k
    }
_ZN5doris3Jni5ClassILNS0_7RefTypeE0EE10find_classEP7JNIEnv_PKcPS3_
Line
Count
Source
857
7
    static Status find_class(JNIEnv* env, const char* class_str, Class<Ref>* result) {
858
7
        DCHECK(result->uninitialized());
859
7
        if constexpr (Ref == Local) {
860
7
            result->_obj = env->FindClass(class_str);
861
7
            RETURN_ERROR_IF_EXC(env);
862
7
            return Status::OK();
863
        } else if constexpr (Ref == Global) {
864
            Class<Local> local_class;
865
            local_class._obj = env->FindClass(class_str);
866
            RETURN_ERROR_IF_EXC(env);
867
            return local_to_global_ref(env, local_class, result);
868
        } else {
869
            static_assert(false);
870
        }
871
7
    }
872
873
    Status get_static_method(JNIEnv* env, const char* method_str, const char* method_signature,
874
28
                             MethodId* method_id) const {
875
28
        DCHECK(!this->uninitialized());
876
28
        DCHECK(method_id->uninitialized());
877
28
        method_id->_id = env->GetStaticMethodID((jclass)this->_obj, method_str, method_signature);
878
28
        RETURN_ERROR_IF_EXC(env);
879
28
        return Status::OK();
880
28
    }
_ZNK5doris3Jni5ClassILNS0_7RefTypeE1EE17get_static_methodEP7JNIEnv_PKcS7_PNS0_8MethodIdE
Line
Count
Source
874
28
                             MethodId* method_id) const {
875
28
        DCHECK(!this->uninitialized());
876
28
        DCHECK(method_id->uninitialized());
877
28
        method_id->_id = env->GetStaticMethodID((jclass)this->_obj, method_str, method_signature);
878
28
        RETURN_ERROR_IF_EXC(env);
879
28
        return Status::OK();
880
28
    }
Unexecuted instantiation: _ZNK5doris3Jni5ClassILNS0_7RefTypeE0EE17get_static_methodEP7JNIEnv_PKcS7_PNS0_8MethodIdE
881
882
    Status get_method(JNIEnv* env, const char* method_str, const char* method_signature,
883
16.7k
                      MethodId* method_id) const {
884
16.7k
        DCHECK(!this->uninitialized());
885
16.7k
        DCHECK(method_id->uninitialized());
886
16.7k
        method_id->_id = env->GetMethodID((jclass)this->_obj, method_str, method_signature);
887
16.7k
        RETURN_ERROR_IF_EXC(env);
888
16.7k
        return Status::OK();
889
16.7k
    }
_ZNK5doris3Jni5ClassILNS0_7RefTypeE1EE10get_methodEP7JNIEnv_PKcS7_PNS0_8MethodIdE
Line
Count
Source
883
16.6k
                      MethodId* method_id) const {
884
16.6k
        DCHECK(!this->uninitialized());
885
16.6k
        DCHECK(method_id->uninitialized());
886
16.6k
        method_id->_id = env->GetMethodID((jclass)this->_obj, method_str, method_signature);
887
16.6k
        RETURN_ERROR_IF_EXC(env);
888
16.6k
        return Status::OK();
889
16.6k
    }
_ZNK5doris3Jni5ClassILNS0_7RefTypeE0EE10get_methodEP7JNIEnv_PKcS7_PNS0_8MethodIdE
Line
Count
Source
883
28
                      MethodId* method_id) const {
884
28
        DCHECK(!this->uninitialized());
885
28
        DCHECK(method_id->uninitialized());
886
28
        method_id->_id = env->GetMethodID((jclass)this->_obj, method_str, method_signature);
887
28
        RETURN_ERROR_IF_EXC(env);
888
28
        return Status::OK();
889
28
    }
890
891
    Status get_static_fieldId(JNIEnv* env, const char* name, const char* signature,
892
42
                              FieldId* field_id) const {
893
42
        DCHECK(!this->uninitialized());
894
42
        DCHECK(field_id->uninitialized());
895
42
        field_id->_id = env->GetStaticFieldID((jclass)this->_obj, name, signature);
896
42
        RETURN_ERROR_IF_EXC(env);
897
42
        return Status::OK();
898
42
    }
899
900
    Status get_static_object_field(JNIEnv* env, const FieldId& field_id,
901
                                   Object<Local>* result) const {
902
        DCHECK(!this->uninitialized());
903
        DCHECK(!field_id.uninitialized());
904
        result->_obj = env->GetStaticObjectField((jclass)this->_obj, field_id._id);
905
        RETURN_ERROR_IF_EXC(env);
906
        return Status::OK();
907
    }
908
909
    Status get_static_object_field(JNIEnv* env, const FieldId& field_id,
910
42
                                   Object<Global>* global_result) const {
911
42
        DCHECK(!this->uninitialized());
912
42
        DCHECK(!field_id.uninitialized());
913
42
        Object<Local> local_result;
914
42
        local_result._obj = env->GetStaticObjectField((jclass)this->_obj, field_id._id);
915
42
        RETURN_ERROR_IF_EXC(env);
916
42
        return local_to_global_ref(env, local_result, global_result);
917
42
    }
918
919
    Status get_static_object_field(JNIEnv* env, const char* name, const char* signature,
920
42
                                   Object<Global>* global_result) const {
921
42
        Jni::FieldId tmpFieldID;
922
42
        RETURN_IF_ERROR(get_static_fieldId(env, name, signature, &tmpFieldID));
923
42
        RETURN_IF_ERROR(get_static_object_field(env, tmpFieldID, global_result));
924
42
        return Status::OK();
925
42
    }
926
927
10.5k
    FunctionCall<NewObject> new_object(JNIEnv* env, MethodId method_id) const {
928
10.5k
        DCHECK(!this->uninitialized());
929
10.5k
        DCHECK(!method_id.uninitialized());
930
10.5k
        return FunctionCall<NewObject>::instance(env, (jclass)this->_obj, method_id._id);
931
10.5k
    }
_ZNK5doris3Jni5ClassILNS0_7RefTypeE1EE10new_objectEP7JNIEnv_NS0_8MethodIdE
Line
Count
Source
927
10.5k
    FunctionCall<NewObject> new_object(JNIEnv* env, MethodId method_id) const {
928
10.5k
        DCHECK(!this->uninitialized());
929
        DCHECK(!method_id.uninitialized());
930
10.5k
        return FunctionCall<NewObject>::instance(env, (jclass)this->_obj, method_id._id);
931
10.5k
    }
_ZNK5doris3Jni5ClassILNS0_7RefTypeE0EE10new_objectEP7JNIEnv_NS0_8MethodIdE
Line
Count
Source
927
7
    FunctionCall<NewObject> new_object(JNIEnv* env, MethodId method_id) const {
928
7
        DCHECK(!this->uninitialized());
929
        DCHECK(!method_id.uninitialized());
930
7
        return FunctionCall<NewObject>::instance(env, (jclass)this->_obj, method_id._id);
931
7
    }
932
933
    FunctionCall<StaticObjectMethod> call_static_object_method(JNIEnv* env,
934
2.73k
                                                               MethodId method_id) const {
935
2.73k
        DCHECK(!this->uninitialized());
936
2.73k
        DCHECK(!method_id.uninitialized());
937
2.73k
        return FunctionCall<StaticObjectMethod>::instance(env, (jclass)this->_obj, method_id._id);
938
2.73k
    }
939
940
0
    FunctionCall<StaticVoidMethod> call_static_void_method(JNIEnv* env, MethodId method_id) const {
941
0
        DCHECK(!this->uninitialized());
942
0
        DCHECK(!method_id.uninitialized());
943
0
        return FunctionCall<StaticVoidMethod>::instance(env, (jclass)this->_obj, method_id._id);
944
0
    }
945
946
private:
947
    DISALLOW_COPY_AND_ASSIGN(Class);
948
};
949
950
using LocalClass = Class<Local>;
951
using GlobalClass = Class<Global>;
952
953
using LocalArray = Array<Local>;
954
using GlobalArray = Array<Global>;
955
956
using LocalString = String<Local>;
957
using GlobalString = String<Global>;
958
959
template <CallTag tag>
960
template <RefType Ref>
961
44.3k
FunctionCall<tag>& FunctionCall<tag>::with_arg(const Object<Ref>& obj) {
962
44.3k
    jvalue v;
963
44.3k
    std::memset(&v, 0, sizeof(v));
964
44.3k
    v.l = obj._obj;
965
44.3k
    _args.push_back(v);
966
44.3k
    return *this;
967
44.3k
}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE0EE8with_argILNS0_7RefTypeE0EEERS3_RKNS0_6ObjectIXT_EEE
Line
Count
Source
961
33.7k
FunctionCall<tag>& FunctionCall<tag>::with_arg(const Object<Ref>& obj) {
962
33.7k
    jvalue v;
963
33.7k
    std::memset(&v, 0, sizeof(v));
964
33.7k
    v.l = obj._obj;
965
33.7k
    _args.push_back(v);
966
33.7k
    return *this;
967
33.7k
}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE9EE8with_argILNS0_7RefTypeE0EEERS3_RKNS0_6ObjectIXT_EEE
Line
Count
Source
961
5.08k
FunctionCall<tag>& FunctionCall<tag>::with_arg(const Object<Ref>& obj) {
962
5.08k
    jvalue v;
963
5.08k
    std::memset(&v, 0, sizeof(v));
964
5.08k
    v.l = obj._obj;
965
5.08k
    _args.push_back(v);
966
5.08k
    return *this;
967
5.08k
}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE3EE8with_argILNS0_7RefTypeE0EEERS3_RKNS0_6ObjectIXT_EEE
Line
Count
Source
961
210
FunctionCall<tag>& FunctionCall<tag>::with_arg(const Object<Ref>& obj) {
962
210
    jvalue v;
963
210
    std::memset(&v, 0, sizeof(v));
964
210
    v.l = obj._obj;
965
210
    _args.push_back(v);
966
210
    return *this;
967
210
}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE2EE8with_argILNS0_7RefTypeE0EEERS3_RKNS0_6ObjectIXT_EEE
Line
Count
Source
961
5.28k
FunctionCall<tag>& FunctionCall<tag>::with_arg(const Object<Ref>& obj) {
962
5.28k
    jvalue v;
963
5.28k
    std::memset(&v, 0, sizeof(v));
964
5.28k
    v.l = obj._obj;
965
5.28k
    _args.push_back(v);
966
5.28k
    return *this;
967
5.28k
}
Unexecuted instantiation: _ZN5doris3Jni12FunctionCallILNS0_7CallTagE8EE8with_argILNS0_7RefTypeE0EEERS3_RKNS0_6ObjectIXT_EEE
968
969
template <CallTag tag>
970
template <RefType Ref>
971
41
NonvirtualFunctionCall<tag>& NonvirtualFunctionCall<tag>::with_arg(const Object<Ref>& obj) {
972
41
    jvalue v;
973
41
    std::memset(&v, 0, sizeof(v));
974
41
    v.l = obj._obj;
975
41
    this->_args.push_back(v);
976
41
    return *this;
977
41
}
978
979
template <CallTag tag>
980
96.1k
Status FunctionCall<tag>::call(Object<Local>* result) {
981
96.1k
    DCHECK(result->uninitialized());
982
96.1k
    result->_obj = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
983
96.1k
    RETURN_ERROR_IF_EXC(this->_env);
984
96.1k
    return Status::OK();
985
96.1k
}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE5EE4callEPNS0_6ObjectILNS0_7RefTypeE0EEE
Line
Count
Source
980
2.73k
Status FunctionCall<tag>::call(Object<Local>* result) {
981
2.73k
    DCHECK(result->uninitialized());
982
2.73k
    result->_obj = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
983
2.73k
    RETURN_ERROR_IF_EXC(this->_env);
984
2.73k
    return Status::OK();
985
2.73k
}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE0EE4callEPNS0_6ObjectILNS0_7RefTypeE0EEE
Line
Count
Source
980
87.9k
Status FunctionCall<tag>::call(Object<Local>* result) {
981
87.9k
    DCHECK(result->uninitialized());
982
87.9k
    result->_obj = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
983
87.9k
    RETURN_ERROR_IF_EXC(this->_env);
984
87.9k
    return Status::OK();
985
87.9k
}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE9EE4callEPNS0_6ObjectILNS0_7RefTypeE0EEE
Line
Count
Source
980
5.49k
Status FunctionCall<tag>::call(Object<Local>* result) {
981
5.49k
    DCHECK(result->uninitialized());
982
5.49k
    result->_obj = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
983
5.49k
    RETURN_ERROR_IF_EXC(this->_env);
984
5.49k
    return Status::OK();
985
5.49k
}
986
987
template <CallTag tag>
988
5.09k
Status FunctionCall<tag>::call(Object<Global>* result) {
989
5.09k
    DCHECK(result->uninitialized());
990
5.09k
    Object<Local> local_result;
991
5.09k
    local_result._obj = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
992
5.09k
    RETURN_ERROR_IF_EXC(this->_env);
993
5.09k
    return local_to_global_ref(_env, local_result, result);
994
5.09k
}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE9EE4callEPNS0_6ObjectILNS0_7RefTypeE1EEE
Line
Count
Source
988
5.09k
Status FunctionCall<tag>::call(Object<Global>* result) {
989
5.09k
    DCHECK(result->uninitialized());
990
5.09k
    Object<Local> local_result;
991
5.09k
    local_result._obj = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
992
5.09k
    RETURN_ERROR_IF_EXC(this->_env);
993
5.09k
    return local_to_global_ref(_env, local_result, result);
994
5.09k
}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE0EE4callEPNS0_6ObjectILNS0_7RefTypeE1EEE
Line
Count
Source
988
5
Status FunctionCall<tag>::call(Object<Global>* result) {
989
5
    DCHECK(result->uninitialized());
990
5
    Object<Local> local_result;
991
5
    local_result._obj = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
992
5
    RETURN_ERROR_IF_EXC(this->_env);
993
5
    return local_to_global_ref(_env, local_result, result);
994
5
}
995
996
template <CallTag tag>
997
39
Status NonvirtualFunctionCall<tag>::call(Object<Local>* result) {
998
39
    DCHECK(result->uninitialized());
999
39
    result->_obj = CallHelper<tag>::call_impl(this->_env, this->_base, _cls, this->_method,
1000
39
                                              this->_args.data());
1001
39
    RETURN_ERROR_IF_EXC(this->_env);
1002
39
    return Status::OK();
1003
39
}
1004
1005
template <RefType Ref>
1006
template <RefType R>
1007
NonvirtualFunctionCall<NonvirtualObjectMethod> Object<Ref>::call_nonvirtual_object_method(
1008
40
        JNIEnv* env, const Class<R>& clazz, MethodId method_id) const {
1009
40
    DCHECK(!this->uninitialized());
1010
40
    DCHECK(!method_id.uninitialized());
1011
1012
40
    return NonvirtualFunctionCall<NonvirtualObjectMethod>::instance(env, _obj, (jclass)clazz._obj,
1013
40
                                                                    method_id._id);
1014
40
}
1015
1016
template <RefType Ref>
1017
template <RefType R>
1018
NonvirtualFunctionCall<NonvirtualVoidMethod> Object<Ref>::call_nonvirtual_void_method(
1019
5.97k
        JNIEnv* env, const Class<R>& clazz, MethodId method_id) const {
1020
5.97k
    DCHECK(!this->uninitialized());
1021
5.97k
    DCHECK(!method_id.uninitialized());
1022
5.97k
    return NonvirtualFunctionCall<NonvirtualVoidMethod>::instance(env, _obj, (jclass)clazz._obj,
1023
5.97k
                                                                  method_id._id);
1024
5.97k
}
1025
1026
template <RefType Ref>
1027
template <RefType R>
1028
NonvirtualFunctionCall<NonvirtualIntMethod> Object<Ref>::call_nonvirtual_int_method(
1029
        JNIEnv* env, const Class<R>& clazz, MethodId method_id) const {
1030
    DCHECK(!this->uninitialized());
1031
    DCHECK(!method_id.uninitialized());
1032
    return NonvirtualFunctionCall<NonvirtualIntMethod>::instance(env, _obj, (jclass)clazz._obj,
1033
                                                                 method_id._id);
1034
}
1035
1036
template <RefType Ref>
1037
template <RefType R>
1038
NonvirtualFunctionCall<NonvirtualBooleanMethod> Object<Ref>::call_nonvirtual_boolean_method(
1039
        JNIEnv* env, const Class<R>& clazz, MethodId method_id) const {
1040
    DCHECK(!this->uninitialized());
1041
    DCHECK(!method_id.uninitialized());
1042
    return NonvirtualFunctionCall<NonvirtualBooleanMethod>::instance(env, _obj, (jclass)clazz._obj,
1043
                                                                     method_id._id);
1044
}
1045
1046
class Util {
1047
public:
1048
    static size_t get_max_jni_heap_memory_size();
1049
1050
    template <RefType Ref>
1051
5.26k
    static Status find_class(JNIEnv* env, const char* class_str, Class<Ref>* result) {
1052
5.26k
        return Class<Ref>::find_class(env, class_str, result);
1053
5.26k
    }
_ZN5doris3Jni4Util10find_classILNS0_7RefTypeE1EEENS_6StatusEP7JNIEnv_PKcPNS0_5ClassIXT_EEE
Line
Count
Source
1051
5.26k
    static Status find_class(JNIEnv* env, const char* class_str, Class<Ref>* result) {
1052
5.26k
        return Class<Ref>::find_class(env, class_str, result);
1053
5.26k
    }
_ZN5doris3Jni4Util10find_classILNS0_7RefTypeE0EEENS_6StatusEP7JNIEnv_PKcPNS0_5ClassIXT_EEE
Line
Count
Source
1051
7
    static Status find_class(JNIEnv* env, const char* class_str, Class<Ref>* result) {
1052
7
        return Class<Ref>::find_class(env, class_str, result);
1053
7
    }
1054
1055
    template <RefType Ref>
1056
    static Status WriteBufferToByteArray(JNIEnv* env, const jbyte* buffer, jint size,
1057
41
                                         Array<Ref>* serialized_msg) {
1058
41
        if constexpr (Ref == Local) {
1059
41
            return Array<Local>::WriteBufferToByteArray(env, buffer, size, serialized_msg);
1060
        } else if constexpr (Ref == Global) {
1061
            Array<Local> local_obj;
1062
            RETURN_IF_ERROR(Array<Local>::WriteBufferToByteArray(env, buffer, size, &local_obj));
1063
            return local_to_global_ref(env, local_obj, serialized_msg);
1064
        } else {
1065
            static_assert(false);
1066
        }
1067
41
    }
1068
1069
    template <class T, RefType Ref>
1070
5.06k
    static Status SerializeThriftMsg(JNIEnv* env, T* msg, Array<Ref>* serialized_msg) {
1071
5.06k
        if constexpr (Ref == Local) {
1072
5.06k
            return Array<Local>::SerializeThriftMsg(env, msg, serialized_msg);
1073
        } else if (Ref == Global) {
1074
            Array<Local> local_obj;
1075
            RETURN_IF_ERROR(Array<Local>::SerializeThriftMsg(env, msg, local_obj));
1076
            return local_to_global_ref(env, local_obj, serialized_msg);
1077
        } else {
1078
            static_assert(false);
1079
        }
1080
5.06k
    }
1081
1082
    template <RefType Ref>
1083
    static Status get_jni_scanner_class(JNIEnv* env, const char* classname,
1084
5
                                        Object<Ref>* jni_scanner_class) {
1085
        // Get JNI scanner class by class name;
1086
5
        LocalString class_name_str;
1087
5
        RETURN_IF_ERROR(LocalString::new_string(env, classname, &class_name_str));
1088
5
        return jni_scanner_loader_obj_.call_object_method(env, jni_scanner_loader_method_)
1089
5
                .with_arg(class_name_str)
1090
5
                .call(jni_scanner_class);
1091
5
    }
_ZN5doris3Jni4Util21get_jni_scanner_classILNS0_7RefTypeE1EEENS_6StatusEP7JNIEnv_PKcPNS0_6ObjectIXT_EEE
Line
Count
Source
1084
5
                                        Object<Ref>* jni_scanner_class) {
1085
        // Get JNI scanner class by class name;
1086
5
        LocalString class_name_str;
1087
5
        RETURN_IF_ERROR(LocalString::new_string(env, classname, &class_name_str));
1088
5
        return jni_scanner_loader_obj_.call_object_method(env, jni_scanner_loader_method_)
1089
5
                .with_arg(class_name_str)
1090
5
                .call(jni_scanner_class);
1091
5
    }
Unexecuted instantiation: _ZN5doris3Jni4Util21get_jni_scanner_classILNS0_7RefTypeE0EEENS_6StatusEP7JNIEnv_PKcPNS0_6ObjectIXT_EEE
1092
1093
    template <RefType Ref>
1094
    static Status convert_to_java_map(JNIEnv* env, const std::map<std::string, std::string>& map,
1095
5.49k
                                      Object<Ref>* hashmap_object) {
1096
5.49k
        RETURN_IF_ERROR(hashmap_class.new_object(env, hashmap_constructor)
1097
5.49k
                                .with_arg((jint)map.size())
1098
5.49k
                                .call(hashmap_object));
1099
1100
16.5k
        for (const auto& it : map) {
1101
16.5k
            LocalString key;
1102
16.5k
            RETURN_IF_ERROR(String<Local>::new_string(env, it.first.c_str(), &key));
1103
1104
16.5k
            LocalString value;
1105
16.5k
            RETURN_IF_ERROR(String<Local>::new_string(env, it.second.c_str(), &value));
1106
1107
16.5k
            LocalObject result;
1108
16.5k
            RETURN_IF_ERROR(hashmap_object->call_object_method(env, hashmap_put)
1109
16.5k
                                    .with_arg(key)
1110
16.5k
                                    .with_arg(value)
1111
16.5k
                                    .call());
1112
16.5k
        }
1113
5.49k
        return Status::OK();
1114
5.49k
    }
1115
1116
    template <RefType Ref>
1117
    static Status convert_to_cpp_map(JNIEnv* env, const Object<Ref>& map,
1118
2
                                     std::map<std::string, std::string>* resultMap) {
1119
2
        LocalObject entrySet;
1120
2
        RETURN_IF_ERROR(map.call_object_method(env, mapEntrySetMethod).call(&entrySet));
1121
1122
        // Call the iterator method on the set to iterate over the key-value pairs
1123
2
        LocalObject iteratorSet;
1124
2
        RETURN_IF_ERROR(entrySet.call_object_method(env, iteratorSetMethod).call(&iteratorSet));
1125
1126
6
        while (true) {
1127
6
            jboolean hasNext = false;
1128
6
            RETURN_IF_ERROR(
1129
6
                    iteratorSet.call_boolean_method(env, iteratorHasNextMethod).call(&hasNext));
1130
6
            if (!hasNext) {
1131
2
                break;
1132
2
            }
1133
1134
4
            LocalObject entry;
1135
4
            RETURN_IF_ERROR(iteratorSet.call_object_method(env, iteratorNextMethod).call(&entry));
1136
1137
4
            LocalString javaKey;
1138
4
            RETURN_IF_ERROR(entry.call_object_method(env, getEntryKeyMethod).call(&javaKey));
1139
1140
4
            LocalString javaValue;
1141
4
            RETURN_IF_ERROR(entry.call_object_method(env, getEntryValueMethod).call(&javaValue));
1142
1143
4
            LocalStringBufferGuard key;
1144
4
            RETURN_IF_ERROR(javaKey.get_string_chars(env, &key));
1145
1146
4
            LocalStringBufferGuard value;
1147
4
            RETURN_IF_ERROR(javaValue.get_string_chars(env, &value));
1148
1149
            // Store the key-value pair in the map
1150
4
            (*resultMap)[key.get()] = value.get();
1151
4
        }
1152
2
        return Status::OK();
1153
2
    }
1154
1155
    static Status clean_udf_class_load_cache(const std::string& function_signature);
1156
1157
    static Status Init();
1158
1159
private:
1160
    static void _parse_max_heap_memory_size_from_jvm();
1161
1162
    static Status _init_collect_class() WARN_UNUSED_RESULT;
1163
    static Status _init_register_natives() WARN_UNUSED_RESULT;
1164
    static Status _init_jni_scanner_loader() WARN_UNUSED_RESULT;
1165
1166
    static bool jvm_inited_;
1167
1168
    // for jvm heap
1169
    static jlong max_jvm_heap_memory_size_;
1170
1171
    // for JNI scanner loader
1172
    static GlobalObject jni_scanner_loader_obj_;
1173
    static MethodId jni_scanner_loader_method_;
1174
1175
    // for clean udf cache
1176
    static MethodId _clean_udf_cache_method_id;
1177
1178
    //for hashmap
1179
    static GlobalClass hashmap_class;
1180
    static MethodId hashmap_constructor;
1181
    static MethodId hashmap_put;
1182
1183
    //for map
1184
    static GlobalClass mapClass;
1185
    static MethodId mapEntrySetMethod;
1186
1187
    // for map entry
1188
    static GlobalClass mapEntryClass;
1189
    static MethodId getEntryKeyMethod;
1190
    static MethodId getEntryValueMethod;
1191
1192
    //for set
1193
    static GlobalClass setClass;
1194
    static MethodId iteratorSetMethod;
1195
1196
    // for iterator
1197
    static GlobalClass iteratorClass;
1198
    static MethodId iteratorHasNextMethod;
1199
    static MethodId iteratorNextMethod;
1200
};
1201
}; // namespace Jni
1202
1203
} // namespace doris