JDK-8232072 : getCurrentThreadAllocatedBytes default implementation s/b getThreadAllocatedBytes
  • Type: CSR
  • Component: core-svc
  • Sub-Component: java.lang.management
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 14
  • Submitted: 2019-10-09
  • Updated: 2020-11-30
  • Resolved: 2019-10-23
Related Reports
CSR :  
Relates :  
Description
Summary
-------

To match its abstract specification, change the default implementation of `com.sun.management.ThreadMXBean.getCurrentThreadAllocatedBytes`  to return the value of ` getThreadAllocatedBytes(Thread.currentThread().getId())`.

Problem
-------

The existing default implementation of `com.sun.management.ThreadMXBean.getCurrentThreadAllocatedBytes`   is to throw `UnsupportedOperationException`, which is permitted but doesn't match the abstract specification of the method.

Solution
--------

Change the default implementation of `com.sun.management.ThreadMXBean.getCurrentThreadAllocatedBytes`  to return the value of ` getThreadAllocatedBytes(Thread.currentThread().getId())`.

Remove the `@implSpec` portion of the Javadoc that described the throwing of the exception.

Specification
-------------
```
/**
 * Returns an approximation of the total amount of memory, in bytes,
 * allocated in heap memory for the current thread.
 * The returned value is an approximation because some Java virtual machine
 * implementations may use object allocation mechanisms that result in a
 * delay between the time an object is allocated and the time its size is
 * recorded.
 *
 * <p>
 * This is a convenience method for local management use and is
 * equivalent to calling:
 * <blockquote><pre>
 *   {@link #getThreadAllocatedBytes getThreadAllocatedBytes}(Thread.currentThread().getId());
 * </pre></blockquote>
 *
-* @implSpec The default implementation throws
-* {@code UnsupportedOperationException}.
-*
 * @return an approximation of the total memory allocated, in bytes, in
 * heap memory for the current thread
 * if thread memory allocation measurement is enabled;
 * {@code -1} otherwise.
 *
 * @throws java.lang.UnsupportedOperationException if the Java virtual
 *         machine implementation does not support thread memory allocation
 *         measurement.
 *
 * @see #isThreadAllocatedMemorySupported
 * @see #isThreadAllocatedMemoryEnabled
 * @see #setThreadAllocatedMemoryEnabled
 * @since 14
 */
public default long getCurrentThreadAllocatedBytes() {
    return getThreadAllocatedBytes(Thread.currentThread().getId());
}
```




Comments
@implSpec tag is normative though the class itself doesn't belong to JavaSE
24-10-2019

Moving to Approved.
23-10-2019

The type com.sun.management.ThreadMXBean is part of the default doc bundle and part of the JDK's API, although not part of Java SE. Changing the Scope field accordingly.
23-10-2019

Then the scope stays 'Implementation'.
23-10-2019

The specification is NOT being changed. Removing an implNote is not changing the specification - that's why we invented implNotes.
23-10-2019

What does 'SE' stand for? The scope of JDK-8231374, which is the CSR for JDK-8231209, is 'JDK'. Shall I make the scope of this CSR also 'JDK'?
23-10-2019

As specification is being changed the Scope is supposedly 'SE' ?
23-10-2019

Rewritten and reviewed. Please move to Finalized.
23-10-2019