< prev index next >

test/micro/org/openjdk/bench/java/lang/foreign/StrLenTest.java

Print this page

138 
139     static String makeString(int size) {
140         String lorem = """
141                 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
142                  dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
143                  ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
144                  fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
145                  mollit anim id est laborum.
146                 """;
147         while (lorem.length() < size) {
148             lorem += lorem;
149         }
150         return lorem.substring(0, size);
151     }
152 
153     static class RingAllocator implements SegmentAllocator {
154         final MemorySegment segment;
155         SegmentAllocator current;
156         long rem;
157 

158         public RingAllocator(Arena session, int size) {
159             this.segment = session.allocate(size, 1);
160             reset();
161         }
162 
163         @Override
164         public MemorySegment allocate(long byteSize, long byteAlignment) {
165             if (rem < byteSize) {
166                 reset();
167             }
168             MemorySegment res = current.allocate(byteSize, byteAlignment);
169             long lastOffset = res.address() - segment.address() + res.byteSize();
170             rem = segment.byteSize() - lastOffset;
171             return res;
172         }
173 
174         void reset() {
175             current = SegmentAllocator.slicingAllocator(segment);
176             rem = segment.byteSize();
177         }

138 
139     static String makeString(int size) {
140         String lorem = """
141                 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
142                  dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
143                  ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
144                  fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
145                  mollit anim id est laborum.
146                 """;
147         while (lorem.length() < size) {
148             lorem += lorem;
149         }
150         return lorem.substring(0, size);
151     }
152 
153     static class RingAllocator implements SegmentAllocator {
154         final MemorySegment segment;
155         SegmentAllocator current;
156         long rem;
157 
158         @SuppressWarnings("initialization")
159         public RingAllocator(Arena session, int size) {
160             this.segment = session.allocate(size, 1);
161             reset();
162         }
163 
164         @Override
165         public MemorySegment allocate(long byteSize, long byteAlignment) {
166             if (rem < byteSize) {
167                 reset();
168             }
169             MemorySegment res = current.allocate(byteSize, byteAlignment);
170             long lastOffset = res.address() - segment.address() + res.byteSize();
171             rem = segment.byteSize() - lastOffset;
172             return res;
173         }
174 
175         void reset() {
176             current = SegmentAllocator.slicingAllocator(segment);
177             rem = segment.byteSize();
178         }
< prev index next >