Improve C++ logging for JNI code.
Gets rid of custom logging code that JNI was using and standardizes on `src/main/cpp/util/logging.h`.
JNI sets up a logger when the library is loaded.
PiperOrigin-RevId: 420161386
diff --git a/src/main/cpp/util/BUILD b/src/main/cpp/util/BUILD
index 3c416be..f63b424 100644
--- a/src/main/cpp/util/BUILD
+++ b/src/main/cpp/util/BUILD
@@ -96,6 +96,9 @@
name = "port",
srcs = ["port.cc"],
hdrs = ["port.h"],
+ visibility = [
+ "//src/main/native:__pkg__",
+ ],
)
cc_library(
diff --git a/src/main/native/BUILD b/src/main/native/BUILD
index 07d1c2d..1e02c9c 100644
--- a/src/main/native/BUILD
+++ b/src/main/native/BUILD
@@ -76,8 +76,9 @@
visibility = ["//src/main/java/com/google/devtools/build/lib/jni:__pkg__"],
deps = [
":latin1_jni_path",
- "//src/main/cpp/util",
+ "//src/main/cpp/util:logging",
"//src/main/cpp/util:md5",
+ "//src/main/cpp/util:port",
],
)
diff --git a/src/main/native/darwin/file_jni.cc b/src/main/native/darwin/file_jni.cc
index 0ef5316..b076cd9 100644
--- a/src/main/native/darwin/file_jni.cc
+++ b/src/main/native/darwin/file_jni.cc
@@ -24,7 +24,6 @@
#include <string>
-#include "src/main/native/macros.h"
#include "src/main/native/unix_jni.h"
namespace blaze_jni {
@@ -86,8 +85,6 @@
return statbuf.st_ctime;
case STAT_MTIME:
return statbuf.st_mtime;
- default:
- CHECK(false);
}
}
@@ -99,8 +96,6 @@
return statbuf.st_ctimespec.tv_nsec;
case STAT_MTIME:
return statbuf.st_mtimespec.tv_nsec;
- default:
- CHECK(false);
}
}
diff --git a/src/main/native/darwin/sleep_prevention_jni.cc b/src/main/native/darwin/sleep_prevention_jni.cc
index 2abb022..67c35b2 100644
--- a/src/main/native/darwin/sleep_prevention_jni.cc
+++ b/src/main/native/darwin/sleep_prevention_jni.cc
@@ -18,9 +18,8 @@
// absl::Mutex but we cannot yet because Bazel doesn't depend on absl.
#include <mutex> // NOLINT
-#include "src/main/native/darwin/util.h"
+#include "src/main/cpp/util/logging.h"
#include "src/main/native/unix_jni.h"
-#include "src/main/native/macros.h"
namespace blaze_jni {
@@ -35,15 +34,14 @@
int portable_push_disable_sleep() {
std::lock_guard<std::mutex> lock(g_sleep_state_mutex);
- CHECK_GE(g_sleep_state_stack, 0);
+ BAZEL_CHECK_GE(g_sleep_state_stack, 0);
if (g_sleep_state_stack == 0) {
- CHECK_EQ(g_sleep_state_assertion, kIOPMNullAssertionID);
+ BAZEL_CHECK_EQ(g_sleep_state_assertion, kIOPMNullAssertionID);
CFStringRef reasonForActivity = CFSTR("build.bazel");
IOReturn success = IOPMAssertionCreateWithName(
kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, reasonForActivity,
&g_sleep_state_assertion);
- CHECK_EQ(success, kIOReturnSuccess);
- log_if_possible("sleep assertion created");
+ BAZEL_CHECK_EQ(success, kIOReturnSuccess);
}
g_sleep_state_stack += 1;
return 0;
@@ -51,14 +49,13 @@
int portable_pop_disable_sleep() {
std::lock_guard<std::mutex> lock(g_sleep_state_mutex);
- CHECK_GT(g_sleep_state_stack, 0);
+ BAZEL_CHECK_GT(g_sleep_state_stack, 0);
g_sleep_state_stack -= 1;
if (g_sleep_state_stack == 0) {
- CHECK_NEQ(g_sleep_state_assertion, kIOPMNullAssertionID);
+ BAZEL_CHECK_NE(g_sleep_state_assertion, kIOPMNullAssertionID);
IOReturn success = IOPMAssertionRelease(g_sleep_state_assertion);
- CHECK_EQ(success, kIOReturnSuccess);
+ BAZEL_CHECK_EQ(success, kIOReturnSuccess);
g_sleep_state_assertion = kIOPMNullAssertionID;
- log_if_possible("sleep assertion released");
}
return 0;
}
diff --git a/src/main/native/darwin/system_disk_space_monitor_jni.cc b/src/main/native/darwin/system_disk_space_monitor_jni.cc
index aacc2ce..eb56bb9 100644
--- a/src/main/native/darwin/system_disk_space_monitor_jni.cc
+++ b/src/main/native/darwin/system_disk_space_monitor_jni.cc
@@ -15,8 +15,8 @@
#include <notify.h>
#include <notify_keys.h>
+#include "src/main/cpp/util/logging.h"
#include "src/main/native/darwin/util.h"
-#include "src/main/native/macros.h"
#include "src/main/native/unix_jni.h"
// Not defined by Apple headers, but definitely sent out with macOS 12.
@@ -32,30 +32,29 @@
dispatch_once(&once_token, ^{
dispatch_queue_t queue = bazel::darwin::JniDispatchQueue();
notify_handler_t lowHandler = (^(int token) {
- log_if_possible("disk space low anomaly");
+ BAZEL_LOG(USER) << "disk space low anomaly";
disk_space_callback(DiskSpaceLevelLow);
});
notify_handler_t veryLowHandler = (^(int token) {
- log_if_possible("disk space very low anomaly");
+ BAZEL_LOG(USER) << "disk space very low anomaly";
disk_space_callback(DiskSpaceLevelVeryLow);
});
int notifyToken;
int status = notify_register_dispatch(kNotifyVFSLowDiskSpace,
¬ifyToken,
queue, lowHandler);
- CHECK(status == NOTIFY_STATUS_OK);
+ BAZEL_CHECK_EQ(status, NOTIFY_STATUS_OK);
status = notify_register_dispatch(kNotifyVFSVeryLowDiskSpace,
¬ifyToken,
queue, veryLowHandler);
- CHECK(status == NOTIFY_STATUS_OK);
+ BAZEL_CHECK_EQ(status, NOTIFY_STATUS_OK);
// These are registered solely so we can test the system from end-to-end.
status = notify_register_dispatch(
"com.google.bazel.test.diskspace.low", ¬ifyToken, queue, lowHandler);
- CHECK(status == NOTIFY_STATUS_OK);
+ BAZEL_CHECK_EQ(status, NOTIFY_STATUS_OK);
status = notify_register_dispatch("com.google.bazel.test.diskspace.verylow",
¬ifyToken, queue, veryLowHandler);
- CHECK(status == NOTIFY_STATUS_OK);
- log_if_possible("Disk space monitoring registered");
+ BAZEL_CHECK_EQ(status, NOTIFY_STATUS_OK);
});
}
diff --git a/src/main/native/darwin/system_load_advisory_monitor_jni.cc b/src/main/native/darwin/system_load_advisory_monitor_jni.cc
index 3a597ec..53a33d5 100644
--- a/src/main/native/darwin/system_load_advisory_monitor_jni.cc
+++ b/src/main/native/darwin/system_load_advisory_monitor_jni.cc
@@ -15,8 +15,8 @@
#include <IOKit/pwr_mgt/IOPMLib.h>
#include <notify.h>
+#include "src/main/cpp/util/logging.h"
#include "src/main/native/darwin/util.h"
-#include "src/main/native/macros.h"
#include "src/main/native/unix_jni.h"
namespace blaze_jni {
@@ -24,9 +24,6 @@
static int gSystemLoadAdvisoryNotifyToken = 0;
void portable_start_system_load_advisory_monitoring() {
- // To test use:
- // /usr/bin/log stream -level debug \
- // --predicate '(subsystem == "build.bazel")'
// We install a test notification as well that can be used for testing.
static dispatch_once_t once_token;
dispatch_once(&once_token, ^{
@@ -38,15 +35,14 @@
int status = notify_register_dispatch(kIOSystemLoadAdvisoryNotifyName,
&gSystemLoadAdvisoryNotifyToken,
queue, handler);
- CHECK(status == NOTIFY_STATUS_OK);
+ BAZEL_CHECK_EQ(status, NOTIFY_STATUS_OK);
// This is registered solely so we can test the system from end-to-end.
// Using the Apple notification requires admin access.
int testToken;
status = notify_register_dispatch(
"com.google.bazel.test.SystemLoadAdvisory", &testToken, queue, handler);
- CHECK(status == NOTIFY_STATUS_OK);
- log_if_possible("system load advisory monitoring registered");
+ BAZEL_CHECK_EQ(status, NOTIFY_STATUS_OK);
});
}
@@ -54,30 +50,28 @@
uint64_t state;
uint32_t status = notify_get_state(gSystemLoadAdvisoryNotifyToken, &state);
if (status != NOTIFY_STATUS_OK) {
- log_if_possible("error: notify_get_state failed (%d)", status);
- return -1;
+ BAZEL_LOG(FATAL) << "notify_get_state failed:" << status;
}
IOSystemLoadAdvisoryLevel advisoryLevel = (IOSystemLoadAdvisoryLevel)state;
int load = -1;
switch (advisoryLevel) {
case kIOSystemLoadAdvisoryLevelGreat:
- log_if_possible("system load advisory great (0) anomaly");
+ BAZEL_LOG(USER) << "system load advisory great (0) anomaly";
load = 0;
break;
case kIOSystemLoadAdvisoryLevelOK:
- log_if_possible("system load advisory ok (25) anomaly");
+ BAZEL_LOG(USER) << "system load advisory ok (25) anomaly";
load = 25;
break;
case kIOSystemLoadAdvisoryLevelBad:
- log_if_possible("system load advisory bad (75) anomaly");
+ BAZEL_LOG(USER) << "system load advisory bad (75) anomaly";
load = 75;
break;
}
if (load == -1) {
- log_if_possible("error: unknown system load advisory level: %d",
- (int)advisoryLevel);
+ BAZEL_LOG(FATAL) << "unknown system load advisory level: " << advisoryLevel;
}
return load;
diff --git a/src/main/native/darwin/system_memory_pressure_jni.cc b/src/main/native/darwin/system_memory_pressure_jni.cc
index 612c7d2..6c6ce7e 100644
--- a/src/main/native/darwin/system_memory_pressure_jni.cc
+++ b/src/main/native/darwin/system_memory_pressure_jni.cc
@@ -14,16 +14,14 @@
#include <notify.h>
+#include "src/main/cpp/util/logging.h"
#include "src/main/native/darwin/util.h"
-#include "src/main/native/macros.h"
#include "src/main/native/unix_jni.h"
namespace blaze_jni {
void portable_start_memory_pressure_monitoring() {
// To test use:
- // /usr/bin/log stream -level debug \
- // --predicate '(subsystem == "build.bazel")'
// sudo memory_pressure -S -l warn
// sudo memory_pressure -S -l critical
// or use the test notifications that we register.
@@ -33,19 +31,19 @@
dispatch_source_t source = dispatch_source_create(
DISPATCH_SOURCE_TYPE_MEMORYPRESSURE, 0,
DISPATCH_MEMORYPRESSURE_WARN | DISPATCH_MEMORYPRESSURE_CRITICAL, queue);
- CHECK(source != nullptr);
+ BAZEL_CHECK_NE(source, nullptr);
dispatch_source_set_event_handler(source, ^{
dispatch_source_memorypressure_flags_t pressureLevel =
dispatch_source_get_data(source);
if (pressureLevel == DISPATCH_MEMORYPRESSURE_WARN) {
- log_if_possible("memory pressure warning anomaly");
+ BAZEL_LOG(USER) << "memory pressure warning anomaly";
memory_pressure_callback(MemoryPressureLevelWarning);
} else if (pressureLevel == DISPATCH_MEMORYPRESSURE_CRITICAL) {
- log_if_possible("memory pressure critical anomaly");
+ BAZEL_LOG(USER) << "memory pressure critical anomaly";
memory_pressure_callback(MemoryPressureLevelCritical);
} else {
- log_if_possible("error: unknown memory pressure critical level: %d",
- (int)pressureLevel);
+ BAZEL_LOG(FATAL) << "unknown memory pressure critical level: "
+ << pressureLevel;
}
});
dispatch_resume(source);
@@ -55,18 +53,17 @@
int32_t status = notify_register_dispatch(
"com.google.bazel.test.memorypressurelevel.warning", &testToken, queue,
^(int state) {
- log_if_possible("memory pressure test warning anomaly");
+ BAZEL_LOG(USER) << "memory pressure test warning anomaly";
memory_pressure_callback(MemoryPressureLevelWarning);
});
- CHECK(status == NOTIFY_STATUS_OK);
+ BAZEL_CHECK_EQ(status, NOTIFY_STATUS_OK);
status = notify_register_dispatch(
"com.google.bazel.test.memorypressurelevel.critical", &testToken, queue,
^(int state) {
- log_if_possible("memory pressure test critical anomaly");
+ BAZEL_LOG(USER) << "memory pressure test critical anomaly";
memory_pressure_callback(MemoryPressureLevelCritical);
});
- CHECK(status == NOTIFY_STATUS_OK);
- log_if_possible("memory pressure monitoring registered");
+ BAZEL_CHECK_EQ(status, NOTIFY_STATUS_OK);
});
}
diff --git a/src/main/native/darwin/system_suspension_monitor_jni.cc b/src/main/native/darwin/system_suspension_monitor_jni.cc
index 4b0450a..3483aa7 100644
--- a/src/main/native/darwin/system_suspension_monitor_jni.cc
+++ b/src/main/native/darwin/system_suspension_monitor_jni.cc
@@ -16,8 +16,8 @@
#include <IOKit/pwr_mgt/IOPMLib.h>
#include <notify.h>
+#include "src/main/cpp/util/logging.h"
#include "src/main/native/darwin/util.h"
-#include "src/main/native/macros.h"
#include "src/main/native/unix_jni.h"
namespace blaze_jni {
@@ -37,7 +37,7 @@
break;
case kIOMessageSystemWillSleep:
- log_if_possible("suspend anomaly due to kIOMessageSystemWillSleep");
+ BAZEL_LOG(USER) << "suspend anomaly due to kIOMessageSystemWillSleep";
suspend_callback(SuspensionReasonSleep);
// This needs to be acknowledged to allow sleep.
IOAllowPowerChange(state->connect_port, (intptr_t)message_argument);
@@ -57,7 +57,7 @@
// wasn't. I haven't come up with an smart way of avoiding this issue, but
// I don't think we really care. Over reporting "suspensions" is better
// than under reporting them.
- log_if_possible("suspend anomaly due to kIOMessageSystemHasPoweredOn");
+ BAZEL_LOG(USER) << "suspend anomaly due to kIOMessageSystemHasPoweredOn";
suspend_callback(SuspensionReasonWake);
break;
@@ -83,11 +83,9 @@
// Register to receive system sleep notifications.
// Testing needs to be done manually. Use the logging to verify
// that sleeps are being caught here.
- // `/usr/bin/log \
- // stream -level debug --predicate '(subsystem == "build.bazel")'`
suspend_state.connect_port = IORegisterForSystemPower(
&suspend_state, ¬ifyPortRef, SleepCallBack, ¬ifierObject);
- CHECK(suspend_state.connect_port != MACH_PORT_NULL);
+ BAZEL_CHECK_NE(suspend_state.connect_port, MACH_PORT_NULL);
IONotificationPortSetDispatchQueue(notifyPortRef, queue);
// Register to deal with SIGCONT.
@@ -98,24 +96,23 @@
// having this functionality gives us some ability to unit test suspension
// counts.
sig_t signal_val = signal(SIGCONT, SIG_IGN);
- CHECK(signal_val != SIG_ERR);
+ BAZEL_CHECK_NE(signal_val, SIG_ERR);
dispatch_source_t signal_source =
dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGCONT, 0, queue);
- CHECK(signal_source != nullptr);
+ BAZEL_CHECK_NE(signal_source, nullptr);
dispatch_source_set_event_handler(signal_source, ^{
- log_if_possible("suspend anomaly due to SIGCONT");
+ BAZEL_LOG(USER) << "suspend anomaly due to SIGCONT";
suspend_callback(SuspensionReasonSIGCONT);
});
dispatch_resume(signal_source);
signal_source =
dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGTSTP, 0, queue);
- CHECK(signal_source != nullptr);
+ BAZEL_CHECK_NE(signal_source, nullptr);
dispatch_source_set_event_handler(signal_source, ^{
- log_if_possible("suspend anomaly due to SIGTSTP");
+ BAZEL_LOG(USER) << "suspend anomaly due to SIGTSTP";
suspend_callback(SuspensionReasonSIGTSTP);
});
dispatch_resume(signal_source);
- log_if_possible("suspend monitoring registered");
});
}
diff --git a/src/main/native/darwin/system_thermal_monitor_jni.cc b/src/main/native/darwin/system_thermal_monitor_jni.cc
index 6b36315..baa6e21 100644
--- a/src/main/native/darwin/system_thermal_monitor_jni.cc
+++ b/src/main/native/darwin/system_thermal_monitor_jni.cc
@@ -16,8 +16,8 @@
#include <libkern/OSThermalNotification.h>
#include <notify.h>
+#include "src/main/cpp/util/logging.h"
#include "src/main/native/darwin/util.h"
-#include "src/main/native/macros.h"
#include "src/main/native/unix_jni.h"
namespace blaze_jni {
@@ -27,41 +27,37 @@
static int thermal_load_from_token(int token) {
uint64_t state;
uint32_t status = notify_get_state(token, &state);
- if (status != NOTIFY_STATUS_OK) {
- log_if_possible("error: notify_get_state failed (%d)", status);
- return -1;
- }
+ BAZEL_CHECK_EQ(status, NOTIFY_STATUS_OK);
OSThermalPressureLevel thermalLevel = (OSThermalPressureLevel)state;
int load = -1;
switch (thermalLevel) {
case kOSThermalPressureLevelNominal:
- log_if_possible("thermal pressure nominal (0) anomaly");
+ BAZEL_LOG(USER) << "thermal pressure nominal (0) anomaly";
load = 0;
break;
case kOSThermalPressureLevelModerate:
- log_if_possible("thermal pressure moderate (33) anomaly ");
+ BAZEL_LOG(USER) << "thermal pressure moderate (33) anomaly ";
load = 33;
break;
case kOSThermalPressureLevelHeavy:
- log_if_possible("thermal pressure heavy (50) anomaly");
+ BAZEL_LOG(USER) << "thermal pressure heavy (50) anomaly";
load = 50;
break;
case kOSThermalPressureLevelTrapping:
- log_if_possible("thermal pressure trapping (90) anomaly");
+ BAZEL_LOG(USER) << "thermal pressure trapping (90) anomaly";
load = 90;
break;
case kOSThermalPressureLevelSleeping:
- log_if_possible("thermal pressure sleeping (100) anomaly");
+ BAZEL_LOG(USER) << "thermal pressure sleeping (100) anomaly";
load = 100;
break;
}
if (load == -1) {
- log_if_possible("error: unknown thermal pressure level: %d",
- (int)thermalLevel);
+ BAZEL_LOG(FATAL) << "unknown thermal pressure level: " << thermalLevel;
}
return load;
@@ -69,8 +65,6 @@
void portable_start_thermal_monitoring() {
// To test use:
- // /usr/bin/log stream -level debug \
- // --predicate '(subsystem == "build.bazel")'
// sudo thermal simulate cpu {nominal|moderate|heavy|trapping|sleeping}
// Note that we install the test notification as well that can be used for
// testing.
@@ -84,7 +78,7 @@
int status =
notify_register_dispatch(kOSThermalNotificationPressureLevelName,
&gThermalNotifyToken, queue, handler);
- CHECK(status == NOTIFY_STATUS_OK);
+ BAZEL_CHECK_EQ(status, NOTIFY_STATUS_OK);
// This is registered solely so we can test the system from end-to-end.
// Using the Apple notification requires admin access.
@@ -92,8 +86,8 @@
status =
notify_register_dispatch("com.google.bazel.test.thermalpressurelevel",
&testToken, queue, handler);
- CHECK(status == NOTIFY_STATUS_OK);
- log_if_possible("thermal monitoring registered");
+ BAZEL_CHECK_EQ(status, NOTIFY_STATUS_OK);
+ BAZEL_LOG(INFO) << "thermal monitoring registered";
});
}
diff --git a/src/main/native/darwin/util.cc b/src/main/native/darwin/util.cc
index 5a4aad7..9709093 100644
--- a/src/main/native/darwin/util.cc
+++ b/src/main/native/darwin/util.cc
@@ -14,7 +14,7 @@
#include "src/main/native/darwin/util.h"
-#include "src/main/native/macros.h"
+#include "src/main/cpp/util/logging.h"
namespace bazel {
namespace darwin {
@@ -24,25 +24,10 @@
static dispatch_queue_t queue;
dispatch_once(&once_token, ^{
queue = dispatch_queue_create("build.bazel.jni", DISPATCH_QUEUE_SERIAL);
- CHECK(queue);
+ BAZEL_CHECK_NE(queue, nullptr);
});
return queue;
}
-os_log_t JniOSLog() {
- static dispatch_once_t once_token;
- static os_log_t log = nullptr;
- // On macOS < 10.12, os_log_create is not available. Since we target 10.10,
- // this will be weakly linked and can be checked for availability at run
- // time.
- if (&os_log_create != nullptr) {
- dispatch_once(&once_token, ^{
- log = os_log_create("build.bazel", "jni");
- CHECK(log);
- });
- }
- return log;
-}
-
} // namespace darwin
} // namespace bazel
diff --git a/src/main/native/darwin/util.h b/src/main/native/darwin/util.h
index 871f2d5..c9bda1d 100644
--- a/src/main/native/darwin/util.h
+++ b/src/main/native/darwin/util.h
@@ -24,26 +24,8 @@
// Queue used for all of our anomaly tracking.
dispatch_queue_t JniDispatchQueue();
-// Log used for all of our anomaly logging.
-// Logging can be traced using:
-// `log stream -level debug --predicate '(subsystem == "build.bazel")'`
-//
-// This may return NULL if `os_log_create` is not supported on this version of
-// macOS. Use `log_if_possible` to log when supported.
-os_log_t JniOSLog();
-
} // namespace darwin
} // namespace bazel
-// The macOS implementation asserts that `msg` be a string literal (not just a
-// const char*), so we cannot use a function.
-#define log_if_possible(msg...) \
- do { \
- os_log_t log = bazel::darwin::JniOSLog(); \
- if (log != nullptr) { \
- os_log_debug(log, msg); \
- } \
- } while (0);
-
#endif // BAZEL_SRC_MAIN_NATIVE_DARWIN_JNI_UTIL_H_
diff --git a/src/main/native/macros.h b/src/main/native/macros.h
index e635339..c310d8e 100644
--- a/src/main/native/macros.h
+++ b/src/main/native/macros.h
@@ -34,20 +34,4 @@
#define FALLTHROUGH_INTENDED do { } while (0)
#endif
-#define CHECK(condition) \
- do { \
- if (!(condition)) { \
- fprintf(stderr, "%s:%d: check failed: %s\n", \
- __FILE__, __LINE__, #condition); \
- abort(); \
- } \
- } while (0)
-
-#define CHECK_EQ(a, b) CHECK((a) == (b))
-#define CHECK_NEQ(a, b) CHECK((a) != (b))
-#define CHECK_GT(a, b) CHECK((a) > (b))
-#define CHECK_GE(a, b) CHECK((a) >= (b))
-#define CHECK_LT(a, b) CHECK((a) < (b))
-#define CHECK_LE(a, b) CHECK((a) <= (b))
-
#endif // MACROS_H__
diff --git a/src/main/native/unix_jni.cc b/src/main/native/unix_jni.cc
index 24be06c..14a3cfb 100644
--- a/src/main/native/unix_jni.cc
+++ b/src/main/native/unix_jni.cc
@@ -35,6 +35,7 @@
#include <string>
#include <vector>
+#include "src/main/cpp/util/logging.h"
#include "src/main/cpp/util/port.h"
#include "src/main/native/latin1_jni_path.h"
#include "src/main/native/macros.h"
@@ -55,9 +56,7 @@
success = env->ThrowNew(exception_class, message.c_str()) == 0;
}
if (!success) {
- fprintf(stderr, "error: Failure to throw java error: %s\n",
- message.c_str());
- abort(); // panic!
+ BAZEL_LOG(FATAL) << "Failure to throw java error: " << message.c_str();
}
}
@@ -174,8 +173,9 @@
env->ThrowNew(exception_class, message.c_str());
return true;
} else {
- abort(); // panic!
- return false; // Not reachable.
+ BAZEL_LOG(FATAL) << "Unable to find exception_class: "
+ << exception_classname;
+ return false;
}
}
@@ -207,19 +207,20 @@
if (status == JNI_EDETACHED) {
attach_current_thread = true;
} else {
- CHECK_EQ(status, JNI_OK);
+ BAZEL_CHECK_EQ(status, JNI_OK);
}
if (attach_current_thread) {
- CHECK_EQ(java_vm->AttachCurrentThread((void **)&java_env, nullptr), 0);
+ BAZEL_CHECK_EQ(java_vm->AttachCurrentThread((void **)&java_env, nullptr),
+ 0);
}
jclass clazz = java_env->GetObjectClass(object);
- CHECK_NEQ(clazz, nullptr);
+ BAZEL_CHECK_NE(clazz, nullptr);
jmethodID method_id = java_env->GetMethodID(clazz, callback, "(I)V");
- CHECK_NEQ(method_id, nullptr);
+ BAZEL_CHECK_NE(method_id, nullptr);
java_env->CallVoidMethod(object, method_id, value);
if (attach_current_thread) {
- CHECK_EQ(java_vm->DetachCurrentThread(), JNI_OK);
+ BAZEL_CHECK_EQ(java_vm->DetachCurrentThread(), JNI_OK);
}
}
@@ -294,14 +295,14 @@
static jclass makeStaticClass(JNIEnv *env, const char *name) {
jclass lookup_result = env->FindClass(name);
- CHECK(lookup_result != nullptr);
+ BAZEL_CHECK_NE(lookup_result, nullptr);
return static_cast<jclass>(env->NewGlobalRef(lookup_result));
}
static jmethodID getConstructorID(JNIEnv *env, jclass clazz,
const char *parameters) {
jmethodID method = env->GetMethodID(clazz, "<init>", parameters);
- CHECK(method != nullptr);
+ BAZEL_CHECK_NE(method, nullptr);
return method;
}
@@ -339,7 +340,7 @@
const char *name,
int val) {
jfieldID fid = env->GetFieldID(clazz, name, "I");
- CHECK(fid != nullptr);
+ BAZEL_CHECK_NE(fid, nullptr);
env->SetIntField(object, fid, val);
}
@@ -780,9 +781,9 @@
jbyteArray types_obj = nullptr;
if (read_types != 'n') {
- CHECK(len == types.size());
+ BAZEL_CHECK_EQ(len, types.size());
types_obj = env->NewByteArray(len);
- CHECK(types_obj);
+ BAZEL_CHECK_NE(types_obj, nullptr);
if (len > 0) {
env->SetByteArrayRegion(types_obj, 0, len, &types[0]);
}
@@ -891,7 +892,7 @@
// dir_path buffer is still empty but we have the full path in entry.
path = entry;
}
- CHECK(!env->ExceptionOccurred());
+ BAZEL_CHECK(!env->ExceptionOccurred());
PostException(env, errno, std::string(function) + " (" + path + ")");
}
@@ -1024,7 +1025,7 @@
const int dir_fd, const char* entry) {
DIR *dir = ForceOpendir(env, *dir_path, dir_fd, entry);
if (dir == nullptr) {
- CHECK(env->ExceptionOccurred() != nullptr);
+ BAZEL_CHECK_NE(env->ExceptionOccurred(), nullptr);
return -1;
}
@@ -1053,7 +1054,7 @@
bool is_dir;
if (IsSubdir(env, *dir_path, dirfd(dir), de, &is_dir) == -1) {
- CHECK(env->ExceptionOccurred() != nullptr);
+ BAZEL_CHECK_NE(env->ExceptionOccurred(), nullptr);
break;
}
if (is_dir) {
@@ -1065,7 +1066,7 @@
if (env->ExceptionOccurred() == nullptr) {
for (const auto &file : dir_files) {
if (ForceDelete(env, *dir_path, dirfd(dir), file.c_str(), false) == -1) {
- CHECK(env->ExceptionOccurred() != nullptr);
+ BAZEL_CHECK_NE(env->ExceptionOccurred(), nullptr);
break;
}
}
@@ -1075,11 +1076,11 @@
if (env->ExceptionOccurred() == nullptr) {
for (const auto &subdir : dir_subdirs) {
if (DeleteTreesBelow(env, dir_path, dirfd(dir), subdir.c_str()) == -1) {
- CHECK(env->ExceptionOccurred() != nullptr);
+ BAZEL_CHECK_NE(env->ExceptionOccurred(), nullptr);
break;
}
if (ForceDelete(env, *dir_path, dirfd(dir), subdir.c_str(), true) == -1) {
- CHECK(env->ExceptionOccurred() != nullptr);
+ BAZEL_CHECK_NE(env->ExceptionOccurred(), nullptr);
break;
}
}
@@ -1108,9 +1109,9 @@
const char *path_chars = GetStringLatin1Chars(env, path);
std::vector<std::string> dir_path;
if (DeleteTreesBelow(env, &dir_path, AT_FDCWD, path_chars) == -1) {
- CHECK(env->ExceptionOccurred() != nullptr);
+ BAZEL_CHECK_NE(env->ExceptionOccurred(), nullptr);
}
- CHECK(dir_path.empty());
+ BAZEL_CHECK(dir_path.empty());
ReleaseStringLatin1Chars(path_chars);
}
diff --git a/src/main/native/unix_jni_bsd.cc b/src/main/native/unix_jni_bsd.cc
index cb9093f..932867f 100644
--- a/src/main/native/unix_jni_bsd.cc
+++ b/src/main/native/unix_jni_bsd.cc
@@ -36,7 +36,6 @@
#include <string>
-#include "src/main/native/macros.h"
#include "src/main/native/unix_jni.h"
namespace blaze_jni {
@@ -66,8 +65,6 @@
return statbuf.st_ctime;
case STAT_MTIME:
return statbuf.st_mtime;
- default:
- CHECK(false);
}
}
@@ -79,8 +76,6 @@
return statbuf.st_ctimespec.tv_nsec;
case STAT_MTIME:
return statbuf.st_mtimespec.tv_nsec;
- default:
- CHECK(false);
}
}
diff --git a/src/main/native/unix_jni_linux.cc b/src/main/native/unix_jni_linux.cc
index 9caae56..4855ab0 100644
--- a/src/main/native/unix_jni_linux.cc
+++ b/src/main/native/unix_jni_linux.cc
@@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-
#include <errno.h>
#include <stdlib.h>
#include <string.h>
@@ -21,7 +20,6 @@
#include <string>
-#include "src/main/native/macros.h"
#include "src/main/native/unix_jni.h"
namespace blaze_jni {
@@ -57,8 +55,6 @@
return statbuf.st_ctim.tv_sec;
case STAT_MTIME:
return statbuf.st_mtim.tv_sec;
- default:
- CHECK(false);
}
return 0;
}
@@ -71,8 +67,6 @@
return statbuf.st_ctim.tv_nsec;
case STAT_MTIME:
return statbuf.st_mtim.tv_nsec;
- default:
- CHECK(false);
}
return 0;
}