< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/MarkUnsafeAccessTest.java

Print this page




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.core.test;
  24 
  25 import static java.nio.file.StandardOpenOption.READ;
  26 import static java.nio.file.StandardOpenOption.WRITE;
  27 

  28 import java.io.IOException;
  29 import java.nio.ByteBuffer;
  30 import java.nio.MappedByteBuffer;
  31 import java.nio.channels.FileChannel;
  32 import java.nio.channels.FileChannel.MapMode;
  33 import java.nio.file.Files;
  34 import java.nio.file.Path;
  35 
  36 import jdk.vm.ci.code.InstalledCode;
  37 import jdk.vm.ci.code.InvalidInstalledCodeException;
  38 import jdk.vm.ci.meta.ResolvedJavaMethod;
  39 import jdk.vm.ci.meta.ResolvedJavaType;
  40 
  41 import org.junit.Assert;
  42 import org.junit.Assume;
  43 import org.junit.Test;
  44 
  45 import sun.misc.Unsafe;
  46 
  47 import org.graalvm.compiler.nodes.StructuredGraph;
  48 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  49 import org.graalvm.compiler.phases.common.inlining.InliningPhase;
  50 import org.graalvm.compiler.phases.common.inlining.policy.InlineEverythingPolicy;
  51 import org.graalvm.compiler.phases.tiers.HighTierContext;









  52 
  53 public class MarkUnsafeAccessTest extends GraalCompilerTest {
  54 
  55     public static Unsafe unsafe;
  56 
  57     public void getRaw() {
  58         unsafe.getInt(0L);
  59     }
  60 
  61     public void get() {
  62         unsafe.getInt(null, 0L);
  63     }
  64 
  65     public void putRaw() {
  66         unsafe.putInt(0L, 0);
  67     }
  68 
  69     public void put() {
  70         unsafe.putInt(null, 0L, 0);
  71     }


 153                 tmpFileChannel.write(bb);
 154             }
 155         }
 156         tmpFileChannel.force(true);
 157         MappedByteBuffer mbb = tmpFileChannel.map(MapMode.READ_WRITE, 0, BLOCK_SIZE * BLOCK_COUNT);
 158         Assert.assertEquals((byte) 0xA8, mbb.get());
 159         mbb.position(mbb.position() + BLOCK_SIZE);
 160         Assert.assertEquals((byte) 0xA8, mbb.get());
 161         boolean truncated = false;
 162         try {
 163             tmpFileChannel.truncate(0);
 164             tmpFileChannel.force(true);
 165             truncated = true;
 166         } catch (IOException e) {
 167             // not all platforms support truncating memory-mapped files
 168         }
 169         Assume.assumeTrue(truncated);
 170         try {
 171             mbb.position(BLOCK_SIZE);
 172             getter.get(mbb);
 173             System.currentTimeMillis(); // materialize async exception


 174         } catch (InternalError e) {
 175             return;
 176         }
 177         Assert.fail("Expected exception");
 178     }
 179 }


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.core.test;
  24 
  25 import static java.nio.file.StandardOpenOption.READ;
  26 import static java.nio.file.StandardOpenOption.WRITE;
  27 
  28 import java.io.File;
  29 import java.io.IOException;
  30 import java.nio.ByteBuffer;
  31 import java.nio.MappedByteBuffer;
  32 import java.nio.channels.FileChannel;
  33 import java.nio.channels.FileChannel.MapMode;
  34 import java.nio.file.Files;
  35 import java.nio.file.Path;
  36 











  37 import org.graalvm.compiler.nodes.StructuredGraph;
  38 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  39 import org.graalvm.compiler.phases.common.inlining.InliningPhase;
  40 import org.graalvm.compiler.phases.common.inlining.policy.InlineEverythingPolicy;
  41 import org.graalvm.compiler.phases.tiers.HighTierContext;
  42 import org.junit.Assert;
  43 import org.junit.Assume;
  44 import org.junit.Test;
  45 
  46 import jdk.vm.ci.code.InstalledCode;
  47 import jdk.vm.ci.code.InvalidInstalledCodeException;
  48 import jdk.vm.ci.meta.ResolvedJavaMethod;
  49 import jdk.vm.ci.meta.ResolvedJavaType;
  50 import sun.misc.Unsafe;
  51 
  52 public class MarkUnsafeAccessTest extends GraalCompilerTest {
  53 
  54     public static Unsafe unsafe;
  55 
  56     public void getRaw() {
  57         unsafe.getInt(0L);
  58     }
  59 
  60     public void get() {
  61         unsafe.getInt(null, 0L);
  62     }
  63 
  64     public void putRaw() {
  65         unsafe.putInt(0L, 0);
  66     }
  67 
  68     public void put() {
  69         unsafe.putInt(null, 0L, 0);
  70     }


 152                 tmpFileChannel.write(bb);
 153             }
 154         }
 155         tmpFileChannel.force(true);
 156         MappedByteBuffer mbb = tmpFileChannel.map(MapMode.READ_WRITE, 0, BLOCK_SIZE * BLOCK_COUNT);
 157         Assert.assertEquals((byte) 0xA8, mbb.get());
 158         mbb.position(mbb.position() + BLOCK_SIZE);
 159         Assert.assertEquals((byte) 0xA8, mbb.get());
 160         boolean truncated = false;
 161         try {
 162             tmpFileChannel.truncate(0);
 163             tmpFileChannel.force(true);
 164             truncated = true;
 165         } catch (IOException e) {
 166             // not all platforms support truncating memory-mapped files
 167         }
 168         Assume.assumeTrue(truncated);
 169         try {
 170             mbb.position(BLOCK_SIZE);
 171             getter.get(mbb);
 172 
 173             // Make a call that goes into native code to materialize async exception
 174             new File("").exists();
 175         } catch (InternalError e) {
 176             return;
 177         }
 178         Assert.fail("Expected exception");
 179     }
 180 }
< prev index next >