Sat, 12 Sep 2020 00:09:03 +0300
8236196: Improve string pooling
Reviewed-by: mgronlun, rehn, ahgross, jwilhelm, rhalade, mbalao, andrew
src/share/vm/jfr/writers/jfrWriterHost.inline.hpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/jfr/writers/jfrWriterHost.inline.hpp Tue Sep 22 13:09:39 2020 +0300 1.2 +++ b/src/share/vm/jfr/writers/jfrWriterHost.inline.hpp Sat Sep 12 00:09:03 2020 +0300 1.3 @@ -70,7 +70,8 @@ 1.4 inline void WriterHost<BE, IE, WriterPolicyImpl>::write(const T* value, size_t len) { 1.5 assert(value != NULL, "invariant"); 1.6 assert(len > 0, "invariant"); 1.7 - u1* const pos = ensure_size(sizeof(T) * len); 1.8 + // Might need T + 1 size 1.9 + u1* const pos = ensure_size(sizeof(T) * len + len); 1.10 if (pos) { 1.11 this->set_current_pos(write(value, len, pos)); 1.12 } 1.13 @@ -124,7 +125,8 @@ 1.14 inline void WriterHost<BE, IE, WriterPolicyImpl>::be_write(const T* value, size_t len) { 1.15 assert(value != NULL, "invariant"); 1.16 assert(len > 0, "invariant"); 1.17 - u1* const pos = ensure_size(sizeof(T) * len); 1.18 + // Might need T + 1 size 1.19 + u1* const pos = ensure_size(sizeof(T) * len + len); 1.20 if (pos) { 1.21 this->set_current_pos(BE::be_write(value, len, pos)); 1.22 } 1.23 @@ -137,10 +139,17 @@ 1.24 _compressed_integers(compressed_integers()) { 1.25 } 1.26 1.27 +// Extra size added as a safety cushion when dimensioning memory. 1.28 +// With varint encoding, the worst case is 1.29 +// associated with writing negative values. 1.30 +// For example, writing a negative s1 (-1) 1.31 +// will encode as 0xff 0x0f (2 bytes). 1.32 +static const size_t size_safety_cushion = 1; 1.33 + 1.34 template <typename BE, typename IE, typename WriterPolicyImpl > 1.35 template <typename StorageType> 1.36 inline WriterHost<BE, IE, WriterPolicyImpl>::WriterHost(StorageType* storage, size_t size) : 1.37 - WriterPolicyImpl(storage, size), 1.38 + WriterPolicyImpl(storage, size + size_safety_cushion), 1.39 _compressed_integers(compressed_integers()) { 1.40 } 1.41 1.42 @@ -150,30 +159,19 @@ 1.43 _compressed_integers(compressed_integers()) { 1.44 } 1.45 1.46 -// Extra size added as a safety cushion when dimensioning memory. 1.47 -// With varint encoding, the worst case is 1.48 -// associated with writing negative values. 1.49 -// For example, writing a negative s1 (-1) 1.50 -// will encode as 0xff 0x0f (2 bytes). 1.51 -// In this example, the sizeof(T) == 1 and length == 1, 1.52 -// but the implementation will need to dimension 1.53 -// 2 bytes for the encoding. 1.54 -// Hopefully, negative values should be relatively rare. 1.55 -static const size_t size_safety_cushion = 1; 1.56 - 1.57 template <typename BE, typename IE, typename WriterPolicyImpl> 1.58 -inline u1* WriterHost<BE, IE, WriterPolicyImpl>::ensure_size(size_t requested) { 1.59 +inline u1* WriterHost<BE, IE, WriterPolicyImpl>::ensure_size(size_t requested_size) { 1.60 if (!this->is_valid()) { 1.61 // cancelled 1.62 return NULL; 1.63 } 1.64 - if (this->available_size() < requested + size_safety_cushion) { 1.65 - if (!this->accommodate(this->used_size(), requested + size_safety_cushion)) { 1.66 + if (this->available_size() < requested_size) { 1.67 + if (!this->accommodate(this->used_size(), requested_size)) { 1.68 this->cancel(); 1.69 return NULL; 1.70 } 1.71 } 1.72 - assert(requested + size_safety_cushion <= this->available_size(), "invariant"); 1.73 + assert(requested_size <= this->available_size(), "invariant"); 1.74 return this->current_pos(); 1.75 } 1.76