From 0dac21c35c658cbc5fca54712a865f189680e8d4 Mon Sep 17 00:00:00 2001 From: cloud-profiler-team Date: Mon, 27 Feb 2023 21:46:12 +0000 Subject: [PATCH 1/3] Always build heap_sampler code, by removing the macro that hides the code for pre-JDK11 environment. PiperOrigin-RevId: 512720321 --- Makefile | 3 +-- third_party/javaprofiler/heap_sampler.cc | 21 --------------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 15b6e6d33..8234047c5 100644 --- a/Makefile +++ b/Makefile @@ -30,8 +30,7 @@ CFLAGS = \ -Wno-array-bounds \ -g0 \ -DSTANDALONE_BUILD \ - -D_GNU_SOURCE \ - -DENABLE_HEAP_SAMPLING + -D_GNU_SOURCE ifeq ($(machine_type),$(filter $(machine_type),aarch64 arm64)) # Building on an ARM64 machine. diff --git a/third_party/javaprofiler/heap_sampler.cc b/third_party/javaprofiler/heap_sampler.cc index 8dc91dd50..10943eee4 100644 --- a/third_party/javaprofiler/heap_sampler.cc +++ b/third_party/javaprofiler/heap_sampler.cc @@ -321,7 +321,6 @@ bool HeapMonitor::CreateGCWaitingThread(jvmtiEnv* jvmti, JNIEnv* jni) { } bool HeapMonitor::Supported(jvmtiEnv *jvmti) { -#ifdef ENABLE_HEAP_SAMPLING jvmtiCapabilities caps; memset(&caps, 0, sizeof(caps)); if (jvmti->GetPotentialCapabilities(&caps) != JVMTI_ERROR_NONE) { @@ -347,9 +346,6 @@ bool HeapMonitor::Supported(jvmtiEnv *jvmti) { return false; } return true; -#else - return false; -#endif } void HeapMonitor::AddSample(JNIEnv *jni_env, jthread thread, jobject object, @@ -421,16 +417,13 @@ void HeapMonitor::WaitForShutdown() { } void HeapMonitor::AddCallback(jvmtiEventCallbacks *callbacks) { -#ifdef ENABLE_HEAP_SAMPLING callbacks->SampledObjectAlloc = &SampledObjectAlloc; callbacks->GarbageCollectionFinish = &GarbageCollectionFinish; -#endif } // Currently, we enable once and forget about it. bool HeapMonitor::Enable(jvmtiEnv *jvmti, JNIEnv* jni, int sampling_interval, bool use_jvm_trace) { -#ifdef ENABLE_HEAP_SAMPLING if (!Supported(jvmti)) { LOG(WARNING) << "Heap sampling is not supported by the JVM, disabling the " << " heap sampling monitor"; @@ -495,13 +488,9 @@ bool HeapMonitor::Enable(jvmtiEnv *jvmti, JNIEnv* jni, int sampling_interval, } return true; -#else - return false; -#endif } void HeapMonitor::Disable() { -#ifdef ENABLE_HEAP_SAMPLING jvmtiEnv *jvmti = jvmti_.load(); if (!jvmti) { return; @@ -516,47 +505,37 @@ void HeapMonitor::Disable() { // Notify the agent thread that we are done. google::javaprofiler::HeapMonitor::GetInstance()->ShutdownGCWaitingThread(); - -#else - // Do nothing: we never enabled ourselves. -#endif } std::unique_ptr HeapMonitor::GetHeapProfiles( JNIEnv* env, bool force_gc) { -#ifdef ENABLE_HEAP_SAMPLING // Note: technically this means that you cannot disable the sampler and then // get the profile afterwards; this could be changed if needed. if (jvmti_) { return GetInstance()->storage_.GetHeapProfiles(env, sampling_interval_, force_gc); } -#endif return EmptyHeapProfile(env); } std::unique_ptr HeapMonitor::GetPeakHeapProfiles( JNIEnv* env, bool force_gc) { -#ifdef ENABLE_HEAP_SAMPLING // Note: technically this means that you cannot disable the sampler and then // get the profile afterwards; this could be changed if needed. if (jvmti_) { return GetInstance()->storage_.GetPeakHeapProfiles(env, sampling_interval_); } -#endif return EmptyHeapProfile(env); } std::unique_ptr HeapMonitor::GetGarbageHeapProfiles(JNIEnv* env, bool force_gc) { -#ifdef ENABLE_HEAP_SAMPLING // Note: technically this means that you cannot disable the sampler and then // get the profile afterwards; this could be changed if needed. if (jvmti_) { return GetInstance()->storage_.GetGarbageHeapProfiles( env, sampling_interval_, force_gc); } -#endif return EmptyHeapProfile(env); } From 5295a73a640c71c8737861cf4a34e0e19ab0a80d Mon Sep 17 00:00:00 2001 From: sharmapranav Date: Fri, 3 Mar 2023 19:08:33 +0000 Subject: [PATCH 2/3] Vulnerability fix: update OpenSSL version 1.1.1f to 1.1.1t PiperOrigin-RevId: 513873456 --- Dockerfile | 2 +- Dockerfile.alpine | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 138a8c453..e508a6fb4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -49,7 +49,7 @@ RUN apt-get update && apt-get -y -q install \ # shared library. ENV PKG_CONFIG_PATH=/usr/local/ssl/lib/pkgconfig RUN mkdir /tmp/openssl && cd /tmp/openssl && \ - curl -sL https://github.com/openssl/openssl/archive/OpenSSL_1_1_1f.tar.gz | \ + curl -sL https://github.com/openssl/openssl/archive/OpenSSL_1_1_1t.tar.gz | \ tar xzv --strip=1 && \ ./config no-shared -fPIC --openssldir=/usr/local/ssl --prefix=/usr/local/ssl && \ make && make install_sw && \ diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 202537a91..5eda83bd4 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -47,7 +47,7 @@ RUN apk --no-cache add \ ENV PKG_CONFIG_PATH=/usr/local/ssl/lib/pkgconfig ENV JAVA_PATH=/usr/lib/jvm/java-11-openjdk/ RUN mkdir /tmp/openssl && cd /tmp/openssl && \ - curl -sL https://github.com/openssl/openssl/archive/OpenSSL_1_1_1f.tar.gz | \ + curl -sL https://github.com/openssl/openssl/archive/OpenSSL_1_1_1t.tar.gz | \ tar xzv --strip=1 && \ ./config no-shared -fPIC --openssldir=/usr/local/ssl --prefix=/usr/local/ssl && \ make && make install_sw && \ From 203d5774d7baaaf1efc14ade7facfea243b852c1 Mon Sep 17 00:00:00 2001 From: cloud-profiler-team Date: Sat, 4 Mar 2023 15:45:28 +0000 Subject: [PATCH 3/3] Internal Code Change PiperOrigin-RevId: 514064702 --- src/proto.cc | 1 + src/threads.cc | 1 + src/throttler_api.cc | 1 + 3 files changed, 3 insertions(+) diff --git a/src/proto.cc b/src/proto.cc index 6c64d8ee3..ffa8d4055 100644 --- a/src/proto.cc +++ b/src/proto.cc @@ -239,6 +239,7 @@ void ProfileProtoBuilder::Populate( int64_t count = trace.second; if (count != 0) { std::vector locations; + locations.reserve(trace.first.frames.size()); for (const auto &frame : trace.first.frames) { locations.push_back(LocationID(jni, frame)); } diff --git a/src/threads.cc b/src/threads.cc index 61ffdfd9d..e55e3ed8b 100644 --- a/src/threads.cc +++ b/src/threads.cc @@ -102,6 +102,7 @@ int64_t ThreadTable::Size() const { std::vector ThreadTable::Threads() const { std::vector tids; std::lock_guard lock(thread_mutex_); + tids.reserve(threads_.size()); for (const auto& t : threads_) { tids.push_back(t.first); } diff --git a/src/throttler_api.cc b/src/throttler_api.cc index 12832ebd9..23a87262a 100644 --- a/src/throttler_api.cc +++ b/src/throttler_api.cc @@ -292,6 +292,7 @@ bool APIThrottler::WaitNext() { } api::CreateProfileRequest req; + req.mutable_profile_type()->Reserve(types_.size()); for (const auto& type : types_) { req.add_profile_type(type); }