001 /*
002 * This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 * This file is licensed to You under the Eclipse Public License (EPL);
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/eclipse-1.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.RVMThread;
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 Space.printUsagePages();
046 Space.printUsageMB();
047 VM.sysFail(message);
048 }
049
050 @Uninterruptible
051 public final void exit(int rc) {
052 VM.sysExit(rc);
053 }
054
055 /**
056 * Checks that the given condition is true. If it is not, this
057 * method does a traceback and exits. All calls to this method
058 * must be guarded by <code>VM.VERIFY_ASSERTIONS</code>.
059 *
060 * @param cond the condition to be checked
061 */
062 @Inline(value=Inline.When.AllArgumentsAreConstant)
063 public final void _assert(boolean cond) {
064 if (!org.mmtk.vm.VM.VERIFY_ASSERTIONS)
065 VM.sysFail("All assertions must be guarded by VM.VERIFY_ASSERTIONS: please check the failing assertion");
066 VM._assert(cond);
067 }
068
069 /**
070 * Checks that the given condition is true. If it is not, this
071 * method prints a message, does a traceback and exits. All calls
072 * to this method must be guarded by <code>VM.VERIFY_ASSERTIONS</code>.
073 *
074 * @param cond the condition to be checked
075 * @param message the message to print
076 */
077 @Inline(value=Inline.When.ArgumentsAreConstant, arguments={1})
078 public final void _assert(boolean cond, String message) {
079 if (!org.mmtk.vm.VM.VERIFY_ASSERTIONS)
080 VM.sysFail("All assertions must be guarded by VM.VERIFY_ASSERTIONS: please check the failing assertion");
081 if (!cond) VM.sysWriteln(message);
082 VM._assert(cond);
083 }
084
085 public final void dumpStack() {
086 RVMThread.dumpStack();
087 }
088
089 /**
090 * Checks if the virtual machine is running. This value changes, so
091 * the call-through to the VM must be a method. In Jikes RVM, just
092 * returns VM.runningVM.
093 *
094 * @return <code>true</code> if the virtual machine is running
095 */
096 public final boolean runningVM() { return VM.runningVM; }
097
098 }