src/hotspot/share/services/attachListener.hpp
author dholmes
Sat, 23 Jun 2018 01:32:41 -0400
changeset 50735 2f2af62dfac7
parent 49406 f654b37c58a1
child 53244 9807daeb47c4
permissions -rw-r--r--
8010319: Implementation of JEP 181: Nest-Based Access Control Reviewed-by: alanb, psandoz, mchung, coleenp, acorn, mcimadamore, forax, jlahoda, sspitsyn, abuckley Contributed-by: alex.buckley@oracle.com, maurizio.mimadamore@oracle.com, mandy.chung@oracle.com, tobias.hartmann@oracle.com, david.holmes@oracle.com, vladimir.x.ivanov@oracle.com, karen.kinnear@oracle.com, vladimir.kozlov@oracle.com, john.r.rose@oracle.com, daniel.smith@oracle.com, serguei.spitsyn@oracle.com, kumardotsrinivasan@gmail.com, boris.ulasevich@bell-sw.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49406
f654b37c58a1 8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents: 47216
diff changeset
     2
 * Copyright (c) 2005, 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: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
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: 1
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
#ifndef SHARE_VM_SERVICES_ATTACHLISTENER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_SERVICES_ATTACHLISTENER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "utilities/debug.hpp"
49406
f654b37c58a1 8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents: 47216
diff changeset
    30
#include "utilities/globalDefinitions.hpp"
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 13977
diff changeset
    31
#include "utilities/macros.hpp"
49406
f654b37c58a1 8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents: 47216
diff changeset
    32
#include "utilities/ostream.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// The AttachListener thread services a queue of operations that are enqueued
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// by client tools. Each operation is identified by a name and has up to 3
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// arguments. The operation name is mapped to a function which performs the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// operation. The function is called with an outputStream which is can use to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// write any result data (for examples the properties command serializes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// properties names and values to the output stream). When the function
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// complets the result value and any result data is returned to the client
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// tool.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
class AttachOperation;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
typedef jint (*AttachOperationFunction)(AttachOperation* op, outputStream* out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
struct AttachOperationFunctionInfo {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  const char* name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  AttachOperationFunction func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
class AttachListener: AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
 public:
18931
5de3638104b4 7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents: 15484
diff changeset
    54
  static void vm_start() NOT_SERVICES_RETURN;
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13195
diff changeset
    55
  static void init()  NOT_SERVICES_RETURN;
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13195
diff changeset
    56
  static void abort() NOT_SERVICES_RETURN;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // invoke to perform clean-up tasks when all clients detach
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13195
diff changeset
    59
  static void detachall() NOT_SERVICES_RETURN;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // indicates if the Attach Listener needs to be created at startup
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13195
diff changeset
    62
  static bool init_at_startup() NOT_SERVICES_RETURN_(false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // indicates if we have a trigger to start the Attach Listener
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13195
diff changeset
    65
  static bool is_init_trigger() NOT_SERVICES_RETURN_(false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13195
diff changeset
    67
#if !INCLUDE_SERVICES
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  static bool is_attach_supported()             { return false; }
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13195
diff changeset
    69
#else
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  static volatile bool _initialized;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  static bool is_initialized()                  { return _initialized; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  static void set_initialized()                 { _initialized = true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // indicates if this VM supports attach-on-demand
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  static bool is_attach_supported()             { return !DisableAttachMechanism; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // platform specific initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  static int pd_init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // platform specific operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  static AttachOperationFunctionInfo* pd_find_operation(const char* name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  // platform specific flag change
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  static jint pd_set_flag(AttachOperation* op, outputStream* out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // platform specific detachall
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  static void pd_detachall();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // platform specific data dump
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  static void pd_data_dump();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // dequeue the next operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  static AttachOperation* dequeue();
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13195
diff changeset
    97
#endif // !INCLUDE_SERVICES
22197
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 18931
diff changeset
    98
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 18931
diff changeset
    99
 private:
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 18931
diff changeset
   100
  static bool has_init_error(TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13195
diff changeset
   103
#if INCLUDE_SERVICES
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   104
class AttachOperation: public CHeapObj<mtInternal> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    name_length_max = 16,       // maximum length of  name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    arg_length_max = 1024,      // maximum length of argument
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    arg_count_max = 3           // maximum number of arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // name of special operation that can be enqueued when all
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  // clients detach
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  static char* detachall_operation_name() { return (char*)"detachall"; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  char _name[name_length_max+1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  char _arg[arg_count_max][arg_length_max+1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  const char* name() const                      { return _name; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  // set the operation name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  void set_name(char* name) {
49406
f654b37c58a1 8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents: 47216
diff changeset
   125
    assert(strlen(name) <= name_length_max, "exceeds maximum name length");
f654b37c58a1 8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents: 47216
diff changeset
   126
    size_t len = MIN2(strlen(name), (size_t)name_length_max);
f654b37c58a1 8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents: 47216
diff changeset
   127
    memcpy(_name, name, len);
f654b37c58a1 8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents: 47216
diff changeset
   128
    _name[len] = '\0';
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // get an argument value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  const char* arg(int i) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    assert(i>=0 && i<arg_count_max, "invalid argument index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    return _arg[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  // set an argument value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  void set_arg(int i, char* arg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    assert(i>=0 && i<arg_count_max, "invalid argument index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    if (arg == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
      _arg[i][0] = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    } else {
49406
f654b37c58a1 8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents: 47216
diff changeset
   143
      assert(strlen(arg) <= arg_length_max, "exceeds maximum argument length");
f654b37c58a1 8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents: 47216
diff changeset
   144
      size_t len = MIN2(strlen(arg), (size_t)arg_length_max);
f654b37c58a1 8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents: 47216
diff changeset
   145
      memcpy(_arg[i], arg, len);
f654b37c58a1 8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents: 47216
diff changeset
   146
      _arg[i][len] = '\0';
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // create an operation of a given name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  AttachOperation(char* name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    set_name(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    for (int i=0; i<arg_count_max; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
      set_arg(i, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // complete operation by sending result code and any result data to the client
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  virtual void complete(jint result, bufferedStream* result_stream) = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
};
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13195
diff changeset
   161
#endif // INCLUDE_SERVICES
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   162
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   163
#endif // SHARE_VM_SERVICES_ATTACHLISTENER_HPP