Hi there,

this patch fixes the deadlock in FontManager for OpenJDK7 that has been
reported repeatedly on this list. I have a testcase here (attached),
which I could prepare for jtreg, but it is not totally reliable and
depends on the system configuration (which and how many fonts
installed), not sure if we want this.

The problem is that two threads run into font code, locking on two
different locks in wrong order. (Better analysis is in the bug). The fix
is to synchronize only on one lock object (the FontManager instance).

http://cr.openjdk.java.net/~rkennke/6892485/webrev.00/

Ok to commit?

import java.util.*;
import java.util.concurrent.*;
import java.awt.*;

public class FontDeadlock {
    static String[] fontNames = {
        "SansSerif.plain",
        "AR PL UMing HK",
        "Sharjah",
        "Metal",
        "Comic Sans MS",
        "Century Schoolbook L Italic",
        "Nimbus Sans L Bold Condensed Italic",
        "DialogInput.bolditalic",
        "Nimbus Mono L Regular Oblique",
        "Graph",
        "URW Gothic L Book Oblique",
        "Tlwg Typewriter",
        "DejaVu Sans Mono Bold Oblique",
        "Winks",
        "Petra",
        "Waree Bold",
        "DejaVu Sans Condensed",
        "Loma Bold",
        "Dimnah",
        "Bitstream Vera Serif Bold",
        "Sawasdee Bold",
        "AnjaliOldLipi",
        "Lucida Sans Regular",
        "Bitstream Vera Sans Bold Oblique",
        "DejaVu Serif Italic",
        "Garuda Bold",
        "Norasi",
        "AR PL UKai CN",
        "Verdana",
        "DejaVu Serif Condensed Oblique",
        "Khalid",
        "Free Monospaced Bold Oblique",
        "SansSerif.italic",
        "Swift",
        "AlYarmook",
        "Courier New Bold Italic",
        "Nimbus Roman No9 L Medium Italic",
        "utkal medium",
        "AlBattar",
        "Trebuchet MS",
        "Monospaced.italic",
        "DejaVu Sans Condensed Bold",
        "Lucida Sans Oblique",
        "Arial Bold",
        "Haramain",
        "URW Palladio L Bold Italic",
        "Tlwg Typewriter Mono Oblique",
        "Nimbus Roman No9 L Medium",
        "Courier 10 Pitch Bold Italic",
        "Junkyard",
        "Garuda Bold Oblique",
        "Lucida Sans Typewriter Oblique",
        "Nice",
        "Waree",
        "Furat",
        "Un Batang Bold",
        "Free Monospaced Bold",
        "Tlwg Typist",
        "Tlwg Typist Bold Oblique",
        "Mashq",
        "Trebuchet MS Bold",
        "Courier New",
        "Andale Mono",
        "Dialog.bold",
        "Bitstream Charter",
        "Verdana Bold Italic",
        "Lohit Hindi",
        "AR PL UKai TW MBE",
        "Free Sans Bold Oblique",
        "Free Serif Bold Italic",
        "AR PL UMing CN",
        "Courier New Bold",
        "Nimbus Roman No9 L Regular Italic",
        "VL Gothic Regular",
        "Sindbad",
        "Hani",
        "progenisis",
        "Bitstream Vera Sans Mono Bold",
        "Nimbus Sans L Bold Condensed",
        "Webdings",
        "Dialog.italic",
        "Lucida Sans Typewriter Bold Oblique",
        "DejaVu Serif Condensed",
        "Norasi Oblique",
        "Standard Symbols L",
        "Tlwg Typewriter Bold Oblique",
        "Vemana2000",
        "Nimbus Sans L Bold",
        "DejaVu Sans Condensed Bold Oblique",
        "AR PL UMing TW MBE",
        "URW Gothic L Demi Oblique",
        "Dialog.bolditalic",
        "URW Bookman L Light",
        "El Abogado Loco",
        "AlManzomah",
        "URW Palladio L Italic",
        "AR PL UMing TW",
        "DejaVu Serif Bold Italic",
        "Free Sans Oblique",
        "Comic Sans MS Bold",
        "Dialog.plain",
        "Tlwg Mono Oblique",
        "DejaVu Serif Condensed Bold Italic",
        "Tarablus",
        "Century Schoolbook L Bold",
        "Free Sans",
        "Times New Roman Bold Italic",
        "MalOtf",
        "AlMohanad",
        "Lucida Sans Typewriter Bold",
        "Waree Oblique",
        "AlHor",
        "URW Bookman L Demi Bold Italic",
        "DejaVu Sans Mono Bold",
        "SteveHand",
        "Waree Bold Oblique",
        "Garuda Oblique",
        "Mashq Bold",
        "Nimbus Mono L Bold",
        "Lucida Bright Demibold",
        "Nagham",
        "Verdana Bold",
        "flatline",
        "Lucida Bright Regular",
        "Rehan",
        "AR PL UKai TW",
        "Arial Bold Italic",
        "Impact",
        "Mukti Narrow Bold",
        "DejaVu Sans Mono",
        "Times New Roman Bold",
        "Loma",
        "Nimbus Sans L Regular Condensed",
        "DejaVu Sans Oblique",
        "It wasn't me",
        "Georgia Bold",
        "Ouhod Bold",
        "Monospaced.bolditalic",
        "Cortoba",
        "Dustismo",
        "Bitstream Charter Bold",
        "Serif.bolditalic",
        "Courier 10 Pitch Bold",
        "DejaVu Serif Condensed Bold",
        "Free Monospaced Oblique",
        "DialogInput.bold",
        "Dustismo Roman Italic",
        "Shado",
        "Lohit Gujarati",
        "Kayrawan",
        "Bitstream Vera Serif",
        "DejaVu Sans",
        "AlMothnna Bold",
        "OpenSymbol",
        "Lucida Sans Demibold",
        "Bitstream Charter Bold Italic",
        "Nimbus Roman No9 L Regular",
        "Japan",
        "URW Palladio L Bold",
        "Georgia Italic",
        "Norasi Bold",
        "Bitstream Vera Sans",
        "Times New Roman Italic",
        "Lucida Bright Italic",
        "URW Gothic L Book",
        "Lucida Bright Demibold Italic",
        "Tholoth",
        "Penguin Attack",
        "Norasi Bold Italic",
        "Nimbus Mono L Regular",
        "Kochi Mincho",
        "URW Bookman L Demi Bold",
        "SansSerif.bold",
        "Tlwg Typewriter Bold",
        "Lucida Sans Typewriter Regular",
        "Phetsarath OT",
        "Norasi Italic",
        "Times New Roman",
        "Un Batang",
        "DejaVu Sans Condensed Oblique",
        "Dustismo  Bold Italic",
        "SansSerif.bolditalic",
        "Courier New Italic",
        "AlArabiya",
        "Serif.bold",
        "Free Serif Bold",
        "Free Serif",
        "Mallige Bold",
        "Bitstream Vera Sans Mono",
        "Un Dotum",
        "Free Monospaced",
        "DejaVu Sans Bold",
        "Serif.italic",
        "Loma Oblique",
        "Tlwg Typist Bold",
        "Kochi Gothic",
        "VL PGothic Regular",
        "Trebuchet MS Bold Italic",
        "Electron",
        "Nimbus Sans L Bold Italic",
        "Sawasdee Oblique",
        "Norasi Bold Oblique",
        "Rasheeq Bold",
        "Free Sans Bold",
        "Ostorah",
        "DejaVu Serif Condensed Bold Oblique",
        "Dustismo Roman Bold Italic",
        "Georgia",
        "Nada",
        "DejaVu Sans ExtraLight",
        "DejaVu Sans Mono Oblique",
        "URW Chancery L Medium Italic",
        "Nimbus Sans L Regular",
        "Georgia Bold Italic",
        "Nimbus Mono L Bold Oblique",
        "Serif.plain",
        "Arial",
        "Lohit Tamil",
        "Sawasdee Bold Oblique",
        "Lohit Punjabi",
        "Bitstream Vera Sans Oblique",
        "Tlwg Mono Bold",
        "Granada",
        "Balker",
        "AR PL UKai HK",
        "Dingbats ",
        "Bitstream Vera Sans Bold",
        "DejaVu Serif Bold",
        "Dustismo  Italic",
        "Salem",
        "Tlwg Mono Bold Oblique",
        "DialogInput.plain",
        "Jet",
        "DejaVu Serif Oblique",
        "Dustismo Roman Bold",
        "URW Palladio L Roman",
        "DialogInput.italic",
        "DejaVu Sans Bold Oblique",
        "AlMateen Bold",
        "DejaVu Serif Italic Condensed",
        "Hor",
        "Free Serif Italic",
        "Mukti Narrow",
        "Courier 10 Pitch",
        "Arab",
        "Loma Bold Oblique",
        "Bitstream Charter Italic",
        "Bitstream Vera Sans Mono Oblique",
        "Wargames",
        "URW Gothic L Demi",
        "Marked Fool",
        "Trebuchet MS Italic",
        "Arial Italic",
        "Un Dotum Bold",
        "Tlwg Typist Oblique",
        "Rachana_w01",
        "Domestic Manners",
        "Nimbus Sans L Regular Condensed Italic",
        "Garuda",
        "Dustismo Roman",
        "Sawasdee",
        "Dustismo  Bold",
        "Verdana Italic",
        "Courier 10 Pitch Italic",
        "Monospaced.bold",
        "DejaVu Serif",
        "Tlwg Mono",
        "Monospaced.plain",
        "Nimbus Sans L Regular Italic",
        "Mallige Normal",
        "Delphine",
        "Century Schoolbook L Roman",
        "Bitstream Vera Sans Mono Bold Oblique",
        "DejaVu Serif Bold Oblique",
        "Lucida Sans Demibold Oblique",
        "URW Bookman L Light Italic",
        "Purisa",
        "Arial Black",
    };
    public static void main(String[] args) throws Throwable {
//         final Font[] fonts = GraphicsEnvironment
//             .getLocalGraphicsEnvironment()
//             .getAllFonts();
        final int count = 100;
        final CountDownLatch startingGate = new CountDownLatch(1);
        Collections.shuffle(Arrays.asList(fontNames));
        //System.out.println(Font.decode("Tholoth"));
        final java.util.List<Thread> threads = new ArrayList<Thread>();
        for (int i = 0; i < count; i++) {
            threads.add(new Thread() { public void run() {
                try {
                startingGate.await();
//                 String[] copy = fontNames.clone();
//                 Collections.shuffle(Arrays.asList(copy));
                for (String name : fontNames) {
                    Font font = Font.decode(name + "-ITALIC");
                    if (font == null) throw new Error();
//                 Font[] copy = fonts.clone();
//                 Collections.shuffle(Arrays.asList(copy));
		    System.out.println(font.getFontName());
		 }
                } catch (Throwable t) { throw new Error(t); }
            }});
        }
        startingGate.countDown();
        for (Thread thread : threads) thread.start();
        for (Thread thread : threads) thread.join();
        //System.out.println(Arrays.toString(fonts));
    }
}

Attachment: runfontdeadlock.sh
Description: application/shellscript

Reply via email to