2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package gov.nasa.jpf.vm.serialize;
21 import gov.nasa.jpf.vm.ChoiceGenerator;
22 import gov.nasa.jpf.vm.ElementInfo;
25 * a CG type adaptive, canonicalizing & filtering serializer that is an
26 * under-approximation mostly aimed at finding data races and deadlocks in programs
27 * with a large number of scheduling points (= thread choices)
29 * This came to bear by accidentally discovering that JPF often seems to finds
30 * concurrency defects by just serializing the thread states, their topmost stack
31 * frames and the objects directly referenced from there.
32 * For non-scheduling points, we just fall back to serializing statics, all thread
33 * stacks and all the data reachable from there
35 public class AdaptiveSerializer extends CFSerializer {
37 boolean traverseObjects;
38 boolean isSchedulingPoint;
41 protected void initReferenceQueue() {
42 super.initReferenceQueue();
43 traverseObjects = true;
45 ChoiceGenerator<?> nextCg = vm.getNextChoiceGenerator();
46 isSchedulingPoint = (nextCg != null) && nextCg.isSchedulingPoint();
50 protected void queueReference(ElementInfo ei){
57 protected void processReferenceQueue() {
58 if (isSchedulingPoint){
59 traverseObjects = false;
61 refQueue.process(this);
66 protected void serializeClassLoaders(){
67 // for thread CGs we skip this - assuming that this is only relevant if there is
68 // a class object lock, which is covered by the thread lock info
69 if (!isSchedulingPoint){
70 // <2do> this seems too conservative - we should only serialize what is
71 // used from this thread, which can be collected at class load time
72 // by looking at GET/PUTSTATIC targets (and their superclasses)
73 super.serializeClassLoaders();