/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import jdk.internal.misc.Unsafe;

class UnsafeMicroBenchmark extends MicroBenchmark {
  protected Unsafe theUnsafe;

  UnsafeMicroBenchmark() throws Throwable {
    Field f = Unsafe.class.getDeclaredField("theUnsafe");
    f.setAccessible(true);
    theUnsafe = (Unsafe) f.get(null);
  }

  protected long getFieldOffset(Field field) throws Throwable {
    return theUnsafe.objectFieldOffset(field);
  }

  protected long getStaticFieldOffset(Field staticField) throws Throwable {
    if (System.getProperty("java.vm.name").equals("Dalvik")) {
        // field.getOffset(); ()J
        Method m = Field.class.getDeclaredMethod("getOffset");
        return (Integer) m.invoke(staticField);
    } else {
        // theUnsafe.staticFieldOffset(field) (Ljava/lang/Field;)J
        Method m = Unsafe.class.getDeclaredMethod("staticFieldOffset", Field.class);
        return (Long) m.invoke(theUnsafe, staticField);
    }
  }
}