Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/runtime/dtraceJSDT.cpp
32285 views
/*1* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "classfile/javaClasses.hpp"26#include "code/codeBlob.hpp"27#include "memory/allocation.hpp"28#include "prims/jvm.h"29#include "runtime/dtraceJSDT.hpp"30#include "runtime/jniHandles.hpp"31#include "runtime/os.hpp"32#include "utilities/exceptions.hpp"33#include "utilities/globalDefinitions.hpp"34#include "utilities/utf8.hpp"3536#ifdef HAVE_DTRACE_H3738jlong DTraceJSDT::activate(39jint version, jstring module_name, jint providers_count,40JVM_DTraceProvider* providers, TRAPS) {4142size_t count = 0;43RegisteredProbes* probes = NULL;4445if (!is_supported()) {46return 0;47}4849assert(module_name != NULL, "valid module name");50assert(providers != NULL, "valid provider array");5152for (int i = 0; i < providers_count; ++i) {53count += providers[i].probe_count;54}55probes = new RegisteredProbes(count);56count = 0;5758for (int i = 0; i < providers_count; ++i) {59assert(providers[i].name != NULL, "valid provider name");60assert(providers[i].probe_count == 0 || providers[i].probes != NULL,61"valid probe count");62for (int j = 0; j < providers[i].probe_count; ++j) {63JVM_DTraceProbe* probe = &(providers[i].probes[j]);64assert(probe != NULL, "valid probe");65assert(probe->method != NULL, "valid method");66assert(probe->name != NULL, "valid probe name");67assert(probe->function != NULL, "valid probe function spec");68methodHandle h_method =69methodHandle(THREAD, Method::resolve_jmethod_id(probe->method));70nmethod* nm = AdapterHandlerLibrary::create_dtrace_nmethod(h_method);71if (nm == NULL) {72delete probes;73THROW_MSG_0(vmSymbols::java_lang_RuntimeException(),74"Unable to register DTrace probes (CodeCache: no room for DTrace nmethods).");75}76h_method()->set_not_compilable();77h_method()->set_code(h_method, nm);78probes->nmethod_at_put(count++, nm);79}80}8182int handle = pd_activate((void*)probes,83module_name, providers_count, providers);84if (handle < 0) {85delete probes;86THROW_MSG_0(vmSymbols::java_lang_RuntimeException(),87"Unable to register DTrace probes (internal error).");88}89probes->set_helper_handle(handle);90return RegisteredProbes::toOpaqueProbes(probes);91}9293jboolean DTraceJSDT::is_probe_enabled(jmethodID method) {94Method* m = Method::resolve_jmethod_id(method);95return nativeInstruction_at(m->code()->trap_address())->is_dtrace_trap();96}9798void DTraceJSDT::dispose(OpaqueProbes probes) {99RegisteredProbes* p = RegisteredProbes::toRegisteredProbes(probes);100if (probes != -1 && p != NULL) {101pd_dispose(p->helper_handle());102delete p;103}104}105106jboolean DTraceJSDT::is_supported() {107return pd_is_supported();108}109110#else // HAVE_DTRACE_H111112jlong DTraceJSDT::activate(113jint version, jstring module_name, jint providers_count,114JVM_DTraceProvider* providers, TRAPS) {115return 0;116}117118jboolean DTraceJSDT::is_probe_enabled(jmethodID method) {119return false;120}121122void DTraceJSDT::dispose(OpaqueProbes probes) {123return;124}125126jboolean DTraceJSDT::is_supported() {127return false;128}129130#endif // ndef HAVE_DTRACE_H131132133