1/*
2 * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
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 */
23package jdk.vm.ci.code.site;
24
25import java.util.Objects;
26
27/**
28 * Associates arbitrary information with a position in machine code. For example, HotSpot specific
29 * code in a compiler backend may use this to denote the position of a safepoint, exception handler
30 * entry point, verified entry point etc.
31 */
32public final class Mark extends Site {
33
34    /**
35     * An object denoting extra semantic information about the machine code position of this mark.
36     */
37    public final Object id;
38
39    /**
40     * Creates a mark that associates {@code id} with the machine code position {@code pcOffset}.
41     *
42     * @param pcOffset
43     * @param id
44     */
45    public Mark(int pcOffset, Object id) {
46        super(pcOffset);
47        this.id = id;
48    }
49
50    @Override
51    public String toString() {
52        if (id == null) {
53            return String.format("%d[<mark>]", pcOffset);
54        } else if (id instanceof Integer) {
55            return String.format("%d[<mark with id %s>]", pcOffset, Integer.toHexString((Integer) id));
56        } else {
57            return String.format("%d[<mark with id %s>]", pcOffset, id.toString());
58        }
59    }
60
61    @Override
62    public boolean equals(Object obj) {
63        if (this == obj) {
64            return true;
65        }
66        if (obj instanceof Mark) {
67            Mark that = (Mark) obj;
68            if (this.pcOffset == that.pcOffset && Objects.equals(this.id, that.id)) {
69                return true;
70            }
71        }
72        return false;
73    }
74}
75