< prev index next >

test/hotspot/jtreg/gc/stress/gcbasher/ConstantPoolEntry.java

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

@@ -22,40 +22,43 @@
   *
   */
  
  package gc.stress.gcbasher;
  
+ import java.util.Optional;
+ 
+ @jdk.test.lib.valueclass.AsValueClass
  class ConstantPoolEntry {
-     private int index;
-     private String value;
+     private Optional<Integer> index;
+     private Optional<String> value;
  
-     public ConstantPoolEntry(int index) {
-         this.index = index;
-         value = null;
+     public ConstantPoolEntry(Integer index) {
+         this.index = Optional.of(index);
+         value = Optional.empty();
      }
  
      public ConstantPoolEntry(String value) {
-         this.index = -1;
-         this.value = value;
+         this.index = Optional.empty();
+         this.value = Optional.of(value);
      }
  
      public String getValue() throws IllegalStateException {
-         if (index != -1) {
+         if (index.isPresent()) {
              throw new IllegalStateException();
          }
-         return value;
+         return value.get();
      }
  
-     public int getNameIndex() throws IllegalStateException {
-         if (value != null) {
+     public Integer getNameIndex() throws IllegalStateException {
+         if (value.isPresent()) {
              throw new IllegalStateException();
          }
-         return index;
+         return index.get();
      }
  
-     public int getClassIndex() throws IllegalStateException {
-         if (value != null) {
+     public Integer getClassIndex() throws IllegalStateException {
+         if (value.isPresent()) {
              throw new IllegalStateException();
          }
-         return index;
+         return index.get();
      }
  }
< prev index next >