From 21f704582bb4948205d344b4a48b5a8f4d9534b6 Mon Sep 17 00:00:00 2001 From: "denghui.ddh" Date: Mon, 20 May 2019 22:39:27 +0800 Subject: [PATCH] [JFR] Add compatibility for UnlockCommercialFeatures Summary: add compatibility for UnlockCommercialFeatures Test Plan: test/jfr/test_unlockCommercialFeatures_compatibility.sh Reviewed-by: yfxhust, luchsh Issue: https://github.com/alibaba/dragonwell8_hotspot/issues/6 --- src/share/vm/jfr/dcmd/jfrDcmds.cpp | 1 + src/share/vm/jfr/dcmd/jfrDcmds.hpp | 19 +++++++ src/share/vm/runtime/globals.hpp | 3 ++ ..._unlockCommercialFeatures_compatibility.sh | 51 +++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 test/jfr/test_unlockCommercialFeatures_compatibility.sh diff --git a/src/share/vm/jfr/dcmd/jfrDcmds.cpp b/src/share/vm/jfr/dcmd/jfrDcmds.cpp index 67358b6b6..293cb2b3e 100644 --- a/src/share/vm/jfr/dcmd/jfrDcmds.cpp +++ b/src/share/vm/jfr/dcmd/jfrDcmds.cpp @@ -626,6 +626,7 @@ bool register_jfr_dcmds() { DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); + DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); return true; } diff --git a/src/share/vm/jfr/dcmd/jfrDcmds.hpp b/src/share/vm/jfr/dcmd/jfrDcmds.hpp index 857772d3b..035179cbd 100644 --- a/src/share/vm/jfr/dcmd/jfrDcmds.hpp +++ b/src/share/vm/jfr/dcmd/jfrDcmds.hpp @@ -166,6 +166,25 @@ class JfrConfigureFlightRecorderDCmd : public DCmdWithParser { virtual void execute(DCmdSource source, TRAPS); }; +class JfrUnlockCommercialFeaturesDCmd : public DCmd { +public: + JfrUnlockCommercialFeaturesDCmd(outputStream* output, bool heap) : DCmd(output, heap) { } + static const char* name() { return "VM.unlock_commercial_features"; } + static const char* description() { + return "Simulate commercial features unlocking for Alibaba Dragonwell8."; + } + static const char* impact() { return "Low"; } + static const JavaPermission permission() { + JavaPermission p = {"java.lang.management.ManagementPermission", + "monitor", NULL}; + return p; + } + static int num_arguments() { return 0; } + virtual void execute(DCmdSource source, TRAPS) { + UnlockCommercialFeatures = true; + } +}; + bool register_jfr_dcmds(); #endif // SHARE_VM_JFR_JFRDCMDS_HPP diff --git a/src/share/vm/runtime/globals.hpp b/src/share/vm/runtime/globals.hpp index 2ed1e013f..e260934aa 100644 --- a/src/share/vm/runtime/globals.hpp +++ b/src/share/vm/runtime/globals.hpp @@ -4027,6 +4027,9 @@ class CommandLineFlags { \ product(bool, EnableJFR, false, "Enable JFR feature") \ \ + product(bool, UnlockCommercialFeatures, false, \ + "This flag is ignored. Left for compatibility") \ + \ lp64_product(bool, CompilationWarmUpRecording, false, \ "Collect profiling information for JWarmUP") \ \ diff --git a/test/jfr/test_unlockCommercialFeatures_compatibility.sh b/test/jfr/test_unlockCommercialFeatures_compatibility.sh new file mode 100644 index 000000000..bb4509b91 --- /dev/null +++ b/test/jfr/test_unlockCommercialFeatures_compatibility.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# +# @test +# @summary Test 'jcmd VM.unlock_commercial_features' +# @run shell/timeout=500 test_unlockCommercialFeatures_compatibility.sh +# + +if [ "${TESTSRC}" = "" ] +then + TESTSRC=${PWD} + echo "TESTSRC not set. Using "${TESTSRC}" as default" +fi +echo "TESTSRC=${TESTSRC}" +## Adding common setup Variables for running shell tests. +. ${TESTSRC}/../test_env.sh + +JAVA=${TESTJAVA}${FS}bin${FS}java +JAVAC=${TESTJAVA}${FS}bin${FS}javac +JCMD=${TESTJAVA}${FS}bin${FS}jcmd +JPS=${TESTJAVA}${FS}bin${FS}jps + +# A simple testcase used to invoke JVM +TEST_CLASS=Test_$(date +%Y%m%d%H%M%S) +TEST_SOURCE=$TEST_CLASS.java + +cat > $TEST_SOURCE << EOF +public class ${TEST_CLASS} { + public static void main(String[] args) throws Exception{ + // keep Java process running + while (true) { Thread.sleep(1000); } + } +} +EOF + +# compile the test class +$JAVAC $TEST_SOURCE +if [ $? != '0' ]; then + echo "Failed to compile ${TEST_SOURCE}" + exit 1 +fi + +${JAVA} -XX:+EnableJFR -cp . ${TEST_CLASS}& + +PID=$(${JPS} | grep ${TEST_CLASS} | awk '{print $1}') +if [ $? != 0 ] || [ -z "${PID}" ]; then exit 1; fi + +${JCMD} ${PID} VM.unlock_commercial_features +if [ $? != 0 ]; then exit 1; fi + +kill -9 ${PID} +exit 0 -- GitLab