Coverage Report

Created: 2026-09-01 19:13

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
296k
    do {                                              \
42
296k
        if (env->ExceptionCheck()) [[unlikely]]       \
43
4
            return Jni::Env::GetJniExceptionMsg(env); \
44
296k
    } 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
239k
    static Status Get(JNIEnv** env) {
54
239k
        if (tls_env_) {
55
239k
            *env = tls_env_;
56
239k
        } else {
57
204
            Status status = GetJNIEnvSlowPath(env);
58
204
            if (!status.ok()) {
59
0
                return status;
60
0
            }
61
204
        }
62
239k
        if (*env == nullptr) [[unlikely]] {
63
0
            return Status::JniError("Failed to get JNIEnv: it is nullptr.");
64
0
        }
65
239k
        return Status::OK();
66
239k
    }
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.39k
    static jobject create(JNIEnv* env, jobject obj) { return env->NewLocalRef(obj); }
141
142
204k
    static void destroy(JNIEnv* env, jobject obj) { env->DeleteLocalRef(obj); }
143
144
210k
    static Status get_env(JNIEnv** env) {
145
        // Get the JNIEnv* corresponding to current thread.
146
210k
        return Jni::Env::Get(env);
147
210k
    }
148
};
149
150
template <>
151
struct RefHelper<Global> {
152
11.3k
    static jobject create(JNIEnv* env, jobject obj) { return env->NewGlobalRef(obj); }
153
154
11.2k
    static void destroy(JNIEnv* env, jobject obj) { env->DeleteGlobalRef(obj); }
155
156
11.2k
    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
19.5k
    MethodId() = default;
168
164k
    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
98.8k
    static jobject call_impl(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) {
221
98.8k
        return env->CallObjectMethodA(obj, methodID, args);
222
98.8k
    }
223
    using BASE_TYPE = jobject;
224
    using RETURN_TYPE = jobject;
225
};
226
227
template <>
228
struct CallHelper<IntMethod> {
229
1.91k
    static jint call_impl(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) {
230
1.91k
        return env->CallIntMethodA(obj, methodID, args);
231
1.91k
    }
232
    using BASE_TYPE = jobject;
233
    using RETURN_TYPE = jint;
234
};
235
236
template <>
237
struct CallHelper<LongMethod> {
238
23.8k
    static jlong call_impl(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) {
239
23.8k
        return env->CallLongMethodA(obj, methodID, args);
240
23.8k
    }
241
    using BASE_TYPE = jobject;
242
    using RETURN_TYPE = jlong;
243
};
244
245
template <>
246
struct CallHelper<VoidMethod> {
247
1.16k
    static void call_impl(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) {
248
1.16k
        env->CallVoidMethodA(obj, methodID, args);
249
1.16k
    }
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.55k
    static jobject call_impl(JNIEnv* env, jclass cls, jmethodID methodID, const jvalue* args) {
266
2.55k
        return env->CallStaticObjectMethodA(cls, methodID, args);
267
2.55k
    }
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
11.0k
    static jobject call_impl(JNIEnv* env, jclass cls, jmethodID methodID, const jvalue* args) {
303
11.0k
        return env->NewObjectA(cls, methodID, args);
304
11.0k
    }
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
6.48k
                          const jvalue* args) {
314
6.48k
        return env->CallNonvirtualVoidMethodA(obj, clazz, methodID, args);
315
6.48k
    }
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
58
                             const jvalue* args) {
325
58
        return env->CallNonvirtualObjectMethodA(obj, clazz, methodID, args);
326
58
    }
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
139k
                                 jmethodID method_id) {
361
139k
        return FunctionCall(env, base, method_id);
362
139k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE5EE8instanceEP7JNIEnv_P7_jclassP10_jmethodID
Line
Count
Source
360
2.55k
                                 jmethodID method_id) {
361
2.55k
        return FunctionCall(env, base, method_id);
362
2.55k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE0EE8instanceEP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
360
98.8k
                                 jmethodID method_id) {
361
98.8k
        return FunctionCall(env, base, method_id);
362
98.8k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE2EE8instanceEP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
360
23.8k
                                 jmethodID method_id) {
361
23.8k
        return FunctionCall(env, base, method_id);
362
23.8k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE1EE8instanceEP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
360
1.91k
                                 jmethodID method_id) {
361
1.91k
        return FunctionCall(env, base, method_id);
362
1.91k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE9EE8instanceEP7JNIEnv_P7_jclassP10_jmethodID
Line
Count
Source
360
11.0k
                                 jmethodID method_id) {
361
11.0k
        return FunctionCall(env, base, method_id);
362
11.0k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE3EE8instanceEP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
360
1.16k
                                 jmethodID method_id) {
361
1.16k
        return FunctionCall(env, base, method_id);
362
1.16k
    }
