changeset 4450:d585b608bd78

more efficient methodData access
author Christian Haeubl <christian.haeubl@oracle.com>
date Fri, 27 Jan 2012 11:45:48 -0800
parents d84ccb0cc897
children defa1b705f14
files graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HOTSPOTMETHODDATAACCESSOR.JAVA graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HOTSPOTPROFILINGINFO.JAVA graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotMethodDataAccessor.java graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotProfilingInfo.java
diffstat 4 files changed, 188 insertions(+), 188 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HOTSPOTMETHODDATAACCESSOR.JAVA	Fri Jan 27 11:36:09 2012 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2011, 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.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.max.graal.hotspot.ri;
-
-import com.oracle.max.cri.ri.*;
-
-/**
- * Interface for accessor objects that encapsulate the logic for accessing the different kinds of data in a HotSpot methodDataOop.
- * This interface is similar to the interface {@link RiProfilingInfo}, but most methods require a MethodDataObject and the
- * exact position within the methodData.
- */
-public interface HotSpotMethodDataAccessor {
-    /**
-     * Returns the tag stored in the LayoutData header.
-     * @return An integer >= 0 or -1 if not supported.
-     */
-    int getTag();
-
-    /**
-     * Returns the BCI stored in the LayoutData header.
-     * @return An integer >= 0 and <= Short.MAX_VALUE, or -1 if not supported.
-     */
-    int getBCI(HotSpotMethodData data, int position);
-
-    /**
-     * Computes the size for the specific data at the given position.
-     * @return An integer > 0.
-     */
-    int getSize(HotSpotMethodData data, int position);
-
-    RiTypeProfile getTypeProfile(HotSpotMethodData data, int position);
-    double getBranchTakenProbability(HotSpotMethodData data, int position);
-    double[] getSwitchProbabilities(HotSpotMethodData data, int position);
-    boolean getImplicitExceptionSeen(HotSpotMethodData data, int position);
-    int getExecutionCount(HotSpotMethodData data, int position);
-}
--- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HOTSPOTPROFILINGINFO.JAVA	Fri Jan 27 11:36:09 2012 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,132 +0,0 @@
-/*
- * Copyright (c) 2012, 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.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.max.graal.hotspot.ri;
-
-import com.oracle.max.cri.ri.*;
-import com.oracle.max.graal.hotspot.*;
-import com.oracle.max.graal.hotspot.Compiler;
-
-
-public final class HotSpotProfilingInfo extends CompilerObject implements RiProfilingInfo {
-
-    /**
-     *
-     */
-    private static final long serialVersionUID = -8307682725047864875L;
-
-    private int position;
-    private int hintPosition;
-    private int hintBCI;
-    private HotSpotMethodDataAccessor dataAccessor;
-    private HotSpotMethodData methodData;
-
-    public HotSpotProfilingInfo(Compiler compiler, HotSpotMethodData methodData) {
-        super(compiler);
-        this.methodData = methodData;
-        hintPosition = 0;
-        hintBCI = -1;
-    }
-
-    @Override
-    public RiTypeProfile getTypeProfile(int bci) {
-        findBCI(bci);
-        return dataAccessor.getTypeProfile(methodData, position);
-    }
-
-    @Override
-    public double getBranchTakenProbability(int bci) {
-        findBCI(bci);
-        return dataAccessor.getBranchTakenProbability(methodData, position);
-    }
-
-    @Override
-    public double[] getSwitchProbabilities(int bci) {
-        findBCI(bci);
-        return dataAccessor.getSwitchProbabilities(methodData, position);
-    }
-
-    @Override
-    public boolean getImplicitExceptionSeen(int bci) {
-        findBCI(bci);
-        return dataAccessor.getImplicitExceptionSeen(methodData, position);
-    }
-
-    @Override
-    public int getExecutionCount(int bci) {
-        findBCI(bci);
-        return dataAccessor.getExecutionCount(methodData, position);
-    }
-
-    private void findBCI(int targetBCI) {
-        assert targetBCI >= 0 : "invalid BCI";
-
-        if (methodData.hasNormalData()) {
-            int currentPosition = targetBCI < hintBCI ? 0 : hintPosition;
-            HotSpotMethodDataAccessor currentAccessor;
-            while ((currentAccessor = methodData.getNormalData(currentPosition)) != null) {
-                int currentBCI = currentAccessor.getBCI(methodData, currentPosition);
-                if (currentBCI == targetBCI) {
-                    normalDataFound(currentAccessor, currentPosition, currentBCI);
-                    return;
-                } else if (currentBCI > targetBCI) {
-                    break;
-                }
-                currentPosition = currentPosition + currentAccessor.getSize(methodData, currentPosition);
-            }
-        }
-
-        if (methodData.hasExtraData()) {
-            int currentPosition = 0;
-            HotSpotMethodDataAccessor currentAccessor;
-            while ((currentAccessor = methodData.getExtraData(currentPosition)) != null) {
-                int currentBCI = currentAccessor.getBCI(methodData, currentPosition);
-                if (currentBCI == targetBCI) {
-                    extraDataFound(currentAccessor, currentPosition);
-                    return;
-                }
-                currentPosition = currentPosition + currentAccessor.getSize(methodData, currentPosition);
-            }
-        }
-
-        noDataFound();
-    }
-
-    private void normalDataFound(HotSpotMethodDataAccessor data, int pos, int bci) {
-        setCurrentData(data, pos);
-        this.hintPosition = position;
-        this.hintBCI = bci;
-    }
-
-    private void extraDataFound(HotSpotMethodDataAccessor data, int pos) {
-        setCurrentData(data, pos);
-    }
-
-    private void noDataFound() {
-        setCurrentData(HotSpotMethodData.getNoMethodData(), -1);
-    }
-
-    private void setCurrentData(HotSpotMethodDataAccessor dataAccessor, int position) {
-        this.dataAccessor = dataAccessor;
-        this.position = position;
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotMethodDataAccessor.java	Fri Jan 27 11:45:48 2012 -0800
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2011, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.max.graal.hotspot.ri;
+
+import com.oracle.max.cri.ri.*;
+
+/**
+ * Interface for accessor objects that encapsulate the logic for accessing the different kinds of data in a HotSpot methodDataOop.
+ * This interface is similar to the interface {@link RiProfilingInfo}, but most methods require a MethodDataObject and the
+ * exact position within the methodData.
+ */
+public interface HotSpotMethodDataAccessor {
+    /**
+     * Returns the tag stored in the LayoutData header.
+     * @return An integer >= 0 or -1 if not supported.
+     */
+    int getTag();
+
+    /**
+     * Returns the BCI stored in the LayoutData header.
+     * @return An integer >= 0 and <= Short.MAX_VALUE, or -1 if not supported.
+     */
+    int getBCI(HotSpotMethodData data, int position);
+
+    /**
+     * Computes the size for the specific data at the given position.
+     * @return An integer > 0.
+     */
+    int getSize(HotSpotMethodData data, int position);
+
+    RiTypeProfile getTypeProfile(HotSpotMethodData data, int position);
+    double getBranchTakenProbability(HotSpotMethodData data, int position);
+    double[] getSwitchProbabilities(HotSpotMethodData data, int position);
+    boolean getImplicitExceptionSeen(HotSpotMethodData data, int position);
+    int getExecutionCount(HotSpotMethodData data, int position);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotProfilingInfo.java	Fri Jan 27 11:45:48 2012 -0800
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2012, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.max.graal.hotspot.ri;
+
+import com.oracle.max.cri.ri.*;
+import com.oracle.max.graal.hotspot.*;
+import com.oracle.max.graal.hotspot.Compiler;
+
+
+public final class HotSpotProfilingInfo extends CompilerObject implements RiProfilingInfo {
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = -8307682725047864875L;
+
+    private int position;
+    private int hintPosition;
+    private int hintBCI;
+    private HotSpotMethodDataAccessor dataAccessor;
+    private HotSpotMethodData methodData;
+
+    public HotSpotProfilingInfo(Compiler compiler, HotSpotMethodData methodData) {
+        super(compiler);
+        this.methodData = methodData;
+        hintPosition = 0;
+        hintBCI = -1;
+    }
+
+    @Override
+    public RiTypeProfile getTypeProfile(int bci) {
+        findBCI(bci, false);
+        return dataAccessor.getTypeProfile(methodData, position);
+    }
+
+    @Override
+    public double getBranchTakenProbability(int bci) {
+        findBCI(bci, false);
+        return dataAccessor.getBranchTakenProbability(methodData, position);
+    }
+
+    @Override
+    public double[] getSwitchProbabilities(int bci) {
+        findBCI(bci, false);
+        return dataAccessor.getSwitchProbabilities(methodData, position);
+    }
+
+    @Override
+    public boolean getImplicitExceptionSeen(int bci) {
+        findBCI(bci, true);
+        return dataAccessor.getImplicitExceptionSeen(methodData, position);
+    }
+
+    @Override
+    public int getExecutionCount(int bci) {
+        findBCI(bci, false);
+        return dataAccessor.getExecutionCount(methodData, position);
+    }
+
+    private void findBCI(int targetBCI, boolean searchExtraData) {
+        assert targetBCI >= 0 : "invalid BCI";
+
+        if (methodData.hasNormalData()) {
+            int currentPosition = targetBCI < hintBCI ? 0 : hintPosition;
+            HotSpotMethodDataAccessor currentAccessor;
+            while ((currentAccessor = methodData.getNormalData(currentPosition)) != null) {
+                int currentBCI = currentAccessor.getBCI(methodData, currentPosition);
+                if (currentBCI == targetBCI) {
+                    normalDataFound(currentAccessor, currentPosition, currentBCI);
+                    return;
+                } else if (currentBCI > targetBCI) {
+                    break;
+                }
+                currentPosition = currentPosition + currentAccessor.getSize(methodData, currentPosition);
+            }
+        }
+
+        if (searchExtraData && methodData.hasExtraData()) {
+            int currentPosition = 0;
+            HotSpotMethodDataAccessor currentAccessor;
+            while ((currentAccessor = methodData.getExtraData(currentPosition)) != null) {
+                int currentBCI = currentAccessor.getBCI(methodData, currentPosition);
+                if (currentBCI == targetBCI) {
+                    extraDataFound(currentAccessor, currentPosition);
+                    return;
+                }
+                currentPosition = currentPosition + currentAccessor.getSize(methodData, currentPosition);
+            }
+        }
+
+        noDataFound();
+    }
+
+    private void normalDataFound(HotSpotMethodDataAccessor data, int pos, int bci) {
+        setCurrentData(data, pos);
+        this.hintPosition = position;
+        this.hintBCI = bci;
+    }
+
+    private void extraDataFound(HotSpotMethodDataAccessor data, int pos) {
+        setCurrentData(data, pos);
+    }
+
+    private void noDataFound() {
+        setCurrentData(HotSpotMethodData.getNoMethodData(), -1);
+    }
+
+    private void setCurrentData(HotSpotMethodDataAccessor dataAccessor, int position) {
+        this.dataAccessor = dataAccessor;
+        this.position = position;
+    }
+}