1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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
.tracecompass
.internal
.ctf
.core
.event
;
15 import java
.util
.Comparator
;
17 import org
.eclipse
.tracecompass
.ctf
.core
.event
.CTFCallsite
;
20 * Comparator for CTFCallsite
22 * @author Simon Delisle
24 public class CTFCallsiteComparator
implements Comparator
<CTFCallsite
> {
26 private static final long MASK32
= 0x00000000ffffffffL
;
29 * The callsites will be sorted by calling addresses. To do this we take IPs
30 * (instruction pointers) and compare them. Java only supports signed
31 * operation and since memory addresses are unsigned, we will convert the
32 * longs into integers that contain the high and low bytes and compare them.
35 public int compare(CTFCallsite o1
, CTFCallsite o2
) {
37 * mask32 is 32 zeros followed by 32 ones, when we bitwise and this it
38 * will return the lower 32 bits
41 long other
= o2
.getIp();
43 * To get a high int: we downshift by 32 and bitwise and with the mask
44 * to get rid of the sign
46 * To get the low int: we bitwise and with the mask.
48 long otherHigh
= (other
>> 32) & MASK32
;
49 long otherLow
= other
& MASK32
;
50 long ownHigh
= (o1
.getIp() >> 32) & MASK32
;
51 long ownLow
= o1
.getIp() & MASK32
;
52 /* are the high values different, if so ignore the lower values */
53 if (ownHigh
> otherHigh
) {
56 if (ownHigh
< otherHigh
) {
59 /* the high values are the same, compare the lower values */
60 if (ownLow
> otherLow
) {
63 if (ownLow
< otherLow
) {
66 /* the values are identical */
This page took 0.050545 seconds and 5 git commands to generate.