equal
deleted
inserted
replaced
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.StringEncoding; |
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(StringEncoding.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(StringEncoding.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(StringEncoding.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(StringEncoding.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 } |