_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.7k
    FunctionCall& with_arg(T arg) {
372
14.7k
        jvalue v;
373
14.7k
        std::memset(&v, 0, sizeof(v));
374
14.7k
        if constexpr (std::is_same_v<T, jboolean>) {
375
211
            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.1k
        } else if constexpr (std::is_same_v<T, jint>) {
383
13.1k
            v.i = arg;
384
13.1k
        } else if constexpr (std::is_same_v<T, jlong>) {
385
1.32k
            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.7k
        _args.push_back(v);
394
14.7k
        return *this;
395
14.7k
    }
_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.02k
    FunctionCall& with_arg(T arg) {
372
7.02k
        jvalue v;
373
7.02k
        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.02k
        } else if constexpr (std::is_same_v<T, jint>) {
383
7.02k
            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.02k
        _args.push_back(v);
394
7.02k
        return *this;
395
7.02k
    }
_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.50k
    FunctionCall& with_arg(T arg) {
372
5.50k
        jvalue v;
373
5.50k
        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.50k
        } else if constexpr (std::is_same_v<T, jint>) {
383
5.50k
            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.50k
        _args.push_back(v);
394
5.50k
        return *this;
395
5.50k
    }
_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
211
    FunctionCall& with_arg(T arg) {
372
211
        jvalue v;
373
211
        std::memset(&v, 0, sizeof(v));
374
211
        if constexpr (std::is_same_v<T, jboolean>) {
375
211
            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
211
        _args.push_back(v);
394
211
        return *this;
395
211
    }
_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
1.13k
    FunctionCall& with_arg(T arg) {
372
1.13k
        jvalue v;
373
1.13k
        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
1.13k
        } else if constexpr (std::is_same_v<T, jlong>) {
385
1.13k
            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
1.13k
        _args.push_back(v);
394
1.13k
        return *this;
395
1.13k
    }
_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
25.7k
    Status call(ReturnType* result) {
403
25.7k
        *result = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
404
25.7k
        RETURN_ERROR_IF_EXC(_env);
405
25.7k
        return Status::OK();
406
25.7k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE2EE4callIlQsr3stdE9is_same_vINS0_10CallHelperIXT_EE11RETURN_TYPEETL0__EEENS_6StatusEPT_
Line
Count
Source
402
23.8k
    Status call(ReturnType* result) {
403
23.8k
        *result = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
404
23.8k
        RETURN_ERROR_IF_EXC(_env);
405
23.8k
        return Status::OK();
406
23.8k
    }
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE1EE4callIiQsr3stdE9is_same_vINS0_10CallHelperIXT_EE11RETURN_TYPEETL0__EEENS_6StatusEPT_
Line
Count
Source
402
1.91k
    Status call(ReturnType* result) {
403
1.91k
        *result = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
404
1.91k
        RETURN_ERROR_IF_EXC(_env);
405
1.91k
        return Status::OK();
406
1.91k
    }
_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
17.7k
    Status call() {
413
17.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
1.16k
                              std::is_same<return_type, void>>) {
420
1.16k
            CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
421
1.16k
            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
17.7k
        return Status::OK();
430
17.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
1.16k
    Status call() {
413
1.16k
        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
1.16k
                              std::is_same<return_type, void>>) {
420
1.16k
            CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
421
1.16k
            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
1.16k
        return Status::OK();
430
1.16k
    }
Unexecuted instantiation: _ZN5doris3Jni12FunctionCallILNS0_7CallTagE8EE4callEv
431
432
protected:
433
    explicit FunctionCall(JNIEnv* env, typename CallHelper<tag>::BASE_TYPE base,
434
                          jmethodID method_id)
435
145k
            : _env(env), _base(base), _method(method_id) {}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE5EEC2EP7JNIEnv_P7_jclassP10_jmethodID
Line
Count
Source
435
2.55k
            : _env(env), _base(base), _method(method_id) {}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE0EEC2EP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
435
98.8k
            : _env(env), _base(base), _method(method_id) {}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE2EEC2EP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
435
23.8k
            : _env(env), _base(base), _method(method_id) {}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE1EEC2EP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
435
1.91k
            : _env(env), _base(base), _method(method_id) {}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE9EEC2EP7JNIEnv_P7_jclassP10_jmethodID
Line
Count
Source
435
11.0k
            : _env(env), _base(base), _method(method_id) {}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE10EEC2EP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
435
6.48k
            : _env(env), _base(base), _method(method_id) {}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE3EEC2EP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
435
1.16k
            : _env(env), _base(base), _method(method_id) {}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE11EEC2EP7JNIEnv_P8_jobjectP10_jmethodID
Line
Count
Source
435
58
            : _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.54k
                                           jclass cls, jmethodID method_id) {
452
6.54k
        return NonvirtualFunctionCall(env, base, cls, method_id);
453
6.54k
    }
_ZN5doris3Jni22NonvirtualFunctionCallILNS0_7CallTagE10EE8instanceEP7JNIEnv_P8_jobjectP7_jclassP10_jmethodID
Line
Count
Source
451
6.48k
                                           jclass cls, jmethodID method_id) {
452
6.48k
        return NonvirtualFunctionCall(env, base, cls, method_id);
453
6.48k
    }
_ZN5doris3Jni22NonvirtualFunctionCallILNS0_7CallTagE11EE8instanceEP7JNIEnv_P8_jobjectP7_jclassP10_jmethodID
Line
Count
Source
451
58
                                           jclass cls, jmethodID method_id) {
452
58
        return NonvirtualFunctionCall(env, base, cls, method_id);
453
58
    }
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
151
    NonvirtualFunctionCall& with_arg(T arg) {
462
151
        jvalue v;
463
151
        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
151
        } else if constexpr (std::is_same_v<T, jlong>) {
475
151
            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
151
        this->_args.push_back(v);
484
151
        return *this;
485
151
    }
_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
94
    NonvirtualFunctionCall& with_arg(T arg) {
462
94
        jvalue v;
463
94
        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
94
        } else if constexpr (std::is_same_v<T, jlong>) {
475
94
            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
94
        this->_args.push_back(v);
484
94
        return *this;
485
94
    }
_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
57
    NonvirtualFunctionCall& with_arg(T arg) {
462
57
        jvalue v;
463
57
        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
57
        } else if constexpr (std::is_same_v<T, jlong>) {
475
57
            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
57
        this->_args.push_back(v);
484
57
        return *this;
485
57
    }
486
487
    template <RefType Ref>
488
    NonvirtualFunctionCall& with_arg(const Object<Ref>& obj) WARN_UNUSED_RESULT;
489
490
    // no override
491
6.48k
    Status call() {
492
6.48k
        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
6.48k
                              std::is_same<return_type, void>>) {
499
6.48k
            CallHelper<tag>::call_impl(this->_env, this->_base, _cls, this->_method,
500
6.48k
                                       this->_args.data());
501
6.48k
            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
6.48k
        return Status::OK();
511
6.48k
    }
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.54k
            : FunctionCall<tag>(env, base, method_id), _cls(cls) {}
_ZN5doris3Jni22NonvirtualFunctionCallILNS0_7CallTagE10EEC2EP7JNIEnv_P8_jobjectP7_jclassP10_jmethodID
Line
Count
Source
527
6.49k
            : FunctionCall<tag>(env, base, method_id), _cls(cls) {}
_ZN5doris3Jni22NonvirtualFunctionCallILNS0_7CallTagE11EEC2EP7JNIEnv_P8_jobjectP7_jclassP10_jmethodID
Line
Count
Source
527
58
            : 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
232k
    Object() = default;
_ZN5doris3Jni6ObjectILNS0_7RefTypeE1EEC2Ev
Line
Count
Source
563
11.4k
    Object() = default;
_ZN5doris3Jni6ObjectILNS0_7RefTypeE0EEC2Ev
Line
Count
Source
563
221k
    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
232k
    virtual ~Object() {
587
232k
        if (_obj != nullptr) [[likely]] {
588
215k
            JNIEnv* env = nullptr;
589
215k
            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
215k
            RefHelper<Ref>::destroy(env, _obj);
594
215k
        }
595
232k
    }
_ZN5doris3Jni6ObjectILNS0_7RefTypeE0EED2Ev
Line
Count
Source
586
220k
    virtual ~Object() {
587
220k
        if (_obj != nullptr) [[likely]] {
588
204k
            JNIEnv* env = nullptr;
589
204k
            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
204k
            RefHelper<Ref>::destroy(env, _obj);
594
204k
        }
595
220k
    }
_ZN5doris3Jni6ObjectILNS0_7RefTypeE1EED2Ev
Line
Count
Source
586
11.4k
    virtual ~Object() {
587
11.4k
        if (_obj != nullptr) [[likely]] {
588
11.2k
            JNIEnv* env = nullptr;
589
11.2k
            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
11.2k
            RefHelper<Ref>::destroy(env, _obj);
594
11.2k
        }
595
11.4k
    }
596
597
    template <RefType R>
598
17.6k
    static Status create(JNIEnv* env, const Object<R>& other, Object<Ref>* result) {
599
17.6k
        DCHECK(!other.uninitialized());
600
17.6k
        DCHECK(result->uninitialized());
601
602
17.6k
        result->_obj = RefHelper<Ref>::create(env, other._obj);
603
17.6k
        RETURN_ERROR_IF_EXC(env);
604
17.6k
        return Status::OK();
605
17.6k
    }
_ZN5doris3Jni6ObjectILNS0_7RefTypeE1EE6createILS2_0EEENS_6StatusEP7JNIEnv_RKNS1_IXT_EEEPS3_
Line
Count
Source
598
11.2k
    static Status create(JNIEnv* env, const Object<R>& other, Object<Ref>* result) {
599
11.2k
        DCHECK(!other.uninitialized());
600
11.2k
        DCHECK(result->uninitialized());
601
602
11.2k
        result->_obj = RefHelper<Ref>::create(env, other._obj);
603
11.2k
        RETURN_ERROR_IF_EXC(env);
604
11.2k
        return Status::OK();
605
11.2k
    }
_ZN5doris3Jni6ObjectILNS0_7RefTypeE0EE6createILS2_0EEENS_6StatusEP7JNIEnv_RKNS1_IXT_EEEPS3_
Line
Count
Source
598
6.39k
    static Status create(JNIEnv* env, const Object<R>& other, Object<Ref>* result) {
599
6.39k
        DCHECK(!other.uninitialized());
600
6.39k
        DCHECK(result->uninitialized());
601
602
6.39k
        result->_obj = RefHelper<Ref>::create(env, other._obj);
603
6.39k
        RETURN_ERROR_IF_EXC(env);
604
6.39k
        return Status::OK();
605
6.39k
    }
606
607
762k
    bool uninitialized() const { return _obj == nullptr; }
_ZNK5doris3Jni6ObjectILNS0_7RefTypeE0EE13uninitializedEv
Line
Count
Source
607
578k
    bool uninitialized() const { return _obj == nullptr; }
_ZNK5doris3Jni6ObjectILNS0_7RefTypeE1EE13uninitializedEv
Line
Count
Source
607
184k
    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
119k
    bool equal(JNIEnv* env, const Object<T>& other) {
619
119k
        DCHECK(!uninitialized());
620
119k
        DCHECK(!other.uninitialized());
621
119k
        return env->IsSameObject(this->_obj, other._obj); //assume not throw exception.
622
119k
    }
623
624
98.7k
    FunctionCall<ObjectMethod> call_object_method(JNIEnv* env, MethodId method_id) const {
625
98.7k
        DCHECK(!this->uninitialized());
626
98.7k
        DCHECK(!method_id.uninitialized());
627
98.7k
        return FunctionCall<ObjectMethod>::instance(env, _obj, method_id._id);
628
98.7k
    }
_ZNK5doris3Jni6ObjectILNS0_7RefTypeE0EE18call_object_methodEP7JNIEnv_NS0_8MethodIdE
Line
Count
Source
624
98.7k
    FunctionCall<ObjectMethod> call_object_method(JNIEnv* env, MethodId method_id) const {
625
98.7k
        DCHECK(!this->uninitialized());
626
        DCHECK(!method_id.uninitialized());
627
98.7k
        return FunctionCall<ObjectMethod>::instance(env, _obj, method_id._id);
628
98.7k
    }
_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
1.91k
    FunctionCall<IntMethod> call_int_method(JNIEnv* env, MethodId method_id) const {
631
1.91k
        DCHECK(!this->uninitialized());
632
1.91k
        DCHECK(!method_id.uninitialized());
633
1.91k
        return FunctionCall<IntMethod>::instance(env, _obj, method_id._id);
634
1.91k
    }
635
636
23.8k
    FunctionCall<LongMethod> call_long_method(JNIEnv* env, MethodId method_id) const {
637
23.8k
        DCHECK(!this->uninitialized());
638
23.8k
        DCHECK(!method_id.uninitialized());
639
23.8k
        return FunctionCall<LongMethod>::instance(env, _obj, method_id._id);
640
23.8k
    }
_ZNK5doris3Jni6ObjectILNS0_7RefTypeE0EE16call_long_methodEP7JNIEnv_NS0_8MethodIdE
Line
Count
Source
636
21.0k
    FunctionCall<LongMethod> call_long_method(JNIEnv* env, MethodId method_id) const {
637
21.0k
        DCHECK(!this->uninitialized());
638
        DCHECK(!method_id.uninitialized());
639
21.0k
        return FunctionCall<LongMethod>::instance(env, _obj, method_id._id);
640
21.0k
    }
_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
1.16k
    FunctionCall<VoidMethod> call_void_method(JNIEnv* env, MethodId method_id) const {
643
1.16k
        DCHECK(!this->uninitialized());
644
1.16k
        DCHECK(!method_id.uninitialized());
645
1.16k
        return FunctionCall<VoidMethod>::instance(env, _obj, method_id._id);
646
1.16k
    }
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
11.3k
                                         GlobalObject* global_ref) {
680
11.3k
    return Object<Global>::create(env, local_ref, global_ref);
681
11.3k
}
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.75k
                                         GlobalObject* global_ref) {
680
5.75k
    return Object<Global>::create(env, local_ref, global_ref);
681
5.75k
}
Unexecuted instantiation: unity_2_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_3_cxx.cxx:_ZN5doris3JniL19local_to_global_refEP7JNIEnv_RKNS0_6ObjectILNS0_7RefTypeE0EEEPNS3_ILS4_1EEE
Unexecuted instantiation: unity_5_cxx.cxx:_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: unity_13_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_7_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: 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.60k
                                         GlobalObject* global_ref) {
680
5.60k
    return Object<Global>::create(env, local_ref, global_ref);
681
5.60k
}
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_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_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_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: 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: 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: unity_23_cxx.cxx:_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.39k
    BufferGuard() = default;
