< prev index next >

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

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