Mercurial > hg > graal-compiler
annotate src/share/vm/services/diagnosticArgument.hpp @ 12294:891687731b59
7009641: Don't fail VM when CodeCache is full
Summary: Allocation in the code cache returns NULL instead of failing the entire VM
Reviewed-by: kvn, iveresov
author | anoll |
---|---|
date | Tue, 24 Sep 2013 15:56:25 +0200 |
parents | d2a62e0f25eb |
children |
rev | line source |
---|---|
4133 | 1 /* |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
4133 | 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 */ | |
24 | |
25 #ifndef SHARE_VM_SERVICES_DIAGNOSTICARGUMENT_HPP | |
26 #define SHARE_VM_SERVICES_DIAGNOSTICARGUMENT_HPP | |
27 | |
28 #include "classfile/vmSymbols.hpp" | |
29 #include "memory/allocation.hpp" | |
30 #include "runtime/os.hpp" | |
31 #include "runtime/thread.hpp" | |
32 #include "utilities/exceptions.hpp" | |
33 | |
6197 | 34 class StringArrayArgument : public CHeapObj<mtInternal> { |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
35 private: |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
36 GrowableArray<char*>* _array; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
37 public: |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
38 StringArrayArgument() { |
6197 | 39 _array = new(ResourceObj::C_HEAP, mtInternal)GrowableArray<char *>(32, true); |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
40 assert(_array != NULL, "Sanity check"); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
41 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
42 void add(const char* str, size_t len) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
43 if (str != NULL) { |
6197 | 44 char* ptr = NEW_C_HEAP_ARRAY(char, len+1, mtInternal); |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
45 strncpy(ptr, str, len); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
46 ptr[len] = 0; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
47 _array->append(ptr); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
48 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
49 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
50 GrowableArray<char*>* array() { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
51 return _array; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
52 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
53 ~StringArrayArgument() { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
54 for (int i=0; i<_array->length(); i++) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
55 if(_array->at(i) != NULL) { // Safety check |
6197 | 56 FREE_C_HEAP_ARRAY(char, _array->at(i), mtInternal); |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
57 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
58 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
59 delete _array; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
60 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
61 }; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
62 |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
63 class NanoTimeArgument { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
64 public: |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
65 jlong _nanotime; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
66 jlong _time; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
67 char _unit[3]; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
68 }; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
69 |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
70 class MemorySizeArgument { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
71 public: |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
72 u8 _size; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
73 u8 _val; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
74 char _multiplier; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
75 }; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
76 |
4133 | 77 class GenDCmdArgument : public ResourceObj { |
78 protected: | |
79 GenDCmdArgument* _next; | |
80 const char* _name; | |
81 const char* _description; | |
82 const char* _type; | |
83 const char* _default_string; | |
84 bool _is_set; | |
85 bool _is_mandatory; | |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
86 bool _allow_multiple; |
4133 | 87 GenDCmdArgument(const char* name, const char* description, const char* type, |
88 const char* default_string, bool mandatory) { | |
89 _name = name; | |
90 _description = description; | |
91 _type = type; | |
92 _default_string = default_string; | |
93 _is_mandatory = mandatory; | |
94 _is_set = false; | |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
95 _allow_multiple = false; |
4133 | 96 }; |
97 public: | |
98 const char* name() { return _name; } | |
99 const char* description() { return _description; } | |
100 const char* type() { return _type; } | |
101 const char* default_string() { return _default_string; } | |
102 bool is_set() { return _is_set; } | |
103 void set_is_set(bool b) { _is_set = b; } | |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4133
diff
changeset
|
104 bool allow_multiple() { return _allow_multiple; } |
4133 | 105 bool is_mandatory() { return _is_mandatory; } |
106 bool has_value() { return _is_set || _default_string != NULL; } | |
107 bool has_default() { return _default_string != NULL; } | |
108 void read_value(const char* str, size_t len, TRAPS); | |
109 virtual void parse_value(const char* str, size_t len, TRAPS) = 0; | |
110 virtual void init_value(TRAPS) = 0; | |
111 virtual void reset(TRAPS) = 0; | |
112 virtual void cleanup() = 0; | |
5978
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
113 virtual void value_as_str(char* buf, size_t len) = 0; |
4133 | 114 void set_next(GenDCmdArgument* arg) { |
115 _next = arg; | |
116 } | |
117 GenDCmdArgument* next() { | |
118 return _next; | |
119 } | |
5978
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
120 |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
121 void to_string(jlong l, char* buf, size_t len); |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
122 void to_string(bool b, char* buf, size_t len); |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
123 void to_string(char* c, char* buf, size_t len); |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
124 void to_string(NanoTimeArgument n, char* buf, size_t len); |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
125 void to_string(MemorySizeArgument f, char* buf, size_t len); |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
126 void to_string(StringArrayArgument* s, char* buf, size_t len); |
4133 | 127 }; |
128 | |
129 template <class ArgType> class DCmdArgument: public GenDCmdArgument { | |
130 private: | |
131 ArgType _value; | |
132 public: | |
133 DCmdArgument(const char* name, const char* description, const char* type, | |
134 bool mandatory) : | |
135 GenDCmdArgument(name, description, type, NULL, mandatory) { } | |
136 DCmdArgument(const char* name, const char* description, const char* type, | |
137 bool mandatory, const char* defaultvalue) : | |
138 GenDCmdArgument(name, description, type, defaultvalue, mandatory) | |
139 { } | |
140 ~DCmdArgument() { destroy_value(); } | |
141 ArgType value() { return _value;} | |
142 void set_value(ArgType v) { _value = v; } | |
143 void reset(TRAPS) { | |
144 destroy_value(); | |
145 init_value(CHECK); | |
146 _is_set = false; | |
147 } | |
148 void cleanup() { | |
149 destroy_value(); | |
150 } | |
151 void parse_value(const char* str, size_t len, TRAPS); | |
152 void init_value(TRAPS); | |
153 void destroy_value(); | |
5978
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
154 void value_as_str(char *buf, size_t len) { return to_string(_value, buf, len);} |
4133 | 155 }; |
156 | |
157 #endif /* SHARE_VM_SERVICES_DIAGNOSTICARGUMENT_HPP */ |