4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
26 * ident "%Z%%M% %I% %E% SMI"
29 import java.util.concurrent.atomic.*;
30 import org.opensolaris.os.dtrace.*;
33 * Regression test for 6521523 aggregation drops can hang the Java
36 public class TestDrop {
37 static final String PROGRAM =
38 "fbt:genunix::entry { @[execname, pid] = count(); }";
40 static AtomicLong consumerThreadID = new AtomicLong();
41 static AtomicLong getAggregateThreadID = new AtomicLong();
42 static AtomicBoolean done = new AtomicBoolean();
52 final Timer timer = new Timer();
53 timer.schedule(new TimerTask() {
62 sampleAggregate(Consumer consumer) throws DTraceException
64 while (consumer.isRunning() && !done.get()) {
66 Thread.currentThread().sleep(50);
67 } catch (InterruptedException e) {
70 consumer.getAggregate(Collections. <String> emptySet());
75 startAggregateThread(final Consumer consumer)
77 Runnable aggregateSampler = new Runnable() {
79 Thread t = Thread.currentThread();
80 getAggregateThreadID.set(t.getId());
83 sampleAggregate(consumer);
84 } catch (Throwable e) {
88 if (Thread.holdsLock(LocalConsumer.class)) {
92 System.out.println("Lock held");
95 System.out.println("Lock released");
96 consumer.close(); // blocks if lock held
101 Thread t = new Thread(aggregateSampler, "Aggregate Sampler");
108 System.err.println("usage: java TestDrop [ seconds ]");
115 if (args.length == 1) {
117 seconds = Integer.parseInt(args[0]);
118 } catch (NumberFormatException e) {
121 } else if (args.length > 1) {
125 final Consumer consumer = new LocalConsumer() {
126 protected Thread createThread() {
127 Runnable worker = new Runnable() {
129 Thread t = Thread.currentThread();
130 consumerThreadID.set(t.getId());
134 Thread t = new Thread(worker);
139 consumer.addConsumerListener(new ConsumerAdapter() {
140 public void consumerStarted(ConsumerEvent e) {
141 startAggregateThread(consumer);
144 public void dataDropped(DropEvent e) throws ConsumerException {
145 Thread t = Thread.currentThread();
146 if (t.getId() == getAggregateThreadID.get()) {
147 Drop drop = e.getDrop();
148 throw new ConsumerException(drop.getDefaultMessage(),
156 consumer.setOption(Option.aggsize, Option.kb(1));
157 consumer.setOption(Option.aggrate, Option.millis(101));
158 consumer.compile(PROGRAM);
160 consumer.go(new ExceptionHandler() {
161 public void handleException(Throwable e) {
165 } catch (DTraceException e) {