8210031: implementation for JVM Constants API

Co-authored-by: Brian Goetz <brian.goetz@oracle.com>
Reviewed-by: jrose, mcimadamore, darcy, mchung, rriggs, dholmes, forax
This commit is contained in:
Vicente Romero 2018-12-09 12:36:24 -05:00
parent b80d335354
commit 9846588b31
72 changed files with 6719 additions and 103 deletions

View file

@ -26,8 +26,13 @@
package java.lang;
import java.lang.annotation.Native;
import java.lang.invoke.MethodHandles;
import java.lang.constant.Constable;
import java.lang.constant.ConstantDesc;
import java.math.*;
import java.util.Objects;
import java.util.Optional;
import jdk.internal.HotSpotIntrinsicCandidate;
import jdk.internal.misc.VM;
@ -57,7 +62,8 @@ import static java.lang.String.UTF16;
* @author Joseph D. Darcy
* @since 1.0
*/
public final class Long extends Number implements Comparable<Long> {
public final class Long extends Number
implements Comparable<Long>, Constable, ConstantDesc {
/**
* A constant holding the minimum value a {@code long} can
* have, -2<sup>63</sup>.
@ -1960,6 +1966,31 @@ public final class Long extends Number implements Comparable<Long> {
return Math.min(a, b);
}
/**
* Returns a nominal descriptor for this instance, which is the instance
* itself.
*
* @return an {@link Optional} describing the {@linkplain Long} instance
* @since 12
*/
@Override
public Optional<Long> describeConstable() {
return Optional.of(this);
}
/**
* Resolves this instance as a {@link ConstantDesc}, the result of which is
* the instance itself.
*
* @param lookup ignored
* @return the {@linkplain Long} instance
* @since 12
*/
@Override
public Long resolveConstantDesc(MethodHandles.Lookup lookup) {
return this;
}
/** use serialVersionUID from JDK 1.0.2 for interoperability */
@Native private static final long serialVersionUID = 4290774380558885855L;
}