diff --git a/src/plan/tracing.rs b/src/plan/tracing.rs index 209b656c25..6a6a92ea79 100644 --- a/src/plan/tracing.rs +++ b/src/plan/tracing.rs @@ -3,6 +3,7 @@ use crate::scheduler::gc_work::{ProcessEdgesWork, SlotOf}; use crate::scheduler::{GCWorker, WorkBucketStage}; +#[cfg(debug_assertions)] use crate::util::log; use crate::util::ObjectReference; use crate::vm::SlotVisitor; diff --git a/src/util/copy/mod.rs b/src/util/copy/mod.rs index a0a1718d23..a1102ce87d 100644 --- a/src/util/copy/mod.rs +++ b/src/util/copy/mod.rs @@ -8,6 +8,7 @@ use crate::policy::copyspace::CopySpaceCopyContext; use crate::policy::immix::ImmixSpace; use crate::policy::immix::{ImmixCopyContext, ImmixHybridCopyContext}; use crate::policy::space::Space; +#[cfg(debug_assertions)] use crate::util::log; use crate::util::object_forwarding; use crate::util::opaque_pointer::VMWorkerThread; diff --git a/src/util/log.rs b/src/util/log.rs index 58baa2a64c..7bb95ac967 100644 --- a/src/util/log.rs +++ b/src/util/log.rs @@ -13,31 +13,43 @@ use the_log_crate; pub(crate) use the_log_crate::{error, info, warn}; -cfg_if::cfg_if! { - if #[cfg(all(not(debug_assertions), not(feature = "hot_log")))] { - // If it is release build and the feature "hot_log" is not enabled, - // then we define verbose logs as no-op in release build. +/// Whether logs of DEBUG and TRACE levels are enabled. +/// In debug build, they are always enabled. +/// In release build, they are not enabled unless the "hot_log" Cargo feature is enabled. +pub(crate) const HOT_LOG_ENABLED: bool = cfg!(any(not(debug_assertions), feature = "hot_log")); - /// The `log::debug!` macro is disabled in release build. - /// Use the "hot_log" feature to enable. - macro_rules! debug { - ($($arg:tt)+) => {} +/// A wrapper of the `debug!` macro in the `log` crate. +/// Does nothing if [`HOT_LOG_ENABLED`] is false. +macro_rules! debug { + (target: $target:expr, $($arg:tt)+) => { + if $crate::util::log::HOT_LOG_ENABLED { + the_log_crate::debug!(target: $target, $($arg)+) } - - /// The `log::trace!` macro is disabled in release build. - /// Use the "hot_log" feature to enable. - macro_rules! trace { - ($($arg:tt)+) => {} + }; + ($($arg:tt)+) => { + if $crate::util::log::HOT_LOG_ENABLED { + the_log_crate::debug!($($arg)+) } + } +} - // By default, a macro has no path-based scope. - // The following allows other modules to access the macros with `crate::util::log::debug` - // and `crate::util::log::trace`. - pub(crate) use debug; - pub(crate) use trace; - - } else { - // Otherwise simply import the macros from the `log` crate. - pub(crate) use the_log_crate::{debug, trace}; +/// A wrapper of the `trace!` macro in the `log` crate. +/// Does nothing if [`HOT_LOG_ENABLED`] is false. +macro_rules! trace { + (target: $target:expr, $($arg:tt)+) => { + if $crate::util::log::HOT_LOG_ENABLED { + the_log_crate::trace!(target: $target, $($arg)+) + } + }; + ($($arg:tt)+) => { + if $crate::util::log::HOT_LOG_ENABLED { + the_log_crate::trace!($($arg)+) + } } } + +// By default, a macro has no path-based scope. +// The following allows other modules to access the macros with `crate::util::log::debug` +// and `crate::util::log::trace`. +pub(crate) use debug; +pub(crate) use trace; diff --git a/src/vm/scanning.rs b/src/vm/scanning.rs index 850e3fb75a..e98b7eeeb6 100644 --- a/src/vm/scanning.rs +++ b/src/vm/scanning.rs @@ -15,7 +15,6 @@ pub trait SlotVisitor { /// This lets us use closures as SlotVisitor. impl SlotVisitor for F { fn visit_slot(&mut self, slot: SL) { - #[cfg(debug_assertions)] log::trace!( "(FunctionClosure) Visit slot {:?} (pointing to {:?})", slot,