1/*
2 * Copyright (c) 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
27import jdk.vm.ci.code.DebugInfo;
28import jdk.vm.ci.meta.InvokeTarget;
29
30/**
31 * Represents a call in the code.
32 */
33public final class Call extends Infopoint {
34
35    /**
36     * The target of the call.
37     */
38    public final InvokeTarget target;
39
40    /**
41     * The size of the call instruction.
42     */
43    public final int size;
44
45    /**
46     * Specifies if this call is direct or indirect. A direct call has an immediate operand encoding
47     * the absolute or relative (to the call itself) address of the target. An indirect call has a
48     * register or memory operand specifying the target address of the call.
49     */
50    public final boolean direct;
51
52    public Call(InvokeTarget target, int pcOffset, int size, boolean direct, DebugInfo debugInfo) {
53        super(pcOffset, debugInfo, InfopointReason.CALL);
54        this.size = size;
55        this.target = target;
56        this.direct = direct;
57    }
58
59    @Override
60    public boolean equals(Object obj) {
61        if (this == obj) {
62            return true;
63        }
64        if (obj instanceof Call && super.equals(obj)) {
65            Call that = (Call) obj;
66            if (this.size == that.size && this.direct == that.direct && Objects.equals(this.target, that.target)) {
67                return true;
68            }
69        }
70        return false;
71    }
72
73    @Override
74    public String toString() {
75        StringBuilder sb = new StringBuilder();
76        sb.append(pcOffset);
77        sb.append('[');
78        sb.append(target);
79        sb.append(']');
80
81        if (debugInfo != null) {
82            appendDebugInfo(sb, debugInfo);
83        }
84
85        return sb.toString();
86    }
87}
88