Home | History | Annotate | Download | only in VirtualMachine
      1 /*
      2  * Licensed to the Apache Software Foundation (ASF) under one or more
      3  * contributor license agreements.  See the NOTICE file distributed with
      4  * this work for additional information regarding copyright ownership.
      5  * The ASF licenses this file to You under the Apache License, Version 2.0
      6  * (the "License"); you may not use this file except in compliance with
      7  * the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *
     15  *  See the License for the specific language governing permissions and
     16  *  limitations under the License.
     17  */
     18 
     19 package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
     20 
     21 import java.util.ArrayList;
     22 import java.util.Random;
     23 
     24 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
     25 import org.apache.harmony.jpda.tests.share.SyncDebuggee;
     26 
     27 public class InstanceCountsDebuggee extends SyncDebuggee {
     28 
     29 	static final int maxNum = 17;
     30 
     31 	static int reachableObjNumOfClass1;
     32 
     33 	static int reachableObjNumOfClass2;
     34 
     35 	static {
     36         reachableObjNumOfClass1 = new Random().nextInt(maxNum) + 2;
     37         reachableObjNumOfClass2 = new Random().nextInt(maxNum) + 2;
     38 	}
     39 
     40 	@SuppressWarnings("unchecked")
     41     @Override
     42 	public void run() {
     43 		//Objects reachable for garbage collection purpose
     44 		ArrayList<Object> reachableObjs = new ArrayList<Object>();
     45 
     46 		for(int i = 0; i < reachableObjNumOfClass1; i++) {
     47 			reachableObjs.add(new MockClass1(true));
     48 		}
     49         for(int i = 0; i < reachableObjNumOfClass2; i++) {
     50             reachableObjs.add(new MockClass2(true));
     51         }
     52 
     53 		//Objects unreachable
     54 		for(int i = 0; i < reachableObjNumOfClass1/2; i++) {
     55 			new MockClass1(false);
     56 		}
     57         for(int i = 0; i < reachableObjNumOfClass2/2; i++) {
     58             new MockClass2(false);
     59         }
     60 
     61 		synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
     62         logWriter.println("--> Debuggee: InstancesDebuggee...");
     63         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
     64 	}
     65 
     66 	public static void main(String[] args) {
     67 		runDebuggee(InstanceCountsDebuggee.class);
     68 	}
     69 
     70 }
     71 
     72 class MockClass1 {
     73     @SuppressWarnings("unused")
     74     private boolean isReachable;
     75 
     76     MockClass1(boolean isReachable) {
     77         this.isReachable = isReachable;
     78     }
     79 }
     80 
     81 class MockClass2 {
     82     @SuppressWarnings("unused")
     83     private boolean isReachable;
     84 
     85     MockClass2(boolean isReachable) {
     86         this.isReachable = isReachable;
     87     }
     88 }
     89