equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
25 #ifndef SHARE_VM_SERVICES_ATTACHLISTENER_HPP |
25 #ifndef SHARE_VM_SERVICES_ATTACHLISTENER_HPP |
26 #define SHARE_VM_SERVICES_ATTACHLISTENER_HPP |
26 #define SHARE_VM_SERVICES_ATTACHLISTENER_HPP |
27 |
27 |
28 #include "memory/allocation.hpp" |
28 #include "memory/allocation.hpp" |
29 #include "utilities/debug.hpp" |
29 #include "utilities/debug.hpp" |
|
30 #include "utilities/globalDefinitions.hpp" |
|
31 #include "utilities/macros.hpp" |
30 #include "utilities/ostream.hpp" |
32 #include "utilities/ostream.hpp" |
31 #include "utilities/macros.hpp" |
|
32 #include "utilities/globalDefinitions.hpp" |
|
33 |
33 |
34 // The AttachListener thread services a queue of operations that are enqueued |
34 // The AttachListener thread services a queue of operations that are enqueued |
35 // by client tools. Each operation is identified by a name and has up to 3 |
35 // by client tools. Each operation is identified by a name and has up to 3 |
36 // arguments. The operation name is mapped to a function which performs the |
36 // arguments. The operation name is mapped to a function which performs the |
37 // operation. The function is called with an outputStream which is can use to |
37 // operation. The function is called with an outputStream which is can use to |
120 public: |
120 public: |
121 const char* name() const { return _name; } |
121 const char* name() const { return _name; } |
122 |
122 |
123 // set the operation name |
123 // set the operation name |
124 void set_name(char* name) { |
124 void set_name(char* name) { |
125 size_t len = strlen(name); |
125 assert(strlen(name) <= name_length_max, "exceeds maximum name length"); |
126 assert(len <= name_length_max, "exceeds maximum name length"); |
126 size_t len = MIN2(strlen(name), (size_t)name_length_max); |
127 memcpy(_name, name, MIN2(len + 1, (size_t)name_length_max)); |
127 memcpy(_name, name, len); |
|
128 _name[len] = '\0'; |
128 } |
129 } |
129 |
130 |
130 // get an argument value |
131 // get an argument value |
131 const char* arg(int i) const { |
132 const char* arg(int i) const { |
132 assert(i>=0 && i<arg_count_max, "invalid argument index"); |
133 assert(i>=0 && i<arg_count_max, "invalid argument index"); |
137 void set_arg(int i, char* arg) { |
138 void set_arg(int i, char* arg) { |
138 assert(i>=0 && i<arg_count_max, "invalid argument index"); |
139 assert(i>=0 && i<arg_count_max, "invalid argument index"); |
139 if (arg == NULL) { |
140 if (arg == NULL) { |
140 _arg[i][0] = '\0'; |
141 _arg[i][0] = '\0'; |
141 } else { |
142 } else { |
142 size_t len = strlen(arg); |
143 assert(strlen(arg) <= arg_length_max, "exceeds maximum argument length"); |
143 assert(len <= arg_length_max, "exceeds maximum argument length"); |
144 size_t len = MIN2(strlen(arg), (size_t)arg_length_max); |
144 memcpy(_arg[i], arg, MIN2(len + 1, (size_t)arg_length_max)); |
145 memcpy(_arg[i], arg, len); |
|
146 _arg[i][len] = '\0'; |
145 } |
147 } |
146 } |
148 } |
147 |
149 |
148 // create an operation of a given name |
150 // create an operation of a given name |
149 AttachOperation(char* name) { |
151 AttachOperation(char* name) { |