annotate src/share/vm/services/attachListener.hpp @ 18408:2c3666f44855

Truffle: initial commit of object API implementation
author Andreas Woess <andreas.woess@jku.at>
date Tue, 18 Nov 2014 23:19:43 +0100
parents 4ca6dc0799b6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
7951
8b46b0196eb0 8000692: Remove old KERNEL code
zgu
parents: 6856
diff changeset
2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_SERVICES_ATTACHLISTENER_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_SERVICES_ATTACHLISTENER_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "memory/allocation.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "utilities/debug.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "utilities/ostream.hpp"
8001
db9981fd3124 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 6856
diff changeset
31 #include "utilities/macros.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32
0
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // The AttachListener thread services a queue of operations that are enqueued
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // by client tools. Each operation is identified by a name and has up to 3
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // arguments. The operation name is mapped to a function which performs the
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // operation. The function is called with an outputStream which is can use to
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // write any result data (for examples the properties command serializes
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // properties names and values to the output stream). When the function
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // complets the result value and any result data is returned to the client
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // tool.
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 class AttachOperation;
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 typedef jint (*AttachOperationFunction)(AttachOperation* op, outputStream* out);
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 struct AttachOperationFunctionInfo {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 const char* name;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 AttachOperationFunction func;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 };
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 class AttachListener: AllStatic {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 public:
11139
2e8f19c2feef 7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents: 8003
diff changeset
53 static void vm_start() NOT_SERVICES_RETURN;
6854
fb19af007ffc 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 6197
diff changeset
54 static void init() NOT_SERVICES_RETURN;
fb19af007ffc 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 6197
diff changeset
55 static void abort() NOT_SERVICES_RETURN;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // invoke to perform clean-up tasks when all clients detach
6854
fb19af007ffc 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 6197
diff changeset
58 static void detachall() NOT_SERVICES_RETURN;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // indicates if the Attach Listener needs to be created at startup
6854
fb19af007ffc 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 6197
diff changeset
61 static bool init_at_startup() NOT_SERVICES_RETURN_(false);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // indicates if we have a trigger to start the Attach Listener
6854
fb19af007ffc 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 6197
diff changeset
64 static bool is_init_trigger() NOT_SERVICES_RETURN_(false);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
65
6854
fb19af007ffc 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 6197
diff changeset
66 #if !INCLUDE_SERVICES
0
a61af66fc99e Initial load
duke
parents:
diff changeset
67 static bool is_attach_supported() { return false; }
6854
fb19af007ffc 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 6197
diff changeset
68 #else
0
a61af66fc99e Initial load
duke
parents:
diff changeset
69 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
70 static volatile bool _initialized;
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
73 static bool is_initialized() { return _initialized; }
a61af66fc99e Initial load
duke
parents:
diff changeset
74 static void set_initialized() { _initialized = true; }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // indicates if this VM supports attach-on-demand
a61af66fc99e Initial load
duke
parents:
diff changeset
77 static bool is_attach_supported() { return !DisableAttachMechanism; }
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // platform specific initialization
a61af66fc99e Initial load
duke
parents:
diff changeset
80 static int pd_init();
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // platform specific operation
a61af66fc99e Initial load
duke
parents:
diff changeset
83 static AttachOperationFunctionInfo* pd_find_operation(const char* name);
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // platform specific flag change
a61af66fc99e Initial load
duke
parents:
diff changeset
86 static jint pd_set_flag(AttachOperation* op, outputStream* out);
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // platform specific detachall
a61af66fc99e Initial load
duke
parents:
diff changeset
89 static void pd_detachall();
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // platform specific data dump
a61af66fc99e Initial load
duke
parents:
diff changeset
92 static void pd_data_dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // dequeue the next operation
a61af66fc99e Initial load
duke
parents:
diff changeset
95 static AttachOperation* dequeue();
6854
fb19af007ffc 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 6197
diff changeset
96 #endif // !INCLUDE_SERVICES
0
a61af66fc99e Initial load
duke
parents:
diff changeset
97 };
a61af66fc99e Initial load
duke
parents:
diff changeset
98
6854
fb19af007ffc 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 6197
diff changeset
99 #if INCLUDE_SERVICES
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 2426
diff changeset
100 class AttachOperation: public CHeapObj<mtInternal> {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
101 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
102 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 name_length_max = 16, // maximum length of name
a61af66fc99e Initial load
duke
parents:
diff changeset
104 arg_length_max = 1024, // maximum length of argument
a61af66fc99e Initial load
duke
parents:
diff changeset
105 arg_count_max = 3 // maximum number of arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
106 };
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // name of special operation that can be enqueued when all
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // clients detach
a61af66fc99e Initial load
duke
parents:
diff changeset
110 static char* detachall_operation_name() { return (char*)"detachall"; }
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
113 char _name[name_length_max+1];
a61af66fc99e Initial load
duke
parents:
diff changeset
114 char _arg[arg_count_max][arg_length_max+1];
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
117 const char* name() const { return _name; }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // set the operation name
a61af66fc99e Initial load
duke
parents:
diff changeset
120 void set_name(char* name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 assert(strlen(name) <= name_length_max, "exceeds maximum name length");
a61af66fc99e Initial load
duke
parents:
diff changeset
122 strcpy(_name, name);
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // get an argument value
a61af66fc99e Initial load
duke
parents:
diff changeset
126 const char* arg(int i) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 assert(i>=0 && i<arg_count_max, "invalid argument index");
a61af66fc99e Initial load
duke
parents:
diff changeset
128 return _arg[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // set an argument value
a61af66fc99e Initial load
duke
parents:
diff changeset
132 void set_arg(int i, char* arg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 assert(i>=0 && i<arg_count_max, "invalid argument index");
a61af66fc99e Initial load
duke
parents:
diff changeset
134 if (arg == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 _arg[i][0] = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
136 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 assert(strlen(arg) <= arg_length_max, "exceeds maximum argument length");
a61af66fc99e Initial load
duke
parents:
diff changeset
138 strcpy(_arg[i], arg);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // create an operation of a given name
a61af66fc99e Initial load
duke
parents:
diff changeset
143 AttachOperation(char* name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 set_name(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 for (int i=0; i<arg_count_max; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 set_arg(i, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // complete operation by sending result code and any result data to the client
a61af66fc99e Initial load
duke
parents:
diff changeset
151 virtual void complete(jint result, bufferedStream* result_stream) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
152 };
6854
fb19af007ffc 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 6197
diff changeset
153 #endif // INCLUDE_SERVICES
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
154
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
155 #endif // SHARE_VM_SERVICES_ATTACHLISTENER_HPP