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 */
013package org.jikesrvm.compilers.opt.escape;
014
015import java.util.HashMap;
016import org.jikesrvm.compilers.opt.ir.Register;
017
018/**
019 * This class holds the results of a flow-insensitive escape analysis
020 * for a method.
021 */
022class FI_EscapeSummary {
023
024  /**
025   * @param r a symbolic register
026   * @return {@code true} iff ANY object pointed to by a symbolic register
027   * MUST be thread local
028   */
029  boolean isThreadLocal(Register r) {
030    Object result = hash.get(r);
031    return result != null && result == THREAD_LOCAL;
032  }
033
034  /**
035   * @param r a symbolic register
036   * @return {@code true} iff ANY object pointed to by a symbolic register
037   * MUST be method local
038   */
039  boolean isMethodLocal(Register r) {
040    Object result = hash2.get(r);
041    return result != null && result == METHOD_LOCAL;
042  }
043
044  /**
045   * Records the fact that ALL object pointed to by a symbolic register
046   * MUST (or may) escape this thread.
047   *
048   * @param r a symbolic register
049   * @param b {@code true} if thread-local, {@code false} otherwise
050   */
051  void setThreadLocal(Register r, boolean b) {
052    if (b) {
053      hash.put(r, THREAD_LOCAL);
054    } else {
055      hash.put(r, MAY_ESCAPE_THREAD);
056    }
057  }
058
059  /**
060   * Records the fact that ALL object pointed to by a symbolic register
061   * MUST (or may) escape this method.
062   *
063   * @param r a symbolic register
064   * @param b {@code true} if method-local, {@code false} otherwise
065   */
066  void setMethodLocal(Register r, boolean b) {
067    if (b) {
068      hash2.put(r, METHOD_LOCAL);
069    } else {
070      hash2.put(r, MAY_ESCAPE_METHOD);
071    }
072  }
073
074  /* Implementation */
075  /**
076   * A mapping that holds the analysis result for thread-locality for each
077   * Register.
078   */
079  private final HashMap<Register, Object> hash = new HashMap<Register, Object>();
080
081  /**
082   * A mapping that holds the analysis result for method-locality for each
083   * Register.
084   */
085  private final HashMap<Register, Object> hash2 = new HashMap<Register, Object>();
086
087  /**
088   * Static object used to represent analysis result
089   */
090  static final Object THREAD_LOCAL = new Object();
091  /**
092   * Static object used to represent analysis result
093   */
094  static final Object MAY_ESCAPE_THREAD = new Object();
095  /**
096   * Static object used to represent analysis result
097   */
098  static final Object METHOD_LOCAL = new Object();
099  /**
100   * Static object used to represent analysis result
101   */
102  static final Object MAY_ESCAPE_METHOD = new Object();
103}
104
105
106