Call.java revision 12657:6ef01bd40ce2
1254147Sobrien/*
2254147Sobrien * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3254147Sobrien * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4256381Smarkm *
5254147Sobrien * This code is free software; you can redistribute it and/or modify it
6254147Sobrien * under the terms of the GNU General Public License version 2 only, as
7254147Sobrien * published by the Free Software Foundation.
8254147Sobrien *
9254147Sobrien * This code is distributed in the hope that it will be useful, but WITHOUT
10254147Sobrien * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11254147Sobrien * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12254147Sobrien * version 2 for more details (a copy is included in the LICENSE file that
13254147Sobrien * accompanied this code).
14254147Sobrien *
15254147Sobrien * You should have received a copy of the GNU General Public License version
16254147Sobrien * 2 along with this work; if not, write to the Free Software Foundation,
17254147Sobrien * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18254147Sobrien *
19254147Sobrien * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20254147Sobrien * or visit www.oracle.com if you need additional information or have any
21254147Sobrien * questions.
22254147Sobrien */
23254147Sobrienpackage jdk.vm.ci.code.site;
24254147Sobrien
25254147Sobrienimport java.util.Objects;
26254147Sobrien
27254147Sobrienimport jdk.vm.ci.code.DebugInfo;
28254147Sobrienimport jdk.vm.ci.meta.InvokeTarget;
29254147Sobrien
30254147Sobrien/**
31254147Sobrien * Represents a call in the code.
32256381Smarkm */
33254147Sobrienpublic final class Call extends Infopoint {
34255362Smarkm
35256381Smarkm    /**
36254147Sobrien     * The target of the call.
37256381Smarkm     */
38256381Smarkm    public final InvokeTarget target;
39255362Smarkm
40254147Sobrien    /**
41256381Smarkm     * The size of the call instruction.
42254147Sobrien     */
43255362Smarkm    public final int size;
44254147Sobrien
45255362Smarkm    /**
46255362Smarkm     * Specifies if this call is direct or indirect. A direct call has an immediate operand encoding
47254147Sobrien     * the absolute or relative (to the call itself) address of the target. An indirect call has a
48254147Sobrien     * register or memory operand specifying the target address of the call.
49254147Sobrien     */
50254147Sobrien    public final boolean direct;
51254147Sobrien
52254147Sobrien    public Call(InvokeTarget target, int pcOffset, int size, boolean direct, DebugInfo debugInfo) {
53254147Sobrien        super(pcOffset, debugInfo, InfopointReason.CALL);
54254147Sobrien        this.size = size;
55254147Sobrien        this.target = target;
56255379Smarkm        this.direct = direct;
57255379Smarkm    }
58256381Smarkm
59254147Sobrien    @Override
60254147Sobrien    public boolean equals(Object obj) {
61254147Sobrien        if (this == obj) {
62254147Sobrien            return true;
63254147Sobrien        }
64254147Sobrien        if (obj instanceof Call && super.equals(obj)) {
65254147Sobrien            Call that = (Call) obj;
66254147Sobrien            if (this.size == that.size && this.direct == that.direct && Objects.equals(this.target, that.target)) {
67256381Smarkm                return true;
68254147Sobrien            }
69254147Sobrien        }
70254147Sobrien        return false;
71254147Sobrien    }
72254147Sobrien
73254147Sobrien    @Override
74254147Sobrien    public String toString() {
75254147Sobrien        StringBuilder sb = new StringBuilder();
76254147Sobrien        sb.append(pcOffset);
77254147Sobrien        sb.append('[');
78254147Sobrien        sb.append(target);
79254147Sobrien        sb.append(']');
80254147Sobrien
81254147Sobrien        if (debugInfo != null) {
82254147Sobrien            appendDebugInfo(sb, debugInfo);
83254147Sobrien        }
84254147Sobrien
85254147Sobrien        return sb.toString();
86254147Sobrien    }
87254147Sobrien}
88254147Sobrien