1
/*
2
 * $Id$
3
 *
4
 * Copyright (C) 2003-2009 JNode.org
5
 *
6
 * This library is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU Lesser General Public License as published
8
 * by the Free Software Foundation; either version 2.1 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful, but 
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
14
 * License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with this library; If not, write to the Free Software Foundation, Inc., 
18
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
 */
20
 
21
package org.jnode.vm;
22
23
import org.jnode.util.NumberUtils;
24
import org.jnode.annotation.MagicPermission;
25
import org.jnode.vm.scheduler.VmProcessor;
26
import org.vmmagic.unboxed.Address;
27
28
/**
29
 * Address is not a normal Java object. Instead it is used as a reference
30
 * to a virtual memory address. Variables of this type are not considered to
31
 * be objects by the garbage collector.
32
 *
33
 * @author epr
34
 */
35
@MagicPermission
36
public abstract class VmAddress extends VmSystemObject {
37
38
    /**
39
     * Convert the given address to a String.
40
     * The length of the string depends of the reference size of
41
     * the current architecture.
42
     *
43
     * @param addr an address
44
     * @return a hexadecimal string rendering of the address
45
     */
46
    public static String toString(VmAddress addr) {
47
        final int refsize = VmProcessor.current().getArchitecture().getReferenceSize();
48
        if (refsize == 4) {
49
            return NumberUtils.hex(Address.fromAddress(addr).toInt());
50
        } else {
51
            return NumberUtils.hex(Address.fromAddress(addr).toLong());
52
        }
53
    }
54
}