116N/A/*
1879N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
116N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
116N/A *
116N/A * This code is free software; you can redistribute it and/or modify it
116N/A * under the terms of the GNU General Public License version 2 only, as
116N/A * published by the Free Software Foundation.
116N/A *
116N/A * This code is distributed in the hope that it will be useful, but WITHOUT
116N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
116N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
116N/A * version 2 for more details (a copy is included in the LICENSE file that
116N/A * accompanied this code).
116N/A *
116N/A * You should have received a copy of the GNU General Public License version
116N/A * 2 along with this work; if not, write to the Free Software Foundation,
116N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
116N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
116N/A *
116N/A */
116N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "classfile/javaClasses.hpp"
1879N/A#include "code/codeBlob.hpp"
1879N/A#include "memory/allocation.hpp"
1879N/A#include "prims/jvm.h"
1879N/A#include "runtime/dtraceJSDT.hpp"
1879N/A#include "runtime/jniHandles.hpp"
1879N/A#include "runtime/os.hpp"
1879N/A#include "utilities/exceptions.hpp"
1879N/A#include "utilities/globalDefinitions.hpp"
1879N/A#include "utilities/utf8.hpp"
116N/A
116N/A#ifdef HAVE_DTRACE_H
116N/A
116N/Ajlong DTraceJSDT::activate(
116N/A jint version, jstring module_name, jint providers_count,
116N/A JVM_DTraceProvider* providers, TRAPS) {
116N/A
116N/A size_t count = 0;
116N/A RegisteredProbes* probes = NULL;
116N/A
116N/A if (!is_supported()) {
116N/A return 0;
116N/A }
116N/A
116N/A assert(module_name != NULL, "valid module name");
116N/A assert(providers != NULL, "valid provider array");
116N/A
116N/A for (int i = 0; i < providers_count; ++i) {
116N/A count += providers[i].probe_count;
116N/A }
116N/A probes = new RegisteredProbes(count);
116N/A count = 0;
116N/A
116N/A for (int i = 0; i < providers_count; ++i) {
116N/A assert(providers[i].name != NULL, "valid provider name");
116N/A assert(providers[i].probe_count == 0 || providers[i].probes != NULL,
116N/A "valid probe count");
116N/A for (int j = 0; j < providers[i].probe_count; ++j) {
116N/A JVM_DTraceProbe* probe = &(providers[i].probes[j]);
116N/A assert(probe != NULL, "valid probe");
116N/A assert(probe->method != NULL, "valid method");
116N/A assert(probe->name != NULL, "valid probe name");
116N/A assert(probe->function != NULL, "valid probe function spec");
116N/A methodHandle h_method =
116N/A methodHandle(THREAD, JNIHandles::resolve_jmethod_id(probe->method));
116N/A nmethod* nm = AdapterHandlerLibrary::create_dtrace_nmethod(h_method);
742N/A if (nm == NULL) {
742N/A delete probes;
742N/A THROW_MSG_0(vmSymbols::java_lang_RuntimeException(),
742N/A "Unable to register DTrace probes (CodeCache: no room for DTrace nmethods).");
742N/A }
1703N/A h_method()->set_not_compilable();
116N/A h_method()->set_code(h_method, nm);
116N/A probes->nmethod_at_put(count++, nm);
116N/A }
116N/A }
116N/A
116N/A int handle = pd_activate((void*)probes,
116N/A module_name, providers_count, providers);
3216N/A if (handle < 0) {
116N/A delete probes;
116N/A THROW_MSG_0(vmSymbols::java_lang_RuntimeException(),
116N/A "Unable to register DTrace probes (internal error).");
116N/A }
116N/A probes->set_helper_handle(handle);
116N/A return RegisteredProbes::toOpaqueProbes(probes);
116N/A}
116N/A
116N/Ajboolean DTraceJSDT::is_probe_enabled(jmethodID method) {
116N/A methodOop m = JNIHandles::resolve_jmethod_id(method);
116N/A return nativeInstruction_at(m->code()->trap_address())->is_dtrace_trap();
116N/A}
116N/A
116N/Avoid DTraceJSDT::dispose(OpaqueProbes probes) {
116N/A RegisteredProbes* p = RegisteredProbes::toRegisteredProbes(probes);
116N/A if (probes != -1 && p != NULL) {
116N/A pd_dispose(p->helper_handle());
116N/A delete p;
116N/A }
116N/A}
116N/A
116N/Ajboolean DTraceJSDT::is_supported() {
116N/A return pd_is_supported();
116N/A}
116N/A
116N/A#else // HAVE_DTRACE_H
116N/A
116N/Ajlong DTraceJSDT::activate(
116N/A jint version, jstring module_name, jint providers_count,
116N/A JVM_DTraceProvider* providers, TRAPS) {
116N/A return 0;
116N/A}
116N/A
116N/Ajboolean DTraceJSDT::is_probe_enabled(jmethodID method) {
116N/A return false;
116N/A}
116N/A
116N/Avoid DTraceJSDT::dispose(OpaqueProbes probes) {
116N/A return;
116N/A}
116N/A
116N/Ajboolean DTraceJSDT::is_supported() {
116N/A return false;
116N/A}
116N/A
116N/A#endif // ndef HAVE_DTRACE_H