688
689
    template <RefType R>
690
    static Status create(JNIEnv* env, const Object<R>& object,
691
6.39k
                         BufferGuard<bufferfType, Ref>* result, jboolean* isCopy) {
692
6.39k
        DCHECK(result->_buffer == nullptr && result->_object.uninitialized());
693
694
6.39k
        RETURN_IF_ERROR(Object<Ref>::create(env, object, &result->_object));
695
696
6.39k
        if constexpr (bufferfType == BufferType::Chars) {
697
6.39k
            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.39k
        RETURN_ERROR_IF_EXC(env);
706
6.39k
        if (result->_buffer == nullptr) [[unlikely]] {
707
0
            return Status::JniError("GetStringUTFChars/GetByteArrayElements fail.");
708
0
        }
709
710
6.39k
        return Status::OK();
711
6.39k
    }
712
713
6.39k
    ~BufferGuard() {
714
6.39k
        if (_object.uninitialized() || _buffer == nullptr) [[unlikely]] {
715
0
            return;
716
0
        }
717
6.39k
        JNIEnv* env = nullptr;
718
719
6.39k
        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.39k
        if constexpr (bufferfType == BufferType::Chars) {
725
6.39k
            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.39k
    }
730
731
12.7k
    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
40.4k
    String() = default;
754
755
34.0k
    static Status new_string(JNIEnv* env, const char* utf_chars, String<Ref>* result) {
756
34.0k
        DCHECK(result->uninitialized());
757
758
34.0k
        if constexpr (Ref == Local) {
759
34.0k
            result->_obj = env->NewStringUTF(utf_chars);
760
34.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
34.0k
        return Status::OK();
770
34.0k
    }
771
772
6.39k
    Status get_string_chars(JNIEnv* env, StringBufferGuard<Ref>* jni_chars) const {
773
6.39k
        return StringBufferGuard<Ref>::create(env, *this, jni_chars, nullptr);
774
6.39k
    }
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.94k
    Array() = default;
784
785
696
    Status get_length(JNIEnv* env, jsize* result) const {
786
696
        DCHECK(!this->uninitialized());
787
788
696
        *result = env->GetArrayLength((jarray)this->_obj);
789
696
        RETURN_ERROR_IF_EXC(env);
790
696
        return Status::OK();
791
696
    }
792
793
56.6k
    Status get_object_array_element(JNIEnv* env, jsize index, Jni::LocalObject* result) {
794
56.6k
        DCHECK(!this->uninitialized());
795
56.6k
        DCHECK(result->uninitialized());
796
56.6k
        result->_obj = env->GetObjectArrayElement((jobjectArray)this->_obj, index);
797
56.6k
        RETURN_ERROR_IF_EXC(env);
798
56.6k
        return Status::OK();
799
56.6k
    }
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
58
    Status get_byte_elements(JNIEnv* env, jsize start, jsize len, jbyte* buffer) {
807
58
        DCHECK(!this->uninitialized());
808
58
        env->GetByteArrayRegion((jbyteArray)this->_obj, start, len, buffer);
809
58
        RETURN_ERROR_IF_EXC(env);
810
58
        return Status::OK();
811
58
    }
812
813
    static Status WriteBufferToByteArray(JNIEnv* env, const jbyte* buffer, jint size,
814
5.59k
                                         Array<Local>* serialized_msg) {
815
5.59k
        DCHECK(serialized_msg->uninitialized());
816
        /// create jbyteArray given buffer
817
5.59k
        serialized_msg->_obj = env->NewByteArray(size);
818
5.59k
        RETURN_ERROR_IF_EXC(env);
819
5.59k
        if (serialized_msg->_obj == nullptr) [[unlikely]] {
820
0
            return Status::JniError("couldn't construct jbyteArray");
821
0
        }
822
5.59k
        env->SetByteArrayRegion((jbyteArray)serialized_msg->_obj, 0, size, buffer);
823
5.59k
        RETURN_ERROR_IF_EXC(env);
824
5.59k
        return Status::OK();
825
5.59k
    }
826
827
    template <class T>
828
5.52k
    static Status SerializeThriftMsg(JNIEnv* env, T* msg, Array<Local>* serialized_msg) {
829
5.52k
        int buffer_size = 100 * 1024; // start out with 100KB
830
5.52k
        ThriftSerializer serializer(false, buffer_size);
831
832
5.52k
        uint8_t* buffer = nullptr;
833
5.52k
        uint32_t size = 0;
834
5.52k
        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.52k
        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.52k
        RETURN_IF_ERROR(WriteBufferToByteArray(env, (jbyte*)buffer, size, serialized_msg));
845
5.52k
        return Status::OK();
846
5.52k
    }
847
848
private:
849
    DISALLOW_COPY_AND_ASSIGN(Array);
850
};
851
852
template <RefType Ref>
853
class Class : public Object<Ref> {
854
public:
855
11.4k
    Class() = default;
_ZN5doris3Jni5ClassILNS0_7RefTypeE1EEC2Ev
Line
Count
Source
855
5.75k
    Class() = default;
_ZN5doris3Jni5ClassILNS0_7RefTypeE0EEC2Ev
Line
Count
Source
855
5.71k
    Class() = default;
856
857
5.70k
    static Status find_class(JNIEnv* env, const char* class_str, Class<Ref>* result) {
858
5.70k
        DCHECK(result->uninitialized());
859
5.70k
        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.69k
        } else if constexpr (Ref == Global) {
864
5.69k
            Class<Local> local_class;
865
5.69k
            local_class._obj = env->FindClass(class_str);
866
5.69k
            RETURN_ERROR_IF_EXC(env);
867
5.69k
            return local_to_global_ref(env, local_class, result);
868
        } else {
869
            static_assert(false);
870
        }
871
5.70k
    }
_ZN5doris3Jni5ClassILNS0_7RefTypeE1EE10find_classEP7JNIEnv_PKcPS3_
Line
Count
Source
857
5.69k
    static Status find_class(JNIEnv* env, const char* class_str, Class<Ref>* result) {
858
5.69k
        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.69k
        } else if constexpr (Ref == Global) {
864
5.69k
            Class<Local> local_class;
865
5.69k
            local_class._obj = env->FindClass(class_str);
866
5.69k
            RETURN_ERROR_IF_EXC(env);
867
5.69k
            return local_to_global_ref(env, local_class, result);
868
        } else {
869
            static_assert(false);
870
        }
871
5.69k
    }
_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
18.3k
                      MethodId* method_id) const {
884
18.3k
        DCHECK(!this->uninitialized());
885
18.3k
        DCHECK(method_id->uninitialized());
886
18.3k
        method_id->_id = env->GetMethodID((jclass)this->_obj, method_str, method_signature);
887
18.3k
        RETURN_ERROR_IF_EXC(env);
888
18.3k
        return Status::OK();
889
18.3k
    }
