1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
4 * All rights reserved. This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Simon Delisle - Initial implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.ctf
.core
.event
;
15 import java
.util
.Comparator
;
17 import org
.eclipse
.linuxtools
.ctf
.core
.event
.CTFCallsite
;
20 * Comparator for CTFCallsite
22 * @author Simon Delisle
26 public class CTFCallsiteComparator
implements Comparator
<CTFCallsite
> {
28 private static final long MASK32
= 0x00000000ffffffffL
;
31 * The callsites will be sorted by calling addresses. To do this we take IPs
32 * (instruction pointers) and compare them. Java only supports signed
33 * operation and since memory addresses are unsigned, we will convert the
34 * longs into integers that contain the high and low bytes and compare them.
37 public int compare(CTFCallsite o1
, CTFCallsite o2
) {
39 * mask32 is 32 zeros followed by 32 ones, when we bitwise and this it
40 * will return the lower 32 bits
43 long other
= o2
.getIp();
45 * To get a high int: we downshift by 32 and bitwise and with the mask
46 * to get rid of the sign
48 * To get the low int: we bitwise and with the mask.
50 long otherHigh
= (other
>> 32) & MASK32
;
51 long otherLow
= other
& MASK32
;
52 long ownHigh
= (o1
.getIp() >> 32) & MASK32
;
53 long ownLow
= o1
.getIp() & MASK32
;
54 /* are the high values different, if so ignore the lower values */
55 if (ownHigh
> otherHigh
) {
58 if (ownHigh
< otherHigh
) {
61 /* the high values are the same, compare the lower values */
62 if (ownLow
> otherLow
) {
65 if (ownLow
< otherLow
) {
68 /* the values are identical */
This page took 0.03748 seconds and 5 git commands to generate.