src/share/vm/services/attachListener.hpp

Tue, 31 Dec 2013 08:58:08 -0500

author
zgu
date
Tue, 31 Dec 2013 08:58:08 -0500
changeset 9313
fd0ca2c1433b
parent 5412
2e8f19c2feef
child 9448
73d689add964
permissions
-rw-r--r--

6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
Summary: Fixed incompatible uses of EXCEPTION_MARK and CHECK macros in AttachListener::init(), handle exception locally.
Reviewed-by: minqi, coleenp

     1 /*
     2  * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #ifndef SHARE_VM_SERVICES_ATTACHLISTENER_HPP
    26 #define SHARE_VM_SERVICES_ATTACHLISTENER_HPP
    28 #include "memory/allocation.hpp"
    29 #include "utilities/debug.hpp"
    30 #include "utilities/ostream.hpp"
    31 #include "utilities/macros.hpp"
    33 // The AttachListener thread services a queue of operations that are enqueued
    34 // by client tools. Each operation is identified by a name and has up to 3
    35 // arguments. The operation name is mapped to a function which performs the
    36 // operation. The function is called with an outputStream which is can use to
    37 // write any result data (for examples the properties command serializes
    38 // properties names and values to the output stream). When the function
    39 // complets the result value and any result data is returned to the client
    40 // tool.
    42 class AttachOperation;
    44 typedef jint (*AttachOperationFunction)(AttachOperation* op, outputStream* out);
    46 struct AttachOperationFunctionInfo {
    47   const char* name;
    48   AttachOperationFunction func;
    49 };
    51 class AttachListener: AllStatic {
    52  public:
    53   static void vm_start() NOT_SERVICES_RETURN;
    54   static void init()  NOT_SERVICES_RETURN;
    55   static void abort() NOT_SERVICES_RETURN;
    57   // invoke to perform clean-up tasks when all clients detach
    58   static void detachall() NOT_SERVICES_RETURN;
    60   // indicates if the Attach Listener needs to be created at startup
    61   static bool init_at_startup() NOT_SERVICES_RETURN_(false);
    63   // indicates if we have a trigger to start the Attach Listener
    64   static bool is_init_trigger() NOT_SERVICES_RETURN_(false);
    66 #if !INCLUDE_SERVICES
    67   static bool is_attach_supported()             { return false; }
    68 #else
    69  private:
    70   static volatile bool _initialized;
    72  public:
    73   static bool is_initialized()                  { return _initialized; }
    74   static void set_initialized()                 { _initialized = true; }
    76   // indicates if this VM supports attach-on-demand
    77   static bool is_attach_supported()             { return !DisableAttachMechanism; }
    79   // platform specific initialization
    80   static int pd_init();
    82   // platform specific operation
    83   static AttachOperationFunctionInfo* pd_find_operation(const char* name);
    85   // platform specific flag change
    86   static jint pd_set_flag(AttachOperation* op, outputStream* out);
    88   // platform specific detachall
    89   static void pd_detachall();
    91   // platform specific data dump
    92   static void pd_data_dump();
    94   // dequeue the next operation
    95   static AttachOperation* dequeue();
    96 #endif // !INCLUDE_SERVICES
    98  private:
    99   static bool has_init_error(TRAPS);
   100 };
   102 #if INCLUDE_SERVICES
   103 class AttachOperation: public CHeapObj<mtInternal> {
   104  public:
   105   enum {
   106     name_length_max = 16,       // maximum length of  name
   107     arg_length_max = 1024,      // maximum length of argument
   108     arg_count_max = 3           // maximum number of arguments
   109   };
   111   // name of special operation that can be enqueued when all
   112   // clients detach
   113   static char* detachall_operation_name() { return (char*)"detachall"; }
   115  private:
   116   char _name[name_length_max+1];
   117   char _arg[arg_count_max][arg_length_max+1];
   119  public:
   120   const char* name() const                      { return _name; }
   122   // set the operation name
   123   void set_name(char* name) {
   124     assert(strlen(name) <= name_length_max, "exceeds maximum name length");
   125     strcpy(_name, name);
   126   }
   128   // get an argument value
   129   const char* arg(int i) const {
   130     assert(i>=0 && i<arg_count_max, "invalid argument index");
   131     return _arg[i];
   132   }
   134   // set an argument value
   135   void set_arg(int i, char* arg) {
   136     assert(i>=0 && i<arg_count_max, "invalid argument index");
   137     if (arg == NULL) {
   138       _arg[i][0] = '\0';
   139     } else {
   140       assert(strlen(arg) <= arg_length_max, "exceeds maximum argument length");
   141       strcpy(_arg[i], arg);
   142     }
   143   }
   145   // create an operation of a given name
   146   AttachOperation(char* name) {
   147     set_name(name);
   148     for (int i=0; i<arg_count_max; i++) {
   149       set_arg(i, NULL);
   150     }
   151   }
   153   // complete operation by sending result code and any result data to the client
   154   virtual void complete(jint result, bufferedStream* result_stream) = 0;
   155 };
   156 #endif // INCLUDE_SERVICES
   158 #endif // SHARE_VM_SERVICES_ATTACHLISTENER_HPP

mercurial