_ZNK5doris3Jni5ClassILNS0_7RefTypeE1EE10get_methodEP7JNIEnv_PKcS7_PNS0_8MethodIdE
Line
Count
Source
883
18.3k
                      MethodId* method_id) const {
884
18.3k
        DCHECK(!this->uninitialized());
885
18.3k
        DCHECK(method_id->uninitialized());
886
18.3k
        method_id->_id = env->GetMethodID((jclass)this->_obj, method_str, method_signature);
887
18.3k
        RETURN_ERROR_IF_EXC(env);
888
18.3k
        return Status::OK();
889
18.3k
    }
_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
11.0k
    FunctionCall<NewObject> new_object(JNIEnv* env, MethodId method_id) const {
928
11.0k
        DCHECK(!this->uninitialized());
929
11.0k
        DCHECK(!method_id.uninitialized());
930
11.0k
        return FunctionCall<NewObject>::instance(env, (jclass)this->_obj, method_id._id);
931
11.0k
    }
_ZNK5doris3Jni5ClassILNS0_7RefTypeE1EE10new_objectEP7JNIEnv_NS0_8MethodIdE
Line
Count
Source
927
11.0k
    FunctionCall<NewObject> new_object(JNIEnv* env, MethodId method_id) const {
928
11.0k
        DCHECK(!this->uninitialized());
929
        DCHECK(!method_id.uninitialized());
930
11.0k
        return FunctionCall<NewObject>::instance(env, (jclass)this->_obj, method_id._id);
931
11.0k
    }
