1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/services/dtraceAttacher.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,148 @@ 1.4 +/* 1.5 + * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "code/codeCache.hpp" 1.30 +#include "memory/resourceArea.hpp" 1.31 +#include "runtime/deoptimization.hpp" 1.32 +#include "runtime/vmThread.hpp" 1.33 +#include "runtime/vm_operations.hpp" 1.34 +#include "services/dtraceAttacher.hpp" 1.35 + 1.36 +#ifdef SOLARIS 1.37 + 1.38 +class VM_DeoptimizeTheWorld : public VM_Operation { 1.39 + public: 1.40 + VMOp_Type type() const { 1.41 + return VMOp_DeoptimizeTheWorld; 1.42 + } 1.43 + void doit() { 1.44 + CodeCache::mark_all_nmethods_for_deoptimization(); 1.45 + ResourceMark rm; 1.46 + DeoptimizationMarker dm; 1.47 + // Deoptimize all activations depending on marked methods 1.48 + Deoptimization::deoptimize_dependents(); 1.49 + 1.50 + // Mark the dependent methods non entrant 1.51 + CodeCache::make_marked_nmethods_not_entrant(); 1.52 + } 1.53 +}; 1.54 + 1.55 +static void set_bool_flag(const char* flag, bool value) { 1.56 + CommandLineFlags::boolAtPut((char*)flag, strlen(flag), &value, 1.57 + Flag::ATTACH_ON_DEMAND); 1.58 +} 1.59 + 1.60 +// Enable only the "fine grained" flags. Do *not* touch 1.61 +// the overall "ExtendedDTraceProbes" flag. 1.62 +void DTrace::enable_dprobes(int probes) { 1.63 + bool changed = false; 1.64 + if (!DTraceAllocProbes && (probes & DTRACE_ALLOC_PROBES)) { 1.65 + set_bool_flag("DTraceAllocProbes", true); 1.66 + changed = true; 1.67 + } 1.68 + if (!DTraceMethodProbes && (probes & DTRACE_METHOD_PROBES)) { 1.69 + set_bool_flag("DTraceMethodProbes", true); 1.70 + changed = true; 1.71 + } 1.72 + if (!DTraceMonitorProbes && (probes & DTRACE_MONITOR_PROBES)) { 1.73 + set_bool_flag("DTraceMonitorProbes", true); 1.74 + changed = true; 1.75 + } 1.76 + 1.77 + if (changed) { 1.78 + // one or more flags changed, need to deoptimize 1.79 + VM_DeoptimizeTheWorld op; 1.80 + VMThread::execute(&op); 1.81 + } 1.82 +} 1.83 + 1.84 +// Disable only the "fine grained" flags. Do *not* touch 1.85 +// the overall "ExtendedDTraceProbes" flag. 1.86 +void DTrace::disable_dprobes(int probes) { 1.87 + bool changed = false; 1.88 + if (DTraceAllocProbes && (probes & DTRACE_ALLOC_PROBES)) { 1.89 + set_bool_flag("DTraceAllocProbes", false); 1.90 + changed = true; 1.91 + } 1.92 + if (DTraceMethodProbes && (probes & DTRACE_METHOD_PROBES)) { 1.93 + set_bool_flag("DTraceMethodProbes", false); 1.94 + changed = true; 1.95 + } 1.96 + if (DTraceMonitorProbes && (probes & DTRACE_MONITOR_PROBES)) { 1.97 + set_bool_flag("DTraceMonitorProbes", false); 1.98 + changed = true; 1.99 + } 1.100 + if (changed) { 1.101 + // one or more flags changed, need to deoptimize 1.102 + VM_DeoptimizeTheWorld op; 1.103 + VMThread::execute(&op); 1.104 + } 1.105 +} 1.106 + 1.107 +// Do clean-up on "all door clients detached" event. 1.108 +void DTrace::detach_all_clients() { 1.109 + /* 1.110 + * We restore the state of the fine grained flags 1.111 + * to be consistent with overall ExtendedDTraceProbes. 1.112 + * This way, we will honour command line setting or the 1.113 + * last explicit modification of ExtendedDTraceProbes by 1.114 + * a call to set_extended_dprobes. 1.115 + */ 1.116 + if (ExtendedDTraceProbes) { 1.117 + enable_dprobes(DTRACE_ALL_PROBES); 1.118 + } else { 1.119 + disable_dprobes(DTRACE_ALL_PROBES); 1.120 + } 1.121 +} 1.122 + 1.123 +void DTrace::set_extended_dprobes(bool flag) { 1.124 + // explicit setting of ExtendedDTraceProbes flag 1.125 + set_bool_flag("ExtendedDTraceProbes", flag); 1.126 + 1.127 + // make sure that the fine grained flags reflect the change. 1.128 + if (flag) { 1.129 + enable_dprobes(DTRACE_ALL_PROBES); 1.130 + } else { 1.131 + /* 1.132 + * FIXME: Revisit this: currently all-client-detach detection 1.133 + * does not work and hence disabled. The following scheme does 1.134 + * not work. So, we have to disable fine-grained flags here. 1.135 + * 1.136 + * disable_dprobes call has to be delayed till next "detach all "event. 1.137 + * This is to be done so that concurrent DTrace clients that may 1.138 + * have enabled one or more fine grained dprobes and may be running 1.139 + * still. On "detach all" clients event, we would sync ExtendedDTraceProbes 1.140 + * with fine grained flags which would take care of disabling fine grained flags. 1.141 + */ 1.142 + disable_dprobes(DTRACE_ALL_PROBES); 1.143 + } 1.144 +} 1.145 + 1.146 +void DTrace::set_monitor_dprobes(bool flag) { 1.147 + // explicit setting of DTraceMonitorProbes flag 1.148 + set_bool_flag("DTraceMonitorProbes", flag); 1.149 +} 1.150 + 1.151 +#endif /* SOLARIS */