equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2016, 2019, 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. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
24 */ |
24 */ |
25 |
25 |
26 package jdk.jfr.internal; |
26 package jdk.jfr.internal; |
27 |
27 |
28 import jdk.internal.misc.Unsafe; |
28 import jdk.internal.misc.Unsafe; |
29 import jdk.jfr.internal.consumer.RecordingInput; |
29 import jdk.jfr.internal.consumer.StringParser; |
30 |
30 |
31 /** |
31 /** |
32 * Class must reside in a package with package restriction. |
32 * Class must reside in a package with package restriction. |
33 * |
33 * |
34 * Users should not have direct access to underlying memory. |
34 * Users should not have direct access to underlying memory. |
113 } |
113 } |
114 } |
114 } |
115 |
115 |
116 public void putString(String s, StringPool pool) { |
116 public void putString(String s, StringPool pool) { |
117 if (s == null) { |
117 if (s == null) { |
118 putByte(RecordingInput.STRING_ENCODING_NULL); |
118 putByte(StringParser.Encoding.NULL.byteValue()); |
119 return; |
119 return; |
120 } |
120 } |
121 int length = s.length(); |
121 int length = s.length(); |
122 if (length == 0) { |
122 if (length == 0) { |
123 putByte(RecordingInput.STRING_ENCODING_EMPTY_STRING); |
123 putByte(StringParser.Encoding.EMPTY_STRING.byteValue()); |
124 return; |
124 return; |
125 } |
125 } |
126 if (length > StringPool.MIN_LIMIT && length < StringPool.MAX_LIMIT) { |
126 if (length > StringPool.MIN_LIMIT && length < StringPool.MAX_LIMIT) { |
127 long l = StringPool.addString(s); |
127 long l = StringPool.addString(s); |
128 if (l > 0) { |
128 if (l > 0) { |
129 putByte(RecordingInput.STRING_ENCODING_CONSTANT_POOL); |
129 putByte(StringParser.Encoding.CONSTANT_POOL.byteValue()); |
130 putLong(l); |
130 putLong(l); |
131 return; |
131 return; |
132 } |
132 } |
133 } |
133 } |
134 putStringValue(s); |
134 putStringValue(s); |
136 } |
136 } |
137 |
137 |
138 private void putStringValue(String s) { |
138 private void putStringValue(String s) { |
139 int length = s.length(); |
139 int length = s.length(); |
140 if (isValidForSize(1 + 5 + 3 * length)) { |
140 if (isValidForSize(1 + 5 + 3 * length)) { |
141 putUncheckedByte(RecordingInput.STRING_ENCODING_CHAR_ARRAY); // 1 byte |
141 putUncheckedByte(StringParser.Encoding.CHAR_ARRAY.byteValue()); // 1 byte |
142 putUncheckedInt(length); // max 5 bytes |
142 putUncheckedInt(length); // max 5 bytes |
143 for (int i = 0; i < length; i++) { |
143 for (int i = 0; i < length; i++) { |
144 putUncheckedChar(s.charAt(i)); // max 3 bytes |
144 putUncheckedChar(s.charAt(i)); // max 3 bytes |
145 } |
145 } |
146 } |
146 } |
195 return false; |
195 return false; |
196 } |
196 } |
197 if (currentPosition + requestedSize > maxPosition) { |
197 if (currentPosition + requestedSize > maxPosition) { |
198 flushOnEnd = flush(usedSize(), requestedSize); |
198 flushOnEnd = flush(usedSize(), requestedSize); |
199 // retry |
199 // retry |
200 if (currentPosition + requestedSize > maxPosition) { |
200 if (!valid) { |
201 Logger.log(LogTag.JFR_SYSTEM, |
|
202 LogLevel.WARN, () -> |
|
203 "Unable to commit. Requested size " + requestedSize + " too large"); |
|
204 valid = false; |
|
205 return false; |
201 return false; |
206 } |
202 } |
207 } |
203 } |
208 return true; |
204 return true; |
209 } |
205 } |