205 long reservedMem = RESERVED_MEMORY.addAndGet(-size); |
205 long reservedMem = RESERVED_MEMORY.addAndGet(-size); |
206 long totalCap = TOTAL_CAPACITY.addAndGet(-cap); |
206 long totalCap = TOTAL_CAPACITY.addAndGet(-cap); |
207 assert cnt >= 0 && reservedMem >= 0 && totalCap >= 0; |
207 assert cnt >= 0 && reservedMem >= 0 && totalCap >= 0; |
208 } |
208 } |
209 |
209 |
210 // -- Monitoring of direct buffer usage -- |
210 static final JavaNioAccess.BufferPool BUFFER_POOL = new JavaNioAccess.BufferPool() { |
211 |
211 @Override |
212 static { |
212 public String getName() { |
213 // setup access to this package in SharedSecrets |
213 return "direct"; |
214 SharedSecrets.setJavaNioAccess( |
214 } |
215 new JavaNioAccess() { |
215 @Override |
216 @Override |
216 public long getCount() { |
217 public JavaNioAccess.BufferPool getDirectBufferPool() { |
217 return Bits.COUNT.get(); |
218 return new JavaNioAccess.BufferPool() { |
218 } |
219 @Override |
219 @Override |
220 public String getName() { |
220 public long getTotalCapacity() { |
221 return "direct"; |
221 return Bits.TOTAL_CAPACITY.get(); |
222 } |
222 } |
223 @Override |
223 @Override |
224 public long getCount() { |
224 public long getMemoryUsed() { |
225 return Bits.COUNT.get(); |
225 return Bits.RESERVED_MEMORY.get(); |
226 } |
226 } |
227 @Override |
227 }; |
228 public long getTotalCapacity() { |
|
229 return Bits.TOTAL_CAPACITY.get(); |
|
230 } |
|
231 @Override |
|
232 public long getMemoryUsed() { |
|
233 return Bits.RESERVED_MEMORY.get(); |
|
234 } |
|
235 }; |
|
236 } |
|
237 @Override |
|
238 public ByteBuffer newDirectByteBuffer(long addr, int cap, Object ob) { |
|
239 return new DirectByteBuffer(addr, cap, ob); |
|
240 } |
|
241 @Override |
|
242 public void truncate(Buffer buf) { |
|
243 buf.truncate(); |
|
244 } |
|
245 }); |
|
246 } |
|
247 |
228 |
248 // These numbers represent the point at which we have empirically |
229 // These numbers represent the point at which we have empirically |
249 // determined that the average cost of a JNI call exceeds the expense |
230 // determined that the average cost of a JNI call exceeds the expense |
250 // of an element by element copy. These numbers may change over time. |
231 // of an element by element copy. These numbers may change over time. |
251 static final int JNI_COPY_TO_ARRAY_THRESHOLD = 6; |
232 static final int JNI_COPY_TO_ARRAY_THRESHOLD = 6; |