001 /*
002 * This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 * This file is licensed to You under the Common Public License (CPL);
005 * You may not use this file except in compliance with the License. You
006 * may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/cpl1.0.php
009 *
010 * See the COPYRIGHT.txt file distributed with this work for information
011 * regarding copyright ownership.
012 */
013 package org.jikesrvm.mm.mmtk;
014
015 import org.mmtk.policy.Space;
016
017 import org.jikesrvm.VM;
018 import org.jikesrvm.scheduler.Scheduler;
019
020 import org.vmmagic.pragma.*;
021
022 @Uninterruptible public class Assert extends org.mmtk.vm.Assert {
023 /**
024 * <code>true</code> if assertions should be verified
025 */
026 protected final boolean getVerifyAssertionsConstant() { return VM.VerifyAssertions;}
027
028 /**
029 * This method should be called whenever an error is encountered.
030 *
031 * @param str A string describing the error condition.
032 */
033 public final void error(String str) {
034 Space.printUsagePages();
035 Space.printUsageMB();
036 fail(str);
037 }
038
039 /**
040 * Logs a message and traceback, then exits.
041 *
042 * @param message the string to log
043 */
044 public final void fail(String message) {
045 VM.sysFail(message);
046 }
047
048 @Uninterruptible
049 public final void exit(int rc) {
050 VM.sysExit(rc);
051 }
052
053 /**
054 * Checks that the given condition is true. If it is not, this
055 * method does a traceback and exits. All calls to this method
056 * must be guarded by <code>VM.VERIFY_ASSERTIONS</code>.
057 *
058 * @param cond the condition to be checked
059 */
060 @Inline(value=Inline.When.AllArgumentsAreConstant)
061 public final void _assert(boolean cond) {
062 if (!org.mmtk.vm.VM.VERIFY_ASSERTIONS)
063 VM.sysFail("All assertions must be guarded by VM.VERIFY_ASSERTIONS: please check the failing assertion");
064 VM._assert(cond);
065 }
066
067 /**
068 * Checks that the given condition is true. If it is not, this
069 * method prints a message, does a traceback and exits. All calls
070 * to this method must be guarded by <code>VM.VERIFY_ASSERTIONS</code>.
071 *
072 * @param cond the condition to be checked
073 * @param message the message to print
074 */
075 @Inline(value=Inline.When.ArgumentsAreConstant, arguments={1})
076 public final void _assert(boolean cond, String message) {
077 if (!org.mmtk.vm.VM.VERIFY_ASSERTIONS)
078 VM.sysFail("All assertions must be guarded by VM.VERIFY_ASSERTIONS: please check the failing assertion");
079 if (!cond) VM.sysWriteln(message);
080 VM._assert(cond);
081 }
082
083 public final void dumpStack() {
084 Scheduler.dumpStack();
085 }
086
087 /**
088 * Checks if the virtual machine is running. This value changes, so
089 * the call-through to the VM must be a method. In Jikes RVM, just
090 * returns VM.runningVM.
091 *
092 * @return <code>true</code> if the virtual machine is running
093 */
094 public final boolean runningVM() { return VM.runningVM; }
095
096 }