jdk/src/solaris/classes/sun/awt/X11/UnsafeXDisposerRecord.java
author yan
Mon, 06 Oct 2008 16:45:00 +0400
changeset 1966 12a51fb0db0d
parent 2 90ce3da70b43
child 3938 ef327bd847c0
permissions -rw-r--r--
5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif Summary: Does not work on Motif but works on XToolkit now; implemented using XQueryPointer. Reviewed-by: anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import sun.misc.Unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.logging.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
class UnsafeXDisposerRecord implements sun.java2d.DisposerRecord {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
    private static final Logger log = Logger.getLogger("sun.awt.X11.UnsafeXDisposerRecord");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
    private static Unsafe unsafe = XlibWrapper.unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    final long[] unsafe_ptrs, x_ptrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    final String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    volatile boolean disposed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    final Throwable place;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    public UnsafeXDisposerRecord(String name, long[] unsafe_ptrs, long[] x_ptrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
        this.unsafe_ptrs = unsafe_ptrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        this.x_ptrs = x_ptrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        if (XlibWrapper.isBuildInternal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
            place = new Throwable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
            place = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public UnsafeXDisposerRecord(String name, long ... unsafe_ptrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        this.unsafe_ptrs = unsafe_ptrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        this.x_ptrs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        if (XlibWrapper.isBuildInternal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            place = new Throwable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            place = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            if (!disposed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                if (XlibWrapper.isBuildInternal && "Java2D Disposer".equals(Thread.currentThread().getName()) && log.isLoggable(Level.WARNING)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                    if (place != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                        log.log(Level.WARNING, name + " object was not disposed before finalization!", place);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                        log.log(Level.WARNING, name + " object was not disposed before finalization!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                if (unsafe_ptrs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                    for (long l : unsafe_ptrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                        if (l != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                            unsafe.freeMemory(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                if (x_ptrs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                    for (long l : x_ptrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                        if (l != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                            if (Native.getLong(l) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                XlibWrapper.XFree(Native.getLong(l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                            unsafe.freeMemory(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                disposed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
}