Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/MachineDescriptionTwosComplement.java
41161 views
/*1* Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324package sun.jvm.hotspot.debugger;2526/** Base class for all twos-complement machine descriptions, which27handles the cIntegerType{Min,Max}Value methods. */2829public abstract class MachineDescriptionTwosComplement {3031/** Handles 1, 2, 4, and 8-byte signed integers */32private static final long[] signedMinValues = {33Byte.MIN_VALUE,34Short.MIN_VALUE,35Integer.MIN_VALUE,36Long.MIN_VALUE37};3839/** Handles 1, 2, 4, and 8-byte signed integers */40private static final long[] signedMaxValues = {41Byte.MAX_VALUE,42Short.MAX_VALUE,43Integer.MAX_VALUE,44Long.MAX_VALUE45};4647/** Handles 1, 2, and 4-byte unsigned integers properly, with a bug48in the 8-byte unsigned integer's constant */49private static final long[] unsignedMaxValues = {50255L,5165535L,524294967295L,53-1L54};5556public long cIntegerTypeMaxValue(long sizeInBytes, boolean isUnsigned) {57if (isUnsigned) {58// Would be nice to signal to the caller that 8-byte unsigned59// integers are not supported properly, but it looks like doing60// so at this level will cause problems above6162return tableLookup(sizeInBytes, unsignedMaxValues);63} else {64return tableLookup(sizeInBytes, signedMaxValues);65}66};6768public long cIntegerTypeMinValue(long sizeInBytes, boolean isUnsigned) {69if (isUnsigned) {70return 0;71}7273return tableLookup(sizeInBytes, signedMinValues);74}7576// Nearly all of the supported machines are not LP64 */77public boolean isLP64() {78return false;79}8081private long tableLookup(long sizeInBytes, long[] table) {82switch ((int) sizeInBytes) {83case 1:84return table[0];85case 2:86return table[1];87case 4:88return table[2];89case 8:90return table[3];91default:92throw new IllegalArgumentException("C integer type of " + sizeInBytes + " not supported");93}94}95}969798