src/hotspot/share/prims/jvmtiTrace.cpp
author adinn
Fri, 05 Apr 2019 10:01:09 +0100
changeset 54439 d9b46b7de028
parent 53143 6b7240a24b56
permissions -rw-r--r--
8221477: Inject os/cpu-specific constants into Unsafe from JVM Summary: Initialize Unsafe os/cpu-specific constants using injection instead of native callouts Reviewed-by: stuefe, coleenp, dholmes, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
51614
36773a4fe3e7 8210235: JvmtiTrace::safe_get_current_thread_name is unsafe in debug builds
kbarrett
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1623
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1623
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1623
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
53143
6b7240a24b56 8216157: Enable inlining of java_lang_Class::is_primitive
redestad
parents: 51614
diff changeset
    26
#include "classfile/javaClasses.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "jvmtifiles/jvmtiEnv.hpp"
37992
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
    28
#include "logging/log.hpp"
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
    29
#include "logging/logConfiguration.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 27654
diff changeset
    30
#include "memory/resourceArea.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "prims/jvmtiTrace.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// class JvmtiTrace
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// Support for JVMTI tracing code
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// ------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// Usage:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//    -XX:TraceJVMTI=DESC,DESC,DESC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
//    DESC is   DOMAIN ACTION KIND
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
//    DOMAIN is function name
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//              event name
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
//              "all" (all functions and events)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
//              "func" (all functions except boring)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
//              "allfunc" (all functions)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
//              "event" (all events)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
//              "ec" (event controller)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
//    ACTION is "+" (add)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
//              "-" (remove)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
//    KIND is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
//     for func
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
//              "i" (input params)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
//              "e" (error returns)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
//              "o" (output)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
//     for event
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
//              "t" (event triggered aka posted)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
//              "s" (event sent)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
// Example:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
//            -XX:TraceJVMTI=ec+,GetCallerFrame+ie,Breakpoint+s
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
#ifdef JVMTI_TRACE
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
bool JvmtiTrace::_initialized = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
bool JvmtiTrace::_on = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
bool JvmtiTrace::_trace_event_controller = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
void JvmtiTrace::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  if (_initialized) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  SafeResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  const char *very_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  const char *curr;
1402
ccb40ce62b79 6744783: HotSpot segfaults if given -XX options with an empty string argument
never
parents: 1
diff changeset
    81
  if (TraceJVMTI != NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    curr = TraceJVMTI;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    curr = "";  // hack in fixed tracing here
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  }
37992
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
    86
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
    87
  // Enable UL for JVMTI tracing
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
    88
  if (strlen(curr) > 0) {
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
    89
    if (!log_is_enabled(Trace, jvmti)) {
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
    90
      log_warning(arguments)("-XX:+TraceJVMTI specified, "
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
    91
         "but no log output configured for the 'jvmti' tag on Trace level. "
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
    92
         "Defaulting to -Xlog:jvmti=trace");
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
    93
      LogConfiguration::configure_stdout(LogLevel::Trace, true, LOG_TAGS(jvmti));
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
    94
    }
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
    95
  }
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
    96
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  very_end = curr + strlen(curr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  while (curr < very_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    const char *curr_end = strchr(curr, ',');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    if (curr_end == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
      curr_end = very_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    const char *op_pos = strchr(curr, '+');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    const char *minus_pos = strchr(curr, '-');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    if (minus_pos != NULL && (minus_pos < op_pos || op_pos == NULL)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      op_pos = minus_pos;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    char op;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    const char *flags = op_pos + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    const char *flags_end = curr_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    if (op_pos == NULL || op_pos > curr_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
      flags = "ies";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
      flags_end = flags + strlen(flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      op_pos = curr_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      op = '+';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      op = *op_pos;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    jbyte bits = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    for (; flags < flags_end; ++flags) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      switch (*flags) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
      case 'i':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
        bits |= SHOW_IN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      case 'I':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
        bits |= SHOW_IN_DETAIL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      case 'e':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
        bits |= SHOW_ERROR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      case 'o':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
        bits |= SHOW_OUT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      case 'O':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
        bits |= SHOW_OUT_DETAIL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      case 't':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
        bits |= SHOW_EVENT_TRIGGER;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      case 's':
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
        bits |= SHOW_EVENT_SENT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      default:
37992
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
   144
        log_warning(jvmti)("Invalid trace flag '%c'", *flags);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    const int FUNC = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    const int EXCLUDE  = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    const int ALL_FUNC = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    const int EVENT = 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    const int ALL_EVENT = 16;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    int domain = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    size_t len = op_pos - curr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    if (op_pos == curr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      domain = ALL_FUNC | FUNC | ALL_EVENT | EVENT | EXCLUDE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    } else if (len==3 && strncmp(curr, "all", 3)==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      domain = ALL_FUNC | FUNC | ALL_EVENT | EVENT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    } else if (len==7 && strncmp(curr, "allfunc", 7)==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      domain = ALL_FUNC | FUNC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    } else if (len==4 && strncmp(curr, "func", 4)==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      domain = ALL_FUNC | FUNC | EXCLUDE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    } else if (len==8 && strncmp(curr, "allevent", 8)==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      domain = ALL_EVENT | EVENT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    } else if (len==5 && strncmp(curr, "event", 5)==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      domain = ALL_EVENT | EVENT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    } else if (len==2 && strncmp(curr, "ec", 2)==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
      _trace_event_controller = true;
37992
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
   169
      log_trace(jvmti)("Tracing the event controller");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      domain = FUNC | EVENT;  // go searching
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    int exclude_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    if (domain & FUNC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      if (domain & ALL_FUNC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
        if (domain & EXCLUDE) {
37992
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
   178
          log_trace(jvmti)("Tracing all significant functions");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
        } else {
37992
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
   180
          log_trace(jvmti)("Tracing all functions");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
      for (int i = 0; i <= _max_function_index; ++i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
        if (domain & EXCLUDE && i == _exclude_functions[exclude_index]) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
          ++exclude_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
          bool do_op = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
          if (domain & ALL_FUNC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
            do_op = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
            const char *fname = function_name(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
            if (fname != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
              size_t fnlen = strlen(fname);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
              if (len==fnlen && strncmp(curr, fname, fnlen)==0) {
37992
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
   195
                log_trace(jvmti)("Tracing the function: %s", fname);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
                do_op = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
          if (do_op) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
            if (op == '+') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
              _trace_flags[i] |= bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
              _trace_flags[i] &= ~bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
            _on = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    if (domain & EVENT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
      if (domain & ALL_EVENT) {
37992
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
   213
        log_trace(jvmti)("Tracing all events");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      for (int i = 0; i <= _max_event_index; ++i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
        bool do_op = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
        if (domain & ALL_EVENT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
          do_op = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
          const char *ename = event_name(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
          if (ename != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
            size_t evtlen = strlen(ename);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
            if (len==evtlen && strncmp(curr, ename, evtlen)==0) {
37992
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
   224
              log_trace(jvmti)("Tracing the event: %s", ename);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
              do_op = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
        if (do_op) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
          if (op == '+') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
            _event_trace_flags[i] |= bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
            _event_trace_flags[i] &= ~bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
          _on = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    if (!_on && (domain & (FUNC|EVENT))) {
37992
c7ec6a3275f7 8154041: JVMTI trace to Unified Logging
rehn
parents: 37248
diff changeset
   240
      log_warning(jvmti)("Trace domain not found");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    curr = curr_end + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  _initialized = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
void JvmtiTrace::shutdown() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  _on = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  _trace_event_controller = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  for (i = 0; i <= _max_function_index; ++i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    _trace_flags[i] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  for (i = 0; i <= _max_event_index; ++i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    _event_trace_flags[i] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
const char* JvmtiTrace::enum_name(const char** names, const jint* values, jint value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  for (int index = 0; names[index] != 0; ++index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    if (values[index] == value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
      return names[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  return "*INVALID-ENUM-VALUE*";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
// return a valid string no matter what state the thread is in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
const char *JvmtiTrace::safe_get_thread_name(Thread *thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  if (thread == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    return "NULL";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  if (!thread->is_Java_thread()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    return thread->name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  JavaThread *java_thread = (JavaThread *)thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  oop threadObj = java_thread->threadObj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  if (threadObj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    return "NULL";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  }
27654
4e508c2376f7 8059677: Thread.getName() instantiates Strings
shade
parents: 14488
diff changeset
   284
  oop name = java_lang_Thread::name(threadObj);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  if (name == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    return "<NOT FILLED IN>";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  }
27654
4e508c2376f7 8059677: Thread.getName() instantiates Strings
shade
parents: 14488
diff changeset
   288
  return java_lang_String::as_utf8_string(name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
// return the name of the current thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
const char *JvmtiTrace::safe_get_current_thread_name() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  if (JvmtiEnv::is_vm_live()) {
51614
36773a4fe3e7 8210235: JvmtiTrace::safe_get_current_thread_name is unsafe in debug builds
kbarrett
parents: 47216
diff changeset
   295
    return JvmtiTrace::safe_get_thread_name(Thread::current_or_null());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    return "VM not live";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
// return a valid string no matter what the state of k_mirror
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
const char * JvmtiTrace::get_class_name(oop k_mirror) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  if (java_lang_Class::is_primitive(k_mirror)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    return "primitive";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
   306
  Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  if (k_oop == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    return "INVALID";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  }
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 13728
diff changeset
   310
  return k_oop->external_name();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
#endif /*JVMTI_TRACE */