_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.55k
                                                               MethodId method_id) const {
935
2.55k
        DCHECK(!this->uninitialized());
936
2.55k
        DCHECK(!method_id.uninitialized());
937
2.55k
        return FunctionCall<StaticObjectMethod>::instance(env, (jclass)this->_obj, method_id._id);
938
2.55k
    }
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
45.7k
FunctionCall<tag>& FunctionCall<tag>::with_arg(const Object<Ref>& obj) {
962
45.7k
    jvalue v;
963
45.7k
    std::memset(&v, 0, sizeof(v));
964
45.7k
    v.l = obj._obj;
965
45.7k
    _args.push_back(v);
966
45.7k
    return *this;
967
45.7k
}
_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.53k
FunctionCall<tag>& FunctionCall<tag>::with_arg(const Object<Ref>& obj) {
962
5.53k
    jvalue v;
963
5.53k
    std::memset(&v, 0, sizeof(v));
964
5.53k
    v.l = obj._obj;
965
5.53k
    _args.push_back(v);
966
5.53k
    return *this;
967
5.53k
}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE3EE8with_argILNS0_7RefTypeE0EEERS3_RKNS0_6ObjectIXT_EEE
Line
Count
Source
961
1.13k
FunctionCall<tag>& FunctionCall<tag>::with_arg(const Object<Ref>& obj) {
962
1.13k
    jvalue v;
963
1.13k
    std::memset(&v, 0, sizeof(v));
964
1.13k
    v.l = obj._obj;
965
1.13k
    _args.push_back(v);
966
1.13k
    return *this;
967
1.13k
}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE2EE8with_argILNS0_7RefTypeE0EEERS3_RKNS0_6ObjectIXT_EEE
Line
Count
Source
961
5.29k
FunctionCall<tag>& FunctionCall<tag>::with_arg(const Object<Ref>& obj) {
962
5.29k
    jvalue v;
963
5.29k
    std::memset(&v, 0, sizeof(v));
964
5.29k
    v.l = obj._obj;
965
5.29k
    _args.push_back(v);
966
5.29k
    return *this;
967
5.29k
}
Unexecuted instantiation: _ZN5doris3Jni12FunctionCallILNS0_7CallTagE8EE8with_argILNS0_7RefTypeE0EEERS3_RKNS0_6ObjectIXT_EEE
968
969
template <CallTag tag>
970
template <RefType Ref>
971
58
NonvirtualFunctionCall<tag>& NonvirtualFunctionCall<tag>::with_arg(const Object<Ref>& obj) {
972
58
    jvalue v;
973
58
    std::memset(&v, 0, sizeof(v));
974
58
    v.l = obj._obj;
975
58
    this->_args.push_back(v);
976
58
    return *this;
977
58
}
978
979
template <CallTag tag>
980
90.3k
Status FunctionCall<tag>::call(Object<Local>* result) {
981
90.3k
    DCHECK(result->uninitialized());
982
90.3k
    result->_obj = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
983
90.3k
    RETURN_ERROR_IF_EXC(this->_env);
984
90.3k
    return Status::OK();
985
90.3k
}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE5EE4callEPNS0_6ObjectILNS0_7RefTypeE0EEE
Line
Count
Source
980
2.55k
Status FunctionCall<tag>::call(Object<Local>* result) {
981
2.55k
    DCHECK(result->uninitialized());
982
2.55k
    result->_obj = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
983
2.55k
    RETURN_ERROR_IF_EXC(this->_env);
984
2.55k
    return Status::OK();
985
2.55k
}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE0EE4callEPNS0_6ObjectILNS0_7RefTypeE0EEE
Line
Count
Source
980
82.2k
Status FunctionCall<tag>::call(Object<Local>* result) {
981
82.2k
    DCHECK(result->uninitialized());
982
82.2k
    result->_obj = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
983
82.2k
    RETURN_ERROR_IF_EXC(this->_env);
984
82.2k
    return Status::OK();
985
82.2k
}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE9EE4callEPNS0_6ObjectILNS0_7RefTypeE0EEE
Line
Count
Source
980
5.50k
Status FunctionCall<tag>::call(Object<Local>* result) {
981
5.50k
    DCHECK(result->uninitialized());
982
5.50k
    result->_obj = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
983
5.50k
    RETURN_ERROR_IF_EXC(this->_env);
984
5.50k
    return Status::OK();
985
5.50k
}
986
987
template <CallTag tag>
988
5.53k
Status FunctionCall<tag>::call(Object<Global>* result) {
989
5.53k
    DCHECK(result->uninitialized());
990
5.53k
    Object<Local> local_result;
991
5.53k
    local_result._obj = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
992
5.53k
    RETURN_ERROR_IF_EXC(this->_env);
993
5.53k
    return local_to_global_ref(_env, local_result, result);
994
5.53k
}
_ZN5doris3Jni12FunctionCallILNS0_7CallTagE9EE4callEPNS0_6ObjectILNS0_7RefTypeE1EEE
Line
Count
Source
988
5.53k
Status FunctionCall<tag>::call(Object<Global>* result) {
989
5.53k
    DCHECK(result->uninitialized());
990
5.53k
    Object<Local> local_result;
991
5.53k
    local_result._obj = CallHelper<tag>::call_impl(_env, _base, _method, _args.data());
992
5.53k
    RETURN_ERROR_IF_EXC(this->_env);
993
5.53k
    return local_to_global_ref(_env, local_result, result);
994
5.53k
}
_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
58
Status NonvirtualFunctionCall<tag>::call(Object<Local>* result) {
998
58
    DCHECK(result->uninitialized());
999
58
    result->_obj = CallHelper<tag>::call_impl(this->_env, this->_base, _cls, this->_method,
1000
58
                                              this->_args.data());
1001
58
    RETURN_ERROR_IF_EXC(this->_env);
1002
58
    return Status::OK();
1003
58
}
1004
1005
template <RefType Ref>
1006
template <RefType R>
1007
NonvirtualFunctionCall<NonvirtualObjectMethod> Object<Ref>::call_nonvirtual_object_method(
1008
58
        JNIEnv* env, const Class<R>& clazz, MethodId method_id) const {
1009
58
    DCHECK(!this->uninitialized());
1010
58
    DCHECK(!method_id.uninitialized());
1011
1012
58
    return NonvirtualFunctionCall<NonvirtualObjectMethod>::instance(env, _obj, (jclass)clazz._obj,
1013
58
                                                                    method_id._id);
1014
58
}
1015
1016
template <RefType Ref>
1017
template <RefType R>
1018
NonvirtualFunctionCall<NonvirtualVoidMethod> Object<Ref>::call_nonvirtual_void_method(
1019
6.48k
        JNIEnv* env, const Class<R>& clazz, MethodId method_id) const {
1020
6.48k
    DCHECK(!this->uninitialized());
1021
6.48k
    DCHECK(!method_id.uninitialized());
1022
6.48k
    return NonvirtualFunctionCall<NonvirtualVoidMethod>::instance(env, _obj, (jclass)clazz._obj,
1023
6.48k
                                                                  method_id._id);
1024
6.48k
}
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.72k
    static Status find_class(JNIEnv* env, const char* class_str, Class<Ref>* result) {
1052
5.72k
        return Class<Ref>::find_class(env, class_str, result);
1053
5.72k
    }
