001/* 002 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package com.oracle.graal.hotspot.replacements; 024 025import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; 026 027import com.oracle.graal.api.replacements.*; 028import com.oracle.graal.hotspot.word.*; 029import com.oracle.graal.word.*; 030 031import sun.reflect.*; 032 033/** 034 * Substitutions for {@link sun.reflect.ConstantPool} methods. 035 */ 036@ClassSubstitution(sun.reflect.ConstantPool.class) 037public class ConstantPoolSubstitutions { 038 039 /** 040 * Get the metaspace {@code ConstantPool} pointer for the given holder class. 041 * 042 * @param constantPoolOop the holder class as {@link Object} 043 * @return a metaspace {@code ConstantPool} pointer 044 */ 045 private static Word metaspaceConstantPool(Object constantPoolOop) { 046 // ConstantPool.constantPoolOop is in fact the holder class. 047 Class<?> constantPoolHolder = (Class<?>) constantPoolOop; 048 KlassPointer klass = ClassGetHubNode.readClass(constantPoolHolder); 049 return klass.readWord(instanceKlassConstantsOffset(), INSTANCE_KLASS_CONSTANTS); 050 } 051 052 @MethodSubstitution(isStatic = false) 053 private static int getSize0(@SuppressWarnings("unused") final ConstantPool thisObj, Object constantPoolOop) { 054 return metaspaceConstantPool(constantPoolOop).readInt(constantPoolLengthOffset()); 055 } 056 057 @MethodSubstitution(isStatic = false) 058 private static int getIntAt0(@SuppressWarnings("unused") final ConstantPool thisObj, Object constantPoolOop, int index) { 059 return metaspaceConstantPool(constantPoolOop).readInt(constantPoolSize() + index * wordSize()); 060 } 061 062 @MethodSubstitution(isStatic = false) 063 private static long getLongAt0(@SuppressWarnings("unused") final ConstantPool thisObj, Object constantPoolOop, int index) { 064 return metaspaceConstantPool(constantPoolOop).readLong(constantPoolSize() + index * wordSize()); 065 } 066 067 @MethodSubstitution(isStatic = false) 068 private static float getFloatAt0(@SuppressWarnings("unused") final ConstantPool thisObj, Object constantPoolOop, int index) { 069 return metaspaceConstantPool(constantPoolOop).readFloat(constantPoolSize() + index * wordSize()); 070 } 071 072 @MethodSubstitution(isStatic = false) 073 private static double getDoubleAt0(@SuppressWarnings("unused") final ConstantPool thisObj, Object constantPoolOop, int index) { 074 return metaspaceConstantPool(constantPoolOop).readDouble(constantPoolSize() + index * wordSize()); 075 } 076 077}