< prev index next >

src/jdk.unsupported/share/classes/sun/misc/Unsafe.java

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 2000, 2021, 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.  Oracle designates this
--- 1,7 ---
  /*
!  * Copyright (c) 2000, 2022, 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.  Oracle designates this

*** 23,16 ***
   * questions.
   */
  
  package sun.misc;
  
  import jdk.internal.vm.annotation.ForceInline;
  import jdk.internal.misc.VM;
  import jdk.internal.reflect.CallerSensitive;
  import jdk.internal.reflect.Reflection;
  
- import java.lang.invoke.MethodHandles;
  import java.lang.reflect.Field;
  import java.util.Set;
  
  
  /**
--- 23,16 ---
   * questions.
   */
  
  package sun.misc;
  
+ import jdk.internal.value.PrimitiveClass;
  import jdk.internal.vm.annotation.ForceInline;
  import jdk.internal.misc.VM;
  import jdk.internal.reflect.CallerSensitive;
  import jdk.internal.reflect.Reflection;
  
  import java.lang.reflect.Field;
  import java.util.Set;
  
  
  /**

*** 649,10 ***
--- 649,13 ---
          }
          Class<?> declaringClass = f.getDeclaringClass();
          if (declaringClass.isHidden()) {
              throw new UnsupportedOperationException("can't get field offset on a hidden class: " + f);
          }
+         if (PrimitiveClass.isPrimitiveClass(f.getDeclaringClass())) {
+             throw new UnsupportedOperationException("can't get field offset on a primitive class: " + f);
+         }
          if (declaringClass.isRecord()) {
              throw new UnsupportedOperationException("can't get field offset on a record class: " + f);
          }
          return theInternalUnsafe.objectFieldOffset(f);
      }

*** 688,10 ***
--- 691,13 ---
          }
          Class<?> declaringClass = f.getDeclaringClass();
          if (declaringClass.isHidden()) {
              throw new UnsupportedOperationException("can't get field offset on a hidden class: " + f);
          }
+         if (PrimitiveClass.isPrimitiveClass(f.getDeclaringClass())) {
+             throw new UnsupportedOperationException("can't get static field offset on a primitive class: " + f);
+         }
          if (declaringClass.isRecord()) {
              throw new UnsupportedOperationException("can't get field offset on a record class: " + f);
          }
          return theInternalUnsafe.staticFieldOffset(f);
      }

*** 719,10 ***
--- 725,13 ---
          }
          Class<?> declaringClass = f.getDeclaringClass();
          if (declaringClass.isHidden()) {
              throw new UnsupportedOperationException("can't get base address on a hidden class: " + f);
          }
+         if (PrimitiveClass.isPrimitiveClass(f.getDeclaringClass())) {
+             throw new UnsupportedOperationException("can't get base address on a primitive class: " + f);
+         }
          if (declaringClass.isRecord()) {
              throw new UnsupportedOperationException("can't get base address on a record class: " + f);
          }
          return theInternalUnsafe.staticFieldBase(f);
      }
< prev index next >