_ZN5doris3Jni4Util10find_classILNS0_7RefTypeE1EEENS_6StatusEP7JNIEnv_PKcPNS0_5ClassIXT_EEE
Line
Count
Source
1051
5.71k
    static Status find_class(JNIEnv* env, const char* class_str, Class<Ref>* result) {
1052
5.71k
        return Class<Ref>::find_class(env, class_str, result);
1053
5.71k
    }
_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
58
                                         Array<Ref>* serialized_msg) {
1058
58
        if constexpr (Ref == Local) {
1059
58
            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
58
    }
1068
1069
    template <class T, RefType Ref>
1070
5.54k
    static Status SerializeThriftMsg(JNIEnv* env, T* msg, Array<Ref>* serialized_msg) {
1071
5.54k
        if constexpr (Ref == Local) {
1072
5.54k
            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.54k
    }
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
                                             int64_t function_id);
1157
1158
    static Status Init();
1159
1160
private:
1161
    static void _parse_max_heap_memory_size_from_jvm();
1162
1163
    static Status _init_collect_class() WARN_UNUSED_RESULT;
1164
    static Status _init_register_natives() WARN_UNUSED_RESULT;
1165
    static Status _init_jni_scanner_loader() WARN_UNUSED_RESULT;
1166
1167
    static bool jvm_inited_;
1168
1169
    // for jvm heap
1170
    static jlong max_jvm_heap_memory_size_;
1171
1172
    // for JNI scanner loader
1173
    static GlobalObject jni_scanner_loader_obj_;
1174
    static MethodId jni_scanner_loader_method_;
1175
1176
    // for clean udf cache
1177
    static MethodId _clean_udf_cache_method_id;
1178
1179
    //for hashmap
1180
    static GlobalClass hashmap_class;
1181
    static MethodId hashmap_constructor;
1182
    static MethodId hashmap_put;
1183
1184
    //for map
1185
    static GlobalClass mapClass;
1186
    static MethodId mapEntrySetMethod;
1187
1188
    // for map entry
1189
    static GlobalClass mapEntryClass;
1190
    static MethodId getEntryKeyMethod;
1191
    static MethodId getEntryValueMethod;
1192
1193
    //for set
1194
    static GlobalClass setClass;
1195
    static MethodId iteratorSetMethod;
1196
1197
    // for iterator
1198
    static GlobalClass iteratorClass;
1199
    static MethodId iteratorHasNextMethod;
1200
    static MethodId iteratorNextMethod;
1201
};
1202
}; // namespace Jni
1203
1204
} // namespace doris